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:
Denis.Zharkov
2021-01-26 10:28:07 +03:00
parent d9f45fdf9e
commit b1b89e6f5f
11 changed files with 64 additions and 5 deletions
@@ -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
@@ -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()
}
@@ -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 {
@@ -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 {
@@ -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");
@@ -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");
@@ -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");
@@ -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");
@@ -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");