Fix "Rewrite at slice LEXICAL_SCOPE" for callable references

For special calls (when-expressions, if-expressions, etc.), do not attempt to
get type of the argument expression, which is the block with the callable
reference, instead get type of the callable reference itself. The difference
matters because for block expressions, a new lexical scope is created for each
getTypeInfo (see ExpressionTypingServices.getBlockReturnedType), and we do not
support rewrites of this value in the binding trace

 #KT-12044 Fixed
This commit is contained in:
Alexander Udalov
2016-07-01 20:16:19 +03:00
parent 38a2518498
commit f8a88bdffb
10 changed files with 61 additions and 4 deletions
@@ -404,10 +404,9 @@ class GenericCandidateResolver(
.replaceExpectedType(expectedTypeWithoutReturnType)
.replaceDataFlowInfo(dataFlowInfoForArgument)
.replaceContextDependency(INDEPENDENT)
val argumentExpression = valueArgument.getArgumentExpression()!!
val type = argumentTypeResolver.getCallableReferenceTypeInfo(
argumentExpression, callableReference, newContext, RESOLVE_FUNCTION_ARGUMENTS).type
return type
return argumentTypeResolver.getCallableReferenceTypeInfo(
callableReference, callableReference, newContext, RESOLVE_FUNCTION_ARGUMENTS
).type
}
}
@@ -0,0 +1,12 @@
// KT-12044 Assertion "Rewrite at slice LEXICAL_SCOPE" for 'if' with property references
fun box(): String {
data class Pair<F, S>(val first: F, val second: S)
val (x, y) =
Pair(1,
if (1 == 1)
Pair<String, String>::first
else
Pair<String, String>::second)
return y.get(Pair("OK", "Fail"))
}
@@ -0,0 +1,3 @@
public final class Kt12044Kt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@@ -0,0 +1,9 @@
// KT-12338 Compiler error ERROR: Rewrite at slice LEXICAL_SCOPE key: REFERENCE_EXPRESSION with when and function references
fun a() { }
fun test() {
when {
true -> <!UNUSED_EXPRESSION!>::a<!>
}
}
@@ -0,0 +1,4 @@
package
public fun a(): kotlin.Unit
public fun test(): kotlin.Unit
@@ -2062,6 +2062,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("kt12044.kt")
public void testKt12044() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12044.kt");
doTest(fileName);
}
@TestMetadata("kt12982_protectedPropertyReference.kt")
public void testKt12982_protectedPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12982_protectedPropertyReference.kt");
@@ -2382,6 +2382,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt12338.kt")
public void testKt12338() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/kt12338.kt");
doTest(fileName);
}
@TestMetadata("kt12751.kt")
public void testKt12751() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/kt12751.kt");
@@ -2062,6 +2062,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt12044.kt")
public void testKt12044() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12044.kt");
doTest(fileName);
}
@TestMetadata("kt12982_protectedPropertyReference.kt")
public void testKt12982_protectedPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12982_protectedPropertyReference.kt");
@@ -2062,6 +2062,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis
doTest(fileName);
}
@TestMetadata("kt12044.kt")
public void testKt12044() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12044.kt");
doTest(fileName);
}
@TestMetadata("kt12982_protectedPropertyReference.kt")
public void testKt12982_protectedPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12982_protectedPropertyReference.kt");
@@ -2525,6 +2525,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
doTest(fileName);
}
@TestMetadata("kt12044.kt")
public void testKt12044() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12044.kt");
doTest(fileName);
}
@TestMetadata("kt12982_protectedPropertyReference.kt")
public void testKt12982_protectedPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/kt12982_protectedPropertyReference.kt");