FIR2IR: Fix smart-cast approximation implicit receiver
Previously, it was always cast to the first type of smart cast variants list independently of callee symbol that might be present in the member scope of a different type
This commit is contained in:
+6
@@ -34894,6 +34894,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
|
||||
@@ -470,7 +470,7 @@ class Fir2IrVisitor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun convertToIrReceiverExpression(
|
||||
internal fun convertToIrReceiverExpression(
|
||||
expression: FirExpression?,
|
||||
calleeReference: FirReference,
|
||||
callableReferenceAccess: FirCallableReferenceAccess? = null
|
||||
|
||||
+3
-4
@@ -713,10 +713,9 @@ class CallAndReferenceGenerator(
|
||||
if (firReceiver == explicitReceiver) {
|
||||
return explicitReceiverExpression
|
||||
}
|
||||
if (firReceiver is FirResolvedQualifier) {
|
||||
return convertToGetObject(firReceiver, this as? FirCallableReferenceAccess)
|
||||
}
|
||||
return firReceiver.takeIf { it !is FirNoReceiverExpression }?.let { visitor.convertToIrExpression(it) }
|
||||
|
||||
return firReceiver.takeIf { it !is FirNoReceiverExpression }
|
||||
?.let { visitor.convertToIrReceiverExpression(it, calleeReference, this as? FirCallableReferenceAccess) }
|
||||
?: explicitReceiverExpression
|
||||
?: run {
|
||||
if (this is FirCallableReferenceAccess) return null
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
interface Bound
|
||||
interface CompilerPhase<in X1 : Bound, Y1>
|
||||
|
||||
private class CompositePhase<X2 : Bound, Y2>(
|
||||
val foo: String
|
||||
) : CompilerPhase<X2, Y2>
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <X3 : Bound, Y3> CompilerPhase<X3, Y3>.bar(): String {
|
||||
this as CompilerPhase<X3, Any?>
|
||||
val ok = if (this is CompositePhase<X3, *>) foo + "K" else "fail"
|
||||
return ok
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return CompositePhase<Bound, Int>("O").bar()
|
||||
}
|
||||
+6
@@ -35094,6 +35094,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
|
||||
+6
@@ -34894,6 +34894,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
|
||||
+5
@@ -28666,6 +28666,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/falseSmartCast.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -24792,6 +24792,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/falseSmartCast.kt");
|
||||
|
||||
Generated
+5
@@ -24792,6 +24792,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/falseSmartCast.kt");
|
||||
|
||||
Generated
+5
@@ -24757,6 +24757,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/falseSmartCast.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -13261,6 +13261,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexImplicitReceiver.kt")
|
||||
public void testComplexImplicitReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/complexImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/falseSmartCast.kt");
|
||||
|
||||
Reference in New Issue
Block a user