don't report unnecessary smart cast on receiver
This commit is contained in:
+2
-1
@@ -35,8 +35,9 @@ public class AutoCastServiceImpl implements AutoCastService {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<ReceiverValue> getVariantsForReceiver(@NotNull ReceiverValue receiverValue) {
|
public List<ReceiverValue> getVariantsForReceiver(@NotNull ReceiverValue receiverValue) {
|
||||||
List<ReceiverValue> variants = Lists.newArrayList(AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiverValue));
|
List<ReceiverValue> variants = Lists.newArrayList();
|
||||||
variants.add(receiverValue);
|
variants.add(receiverValue);
|
||||||
|
variants.addAll(AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiverValue));
|
||||||
return variants;
|
return variants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package d
|
|||||||
|
|
||||||
fun bar(a: Any?) {
|
fun bar(a: Any?) {
|
||||||
if (a != null) {
|
if (a != null) {
|
||||||
<!DEBUG_INFO_AUTOCAST!>a<!>.foo() //overload resolution ambiguity
|
a.foo() //overload resolution ambiguity
|
||||||
<!DEBUG_INFO_AUTOCAST!>a<!>.sure() //overload resolution ambiguity
|
a.sure() //overload resolution ambiguity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ fun returnFunctionLiteral(a: Any?): Function0<Int> =
|
|||||||
fun mergeAutocasts(a: Any?) {
|
fun mergeAutocasts(a: Any?) {
|
||||||
if (a is String || a is Int) {
|
if (a is String || a is Int) {
|
||||||
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
|
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
|
||||||
<!DEBUG_INFO_AUTOCAST!>a<!>.toString()
|
a.toString()
|
||||||
}
|
}
|
||||||
if (a is Int || a is String) {
|
if (a is Int || a is String) {
|
||||||
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
|
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun Any?.foo() {}
|
||||||
|
|
||||||
|
fun test(a: Any?) {
|
||||||
|
if (a != null) {
|
||||||
|
a.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6173,6 +6173,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt");
|
doTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noUnnecessarySmartCastForReceiver.kt")
|
||||||
|
public void testNoUnnecessarySmartCastForReceiver() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("thisWithLabel.kt")
|
@TestMetadata("thisWithLabel.kt")
|
||||||
public void testThisWithLabel() throws Exception {
|
public void testThisWithLabel() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.kt");
|
doTest("compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.kt");
|
||||||
|
|||||||
@@ -165,11 +165,11 @@ fun declarations(a: Any?) {
|
|||||||
fun vars(a: Any?) {
|
fun vars(a: Any?) {
|
||||||
var <warning>b</warning>: Int = 0
|
var <warning>b</warning>: Int = 0
|
||||||
if (a is Int) {
|
if (a is Int) {
|
||||||
b = <info descr="Automatically cast to jet.Int"><warning>a</warning></info>
|
b = <warning><info descr="Automatically cast to jet.Int">a</info></warning>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun returnFunctionLiteralBlock(<info>a</info>: Any?): Function0<Int> {
|
fun returnFunctionLiteralBlock(<info>a</info>: Any?): Function0<Int> {
|
||||||
if (<info>a</info> is Int) return { <info><info descr="Automatically cast to jet.Int">a</info></info> }
|
if (<info>a</info> is Int) return { <info descr="Automatically cast to jet.Int"><info>a</info></info> }
|
||||||
else return { 1 }
|
else return { 1 }
|
||||||
}
|
}
|
||||||
fun returnFunctionLiteral(<info>a</info>: Any?): Function0<Int> =
|
fun returnFunctionLiteral(<info>a</info>: Any?): Function0<Int> =
|
||||||
@@ -179,7 +179,7 @@ fun returnFunctionLiteral(<info>a</info>: Any?): Function0<Int> =
|
|||||||
fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
|
fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
|
||||||
if (a is String || a is Int) {
|
if (a is String || a is Int) {
|
||||||
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
|
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
|
||||||
<info descr="Automatically cast to jet.Any">a</info>.toString()
|
a.toString()
|
||||||
}
|
}
|
||||||
if (a is Int || a is String) {
|
if (a is Int || a is String) {
|
||||||
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
|
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
|
||||||
|
|||||||
Reference in New Issue
Block a user