K2: allow/disallow coercion-to-unit for callable references more precisely

Before this commit, K2 always applied coercion-to-unit for
callable references if expected type was Unit, and actual non-Unit.
However, this may not work in case when actual return type is
a type parameter and it must be inferred into Unit.
In this commit we started to disallow coercion-to-unit
for references with synthetic outer call (~ top-level in K1)
AND a type parameter as a return type (both should be true to disallow).
This provides better K1 consistency,
while still keeping some broken K1 cases working in K2.

See also added comment in CallableReferenceResolution.kt.

#KT-62565 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-12-05 15:12:31 +01:00
committed by Space Team
parent 25c0bd278e
commit 2680c8effd
16 changed files with 213 additions and 16 deletions
@@ -4833,6 +4833,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
}
@Test
@TestMetadata("ambiguityTopLevelVsTopLevelGeneric.kt")
public void testAmbiguityTopLevelVsTopLevelGeneric() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt");
}
@Test
@TestMetadata("annotationClassConstructor.kt")
public void testAnnotationClassConstructor() throws Exception {
@@ -17463,6 +17469,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
}
@Test
@TestMetadata("conversionLastStatementInLambdaGeneric.kt")
public void testConversionLastStatementInLambdaGeneric() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambdaGeneric.kt");
}
@Test
@TestMetadata("kt55931.kt")
public void testKt55931() throws Exception {
@@ -17825,6 +17837,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
}
@Test
@TestMetadata("genericInApply.kt")
public void testGenericInApply() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/genericInApply.kt");
}
@Test
@TestMetadata("indirectCoercionWithExpectedType.kt")
public void testIndirectCoercionWithExpectedType() throws Exception {
@@ -4833,6 +4833,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
}
@Test
@TestMetadata("ambiguityTopLevelVsTopLevelGeneric.kt")
public void testAmbiguityTopLevelVsTopLevelGeneric() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt");
}
@Test
@TestMetadata("annotationClassConstructor.kt")
public void testAnnotationClassConstructor() throws Exception {
@@ -17463,6 +17469,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
}
@Test
@TestMetadata("conversionLastStatementInLambdaGeneric.kt")
public void testConversionLastStatementInLambdaGeneric() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambdaGeneric.kt");
}
@Test
@TestMetadata("kt55931.kt")
public void testKt55931() throws Exception {
@@ -17825,6 +17837,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
}
@Test
@TestMetadata("genericInApply.kt")
public void testGenericInApply() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/genericInApply.kt");
}
@Test
@TestMetadata("indirectCoercionWithExpectedType.kt")
public void testIndirectCoercionWithExpectedType() throws Exception {