[FIR] Reproduce KT-66277, KT-66279, KT-66512 and KT-66534

This commit is contained in:
Sergej Jaskiewicz
2024-03-14 16:39:23 +01:00
committed by Space Team
parent b3827947d9
commit 9851ff1905
13 changed files with 824 additions and 0 deletions
@@ -14199,6 +14199,30 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt");
}
@Test
@TestMetadata("kt66277.kt")
public void testKt66277() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66277.kt");
}
@Test
@TestMetadata("kt66279.kt")
public void testKt66279() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66279.kt");
}
@Test
@TestMetadata("kt66512.kt")
public void testKt66512() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66512.kt");
}
@Test
@TestMetadata("kt66534.kt")
public void testKt66534() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66534.kt");
}
@Test
@TestMetadata("LambdaReturnTypeIsUnitIfImplicitReturnExists.kt")
public void testLambdaReturnTypeIsUnitIfImplicitReturnExists() {
@@ -14199,6 +14199,30 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt");
}
@Test
@TestMetadata("kt66277.kt")
public void testKt66277() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66277.kt");
}
@Test
@TestMetadata("kt66279.kt")
public void testKt66279() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66279.kt");
}
@Test
@TestMetadata("kt66512.kt")
public void testKt66512() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66512.kt");
}
@Test
@TestMetadata("kt66534.kt")
public void testKt66534() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66534.kt");
}
@Test
@TestMetadata("LambdaReturnTypeIsUnitIfImplicitReturnExists.kt")
public void testLambdaReturnTypeIsUnitIfImplicitReturnExists() {
@@ -14193,6 +14193,30 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt");
}
@Test
@TestMetadata("kt66277.kt")
public void testKt66277() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66277.kt");
}
@Test
@TestMetadata("kt66279.kt")
public void testKt66279() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66279.kt");
}
@Test
@TestMetadata("kt66512.kt")
public void testKt66512() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66512.kt");
}
@Test
@TestMetadata("kt66534.kt")
public void testKt66534() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66534.kt");
}
@Test
@TestMetadata("LambdaReturnTypeIsUnitIfImplicitReturnExists.kt")
public void testLambdaReturnTypeIsUnitIfImplicitReturnExists() {
@@ -14199,6 +14199,30 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt");
}
@Test
@TestMetadata("kt66277.kt")
public void testKt66277() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66277.kt");
}
@Test
@TestMetadata("kt66279.kt")
public void testKt66279() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66279.kt");
}
@Test
@TestMetadata("kt66512.kt")
public void testKt66512() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66512.kt");
}
@Test
@TestMetadata("kt66534.kt")
public void testKt66534() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66534.kt");
}
@Test
@TestMetadata("LambdaReturnTypeIsUnitIfImplicitReturnExists.kt")
public void testLambdaReturnTypeIsUnitIfImplicitReturnExists() {
@@ -0,0 +1,93 @@
// ISSUE: KT-66277
fun foo() {}
typealias MyUnit = Unit
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedAnyEmptyReturnAndString: () -> Any = l@ {
if ("0".hashCode() == 42) return@l
""
}
val expectedAnyExplicitReturnUnitAndString: () -> Any = l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
val expectedAnyExplicitReturnMyUnitAndString: () -> Any = l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}
val expectedAnyExplicitReturnFooAndString: () -> Any = l@ {
if ("0".hashCode() == 42) return@l foo()
""
}
val expectedAnyEmptyReturnOnly: () -> Any = l@ {
if ("0".hashCode() == 42) return@l
return@l
}
val expectedAnyImplicitAndExplicitReturnUnit: () -> Any = l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
val expectedAnyEmptyReturnAndExplicitReturnMyUnit: () -> Any = l@ {
if ("0".hashCode() == 42) return@l
return@l MyUnit
}
val expectedAnyEmptyReturnAndExplicitReturnFoo: () -> Any = l@ {
if ("0".hashCode() == 42) return@l
return@l foo()
}
// ============== Lambdas passed as function argument ===============
fun test() {
run<Any> l@ {
if ("0".hashCode() == 42) return@l
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l foo()
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l MyUnit
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l foo()
}
}
@@ -0,0 +1,93 @@
// ISSUE: KT-66277
fun foo() {}
typealias MyUnit = Unit
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedAnyEmptyReturnAndString: () -> Any = l@ {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@l<!>
""
}
val expectedAnyExplicitReturnUnitAndString: () -> Any = l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
val expectedAnyExplicitReturnMyUnitAndString: () -> Any = l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}
val expectedAnyExplicitReturnFooAndString: () -> Any = l@ {
if ("0".hashCode() == 42) return@l foo()
""
}
val expectedAnyEmptyReturnOnly: () -> Any = l@ {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@l<!>
<!RETURN_TYPE_MISMATCH!>return@l<!>
}
val expectedAnyImplicitAndExplicitReturnUnit: () -> Any = l@ {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@l<!>
return@l Unit
}
val expectedAnyEmptyReturnAndExplicitReturnMyUnit: () -> Any = l@ {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@l<!>
return@l MyUnit
}
val expectedAnyEmptyReturnAndExplicitReturnFoo: () -> Any = l@ {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@l<!>
return@l foo()
}
// ============== Lambdas passed as function argument ===============
fun test() {
run<Any> l@ {
if ("0".hashCode() == 42) return@l
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l foo()
""
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l MyUnit
}
run<Any> l@ {
if ("0".hashCode() == 42) return@l
return@l foo()
}
}
@@ -0,0 +1,114 @@
// ISSUE: KT-66279
fun foo() {}
typealias MyUnit = Unit
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedUnitEmptyReturnUnitAndString: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
""
}
val expectedMyUnitEmptyReturnUnitAndString: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
""
}
val expectedUnitExplicitReturnUnitAndString: () -> Unit = <!INITIALIZER_TYPE_MISMATCH!>l@ {
if ("0".hashCode() == 42) return@l Unit
""
}<!>
val expectedUnitExplicitReturnMyUniAndString: () -> Unit = <!INITIALIZER_TYPE_MISMATCH!>l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}<!>
val expectedUnitExplicitReturnFooAndString: () -> Unit = <!INITIALIZER_TYPE_MISMATCH!>l@ {
if ("0".hashCode() == 42) return@l foo()
""
}<!>
val expectedUnitEmptyReturnOnly: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
return@l
}
val expectedUnitEmptyReturnAndExplicitReturnUnit: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
val expectedUnitEmptyReturnAndExplicitReturnFoo: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
return@l foo()
}
val expectedMyUnitEmptyReturnOnly: () -> MyUnit = l@ {
if ("0".hashCode() == 42) return@l
return@l
}
val expectedMyUnitEmptyReturnAndExplicitReturnMyUnit: () -> MyUnit = l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
// ============== Lambdas passed as function argument ===============
fun test() {
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
""
}
run<MyUnit> l@ {
if ("0".hashCode() == 42) return@l
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l foo()
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
return@l
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
return@l foo()
}
run<MyUnit> l@ {
if ("0".hashCode() == 42) return@l
return@l
}
run<MyUnit> l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
}
@@ -0,0 +1,114 @@
// ISSUE: KT-66279
fun foo() {}
typealias MyUnit = Unit
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedUnitEmptyReturnUnitAndString: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
""
}
val expectedMyUnitEmptyReturnUnitAndString: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
""
}
val expectedUnitExplicitReturnUnitAndString: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
val expectedUnitExplicitReturnMyUniAndString: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}
val expectedUnitExplicitReturnFooAndString: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l foo()
""
}
val expectedUnitEmptyReturnOnly: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
return@l
}
val expectedUnitEmptyReturnAndExplicitReturnUnit: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
val expectedUnitEmptyReturnAndExplicitReturnFoo: () -> Unit = l@ {
if ("0".hashCode() == 42) return@l
return@l foo()
}
val expectedMyUnitEmptyReturnOnly: () -> MyUnit = l@ {
if ("0".hashCode() == 42) return@l
return@l
}
val expectedMyUnitEmptyReturnAndExplicitReturnMyUnit: () -> MyUnit = l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
// ============== Lambdas passed as function argument ===============
fun test() {
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
""
}
run<MyUnit> l@ {
if ("0".hashCode() == 42) return@l
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l MyUnit
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l foo()
""
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
return@l
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
run<Unit> l@ {
if ("0".hashCode() == 42) return@l
return@l foo()
}
run<MyUnit> l@ {
if ("0".hashCode() == 42) return@l
return@l
}
run<MyUnit> l@ {
if ("0".hashCode() == 42) return@l
return@l Unit
}
}
@@ -0,0 +1,20 @@
// ISSUE: KT-66512
typealias MyUnit = Unit
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedMyUnitExplicitReturnString: () -> MyUnit = <!INITIALIZER_TYPE_MISMATCH!>l@ {
return@l ""
}<!>
// ============== Lambdas passed as function argument ===============
fun test() {
run<MyUnit> l@ {
return@l <!ARGUMENT_TYPE_MISMATCH, RETURN_TYPE_MISMATCH!>""<!>
}
}
@@ -0,0 +1,20 @@
// ISSUE: KT-66512
typealias MyUnit = Unit
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedMyUnitExplicitReturnString: () -> MyUnit = l@ {
return@l <!TYPE_MISMATCH!>""<!>
}
// ============== Lambdas passed as function argument ===============
fun test() {
run<MyUnit> l@ {
return@l <!TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
}
}
@@ -0,0 +1,125 @@
// ISSUE: KT-66534
// WITH_STDLIB
// FILE: A.java
import org.jetbrains.annotations.NotNull;
import kotlin.jvm.functions.Function0;
import kotlin.Unit;
public class A {
public static @NotNull Function0<Unit> foo;
public static void run(@NotNull Function0<Unit> foo) {}
}
// FILE: main.kt
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedNullableUnitEmptyReturnAndString: () -> Unit? = l@ {
if ("0".hashCode() == 42) return@l
""
}
fun expectedFlexibleUnitEmptyReturnAndString() {
A.foo = l@ {
if ("0".hashCode() == 42) return@l
""
}
}
val expectedNullableUnitEmptyReturnAndExplicitReturnNull: () -> Unit? = l@ {
if ("0".hashCode() == 42) return@l
return@l <!NULL_FOR_NONNULL_TYPE!>null<!>
}
fun expectedFlexibleUnitEmptyReturnAndExplicitReturnNull() {
A.foo = l@ {
if ("0".hashCode() == 42) return@l
return@l <!NULL_FOR_NONNULL_TYPE!>null<!>
}
}
val expectedNullableUnitExplicitReturnUnitAndString: () -> Unit? = <!INITIALIZER_TYPE_MISMATCH!>l@ {
if ("0".hashCode() == 42) return@l Unit
""
}<!>
fun expectedFlexibleUnitExplicitReturnUnitAndString() {
A.foo = l@ <!ASSIGNMENT_TYPE_MISMATCH!>{
if ("0".hashCode() == 42) return@l Unit
""
}<!>
}
val expectedNullableUnitExplicitReturnString: () -> Unit? = <!INITIALIZER_TYPE_MISMATCH!>l@ {
return@l ""
}<!>
fun expectedFlexibleUnitExplicitReturnString() {
A.foo = l@ <!ASSIGNMENT_TYPE_MISMATCH!>{
return@l ""
}<!>
}
val expectedNullableUnitExplicitReturnNull: () -> Unit? = l@ {
return@l null
}
fun expectedFlexibleUnitExplicitReturnNull() {
A.foo = l@ {
return@l null
}
}
// ============== Lambdas passed as function argument ===============
fun test() {
run<Unit?> l@ {
if ("0".hashCode() == 42) return@l
""
}
A.run l@ {
if ("0".hashCode() == 42) return@l
""
}
run<Unit?> l@ {
if ("0".hashCode() == 42) return@l
return@l <!NULL_FOR_NONNULL_TYPE!>null<!>
}
A.run l@ {
if ("0".hashCode() == 42) return@l
return@l null
}
run<Unit?> l@ {
if ("0".hashCode() == 42) return@l Unit
<!ARGUMENT_TYPE_MISMATCH!>""<!>
}
A.run l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
run<Unit?> l@ {
return@l <!ARGUMENT_TYPE_MISMATCH, RETURN_TYPE_MISMATCH!>""<!>
}
A.run l@ {
return@l <!ARGUMENT_TYPE_MISMATCH, RETURN_TYPE_MISMATCH!>""<!>
}
run<Unit?> l@ {
return@l null
}
A.run l@ {
return@l null
}
}
@@ -0,0 +1,125 @@
// ISSUE: KT-66534
// WITH_STDLIB
// FILE: A.java
import org.jetbrains.annotations.NotNull;
import kotlin.jvm.functions.Function0;
import kotlin.Unit;
public class A {
public static @NotNull Function0<Unit> foo;
public static void run(@NotNull Function0<Unit> foo) {}
}
// FILE: main.kt
// Note that resolution works differently for lambdas passed as function arguments and lambdas assigned to variables,
// thus we need to test both cases.
// ================= Lambdas assigned to a variable =================
val expectedNullableUnitEmptyReturnAndString: () -> Unit? = l@ {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@l<!>
<!TYPE_MISMATCH!>""<!>
}
fun expectedFlexibleUnitEmptyReturnAndString() {
A.foo = l@ {
if ("0".hashCode() == 42) return@l
""
}
}
val expectedNullableUnitEmptyReturnAndExplicitReturnNull: () -> Unit? = l@ {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@l<!>
return@l <!RETURN_TYPE_MISMATCH!>null<!>
}
fun expectedFlexibleUnitEmptyReturnAndExplicitReturnNull() {
A.foo = l@ {
if ("0".hashCode() == 42) return@l
return@l <!RETURN_TYPE_MISMATCH!>null<!>
}
}
val expectedNullableUnitExplicitReturnUnitAndString: () -> Unit? = l@ {
if ("0".hashCode() == 42) return@l Unit
<!TYPE_MISMATCH!>""<!>
}
fun expectedFlexibleUnitExplicitReturnUnitAndString() {
A.foo = l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
}
val expectedNullableUnitExplicitReturnString: () -> Unit? = l@ {
return@l <!TYPE_MISMATCH!>""<!>
}
fun expectedFlexibleUnitExplicitReturnString() {
A.foo = l@ {
return@l <!TYPE_MISMATCH!>""<!>
}
}
val expectedNullableUnitExplicitReturnNull: () -> Unit? = l@ {
return@l null
}
fun expectedFlexibleUnitExplicitReturnNull() {
A.foo = l@ {
return@l null
}
}
// ============== Lambdas passed as function argument ===============
fun test() {
run<Unit?> l@ {
if ("0".hashCode() == 42) return@l
""
}
A.run l@ {
if ("0".hashCode() == 42) return@l
""
}
run<Unit?> l@ {
if ("0".hashCode() == 42) return@l
return@l <!RETURN_TYPE_MISMATCH!>null<!>
}
A.run l@ {
if ("0".hashCode() == 42) return@l
return@l <!RETURN_TYPE_MISMATCH!>null<!>
}
run<Unit?> l@ {
if ("0".hashCode() == 42) return@l Unit
<!TYPE_MISMATCH!>""<!>
}
A.run l@ {
if ("0".hashCode() == 42) return@l Unit
""
}
run<Unit?> l@ {
return@l <!TYPE_MISMATCH!>""<!>
}
A.run l@ {
return@l <!TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
}
run<Unit?> l@ {
return@l null
}
A.run l@ {
return@l null
}
}
@@ -14199,6 +14199,30 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt");
}
@Test
@TestMetadata("kt66277.kt")
public void testKt66277() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66277.kt");
}
@Test
@TestMetadata("kt66279.kt")
public void testKt66279() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66279.kt");
}
@Test
@TestMetadata("kt66512.kt")
public void testKt66512() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66512.kt");
}
@Test
@TestMetadata("kt66534.kt")
public void testKt66534() {
runTest("compiler/testData/diagnostics/tests/functionLiterals/return/kt66534.kt");
}
@Test
@TestMetadata("LambdaReturnTypeIsUnitIfImplicitReturnExists.kt")
public void testLambdaReturnTypeIsUnitIfImplicitReturnExists() {