[FIR] Add proper constraint if Unit upper bound leads to Unit lambda return type
#KT-63524 Fixed
This commit is contained in:
committed by
Space Team
parent
ce4eecebf4
commit
8a863e00ba
+6
@@ -17058,6 +17058,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UnitUpperboundLambdaReturnType.kt")
|
||||
public void testUnitUpperboundLambdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/UnitUpperboundLambdaReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsoundness1.kt")
|
||||
public void testUnsoundness1() throws Exception {
|
||||
|
||||
+6
@@ -17058,6 +17058,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UnitUpperboundLambdaReturnType.kt")
|
||||
public void testUnitUpperboundLambdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/UnitUpperboundLambdaReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsoundness1.kt")
|
||||
public void testUnsoundness1() throws Exception {
|
||||
|
||||
+6
@@ -17052,6 +17052,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UnitUpperboundLambdaReturnType.kt")
|
||||
public void testUnitUpperboundLambdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/UnitUpperboundLambdaReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsoundness1.kt")
|
||||
public void testUnsoundness1() throws Exception {
|
||||
|
||||
+6
@@ -17058,6 +17058,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UnitUpperboundLambdaReturnType.kt")
|
||||
public void testUnitUpperboundLambdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/UnitUpperboundLambdaReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsoundness1.kt")
|
||||
public void testUnsoundness1() throws Exception {
|
||||
|
||||
+2
-2
@@ -201,10 +201,10 @@ class PostponedArgumentsAnalyzer(
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasExpressionInReturnArguments && !lambdaExpectedTypeIsUnit) {
|
||||
if (!hasExpressionInReturnArguments) {
|
||||
builder.addSubtypeConstraint(
|
||||
components.session.builtinTypes.unitType.type,
|
||||
returnTypeRef.type,
|
||||
substitute(lambda.returnType),
|
||||
ConeLambdaArgumentConstraintPosition(lambda.atom)
|
||||
)
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// FIR_IDENTICAL
|
||||
// DIAGNOSTICS: -FINAL_UPPER_BOUND
|
||||
|
||||
fun <U : Unit> fork(task: () -> U) {}
|
||||
|
||||
fun test() {
|
||||
fork {}
|
||||
fork { Unit }
|
||||
fork { 42 }
|
||||
}
|
||||
Vendored
+2
-2
@@ -138,8 +138,8 @@ fun main() {
|
||||
* K <: (C) -> Unit -> TypeVariable(_RP1) >: C
|
||||
* K == (B) -> Unit -> TypeVariable(_RP1) == B
|
||||
*/
|
||||
val x17: (C) -> Unit = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>selectB(id <!ARGUMENT_TYPE_MISMATCH!>{ <!DEBUG_INFO_EXPRESSION_TYPE("B")!>it<!> }<!>, id <!ARGUMENT_TYPE_MISMATCH!>{ it }<!>, id<(B) -> Unit> { x -> x })<!>
|
||||
val x18: (C) -> Unit = <!TYPE_MISMATCH!>select(id <!ARGUMENT_TYPE_MISMATCH!>{ <!DEBUG_INFO_EXPRESSION_TYPE("C")!>it<!> }<!>, <!ARGUMENT_TYPE_MISMATCH!>{ <!DEBUG_INFO_EXPRESSION_TYPE("C")!>it<!> }<!>, id<(B) -> Unit> { x -> x })<!>
|
||||
val x17: (C) -> Unit = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>selectB(id <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>{ <!DEBUG_INFO_EXPRESSION_TYPE("B")!>it<!> }<!>, id <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>{ it }<!>, id<(B) -> Unit> { x -> x })<!>
|
||||
val x18: (C) -> Unit = <!TYPE_MISMATCH!>select(id <!ARGUMENT_TYPE_MISMATCH!>{ <!DEBUG_INFO_EXPRESSION_TYPE("C")!>it<!> }<!>, <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>{ <!DEBUG_INFO_EXPRESSION_TYPE("C")!>it<!> }<!>, id<(B) -> Unit> { x -> x })<!>
|
||||
|
||||
// Resolution of extension/non-extension functions combination
|
||||
val x19: String.() -> Unit = select(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Function1<kotlin.String, kotlin.Unit>")!>id { <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>this<!> }<!>, <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Function1<kotlin.String, kotlin.Unit>")!>id(fun(x: String) {})<!>)
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ fun main() {
|
||||
val x1: suspend (Int) -> Unit = takeSuspend(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>id { it }<!>, <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>{ x -> x }<!>)
|
||||
|
||||
// Here, the error should be
|
||||
val x2: (Int) -> Unit = <!INITIALIZER_TYPE_MISMATCH!>takeSuspend(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>id <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>{ it }<!><!>, <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>{ x -> x }<!>)<!>
|
||||
val x3: suspend (Int) -> Unit = takeSimpleFunction(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>id <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>{ it }<!><!>, <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>{ x -> x }<!>)
|
||||
val x2: (Int) -> Unit = <!INITIALIZER_TYPE_MISMATCH!>takeSuspend(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>id <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>{ it }<!><!>, <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>{ x -> x }<!>)<!>
|
||||
val x3: suspend (Int) -> Unit = takeSimpleFunction(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>id <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>{ it }<!><!>, <!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH, DEBUG_INFO_EXPRESSION_TYPE("kotlin.coroutines.SuspendFunction1<kotlin.Int, kotlin.Unit>")!>{ x -> x }<!>)
|
||||
val x4: (Int) -> Unit = takeSimpleFunction(<!ARGUMENT_TYPE_MISMATCH!>id<suspend (Int) -> Unit> {}<!>, <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Function1<kotlin.Int, kotlin.Unit>")!>{}<!>)
|
||||
}
|
||||
|
||||
Generated
+6
@@ -17058,6 +17058,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UnitUpperboundLambdaReturnType.kt")
|
||||
public void testUnitUpperboundLambdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/UnitUpperboundLambdaReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsoundness1.kt")
|
||||
public void testUnsoundness1() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user