diff --git a/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.kt b/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.kt new file mode 100644 index 00000000000..a6774970834 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.kt @@ -0,0 +1,5 @@ +fun foo(f: (Y) -> Z, g: (X) -> Y, x: X): Z = f(g(x)) + +// TODO: Actually, this is a bug and will work when new inference is enabled +// see ([NI] Select variable with proper non-trivial constraint first) for more details +fun test() = foo({ it + 1 }, { it.length }, "") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.txt b/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.txt new file mode 100644 index 00000000000..b6f9ba817fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.txt @@ -0,0 +1,4 @@ +package + +public fun foo(/*0*/ f: (Y) -> Z, /*1*/ g: (X) -> Y, /*2*/ x: X): Z +public fun test(): [ERROR : Error function type] diff --git a/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.kt b/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.kt new file mode 100644 index 00000000000..ed26c78819f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.kt @@ -0,0 +1,9 @@ +typealias SuspendFn = suspend () -> Unit + +val test1f: suspend () -> Unit = fun () {} +val test2f: suspend Any.() -> Unit = fun Any.() {} + +// This is a bug in the old inference and should be fixed in new inference +// see "Fix anonymous function literals handling in type checker" for more deatils +val test3f: suspend Any.(Int) -> Int = fun (k: Int) = k + 1 +val test4f: SuspendFn = fun Any.() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.txt b/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.txt new file mode 100644 index 00000000000..02442939dea --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.txt @@ -0,0 +1,7 @@ +package + +public val test1f: suspend () -> kotlin.Unit +public val test2f: suspend kotlin.Any.() -> kotlin.Unit +public val test3f: suspend kotlin.Any.(kotlin.Int) -> kotlin.Int +public val test4f: SuspendFn /* = suspend () -> kotlin.Unit */ +public typealias SuspendFn = suspend () -> kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt index b4a37af6028..d54b82ca84d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt @@ -4,8 +4,3 @@ val test1: suspend () -> Unit = {} val test2: suspend Any.() -> Unit = {} val test3: suspend Any.(Int) -> Int = { k: Int -> k + 1 } val test4: SuspendFn = {} - -val test1f: suspend () -> Unit = fun () {} -val test2f: suspend Any.() -> Unit = fun Any.() {} -val test3f: suspend Any.(Int) -> Int = fun (k: Int) = k + 1 -val test4f: SuspendFn = fun Any.() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.txt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.txt index b2e8169f135..b16b1d8303d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.txt @@ -1,11 +1,7 @@ package public val test1: suspend () -> kotlin.Unit -public val test1f: suspend () -> kotlin.Unit public val test2: suspend kotlin.Any.() -> kotlin.Unit -public val test2f: suspend kotlin.Any.() -> kotlin.Unit public val test3: suspend kotlin.Any.(kotlin.Int) -> kotlin.Int -public val test3f: suspend kotlin.Any.(kotlin.Int) -> kotlin.Int public val test4: SuspendFn /* = suspend () -> kotlin.Unit */ -public val test4f: SuspendFn /* = suspend () -> kotlin.Unit */ public typealias SuspendFn = suspend () -> kotlin.Unit diff --git a/compiler/testData/ir/irText/regressions/newInference/fixationOrder2.kt b/compiler/testData/ir/irText/regressions/newInference/fixationOrder2.kt deleted file mode 100644 index cce576bdfbd..00000000000 --- a/compiler/testData/ir/irText/regressions/newInference/fixationOrder2.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(f: (Y) -> Z, g: (X) -> Y, x: X): Z = f(g(x)) - -fun test() = foo({ it + 1 }, { it.length }, "") \ No newline at end of file diff --git a/compiler/testData/ir/irText/regressions/newInference/fixationOrder2.txt b/compiler/testData/ir/irText/regressions/newInference/fixationOrder2.txt deleted file mode 100644 index 4dbef142dd4..00000000000 --- a/compiler/testData/ir/irText/regressions/newInference/fixationOrder2.txt +++ /dev/null @@ -1,40 +0,0 @@ -FILE /fixationOrder2.kt - FUN public fun foo(f: (Y) -> Z, g: (X) -> Y, x: X): Z - TYPE_PARAMETER - TYPE_PARAMETER - TYPE_PARAMETER - VALUE_PARAMETER value-parameter f: (Y) -> Z - VALUE_PARAMETER value-parameter g: (X) -> Y - VALUE_PARAMETER value-parameter x: X - BLOCK_BODY - RETURN type=kotlin.Nothing from='foo((Y) -> Z, (X) -> Y, X): Z' - CALL 'invoke(Y): Z' type=Z origin=INVOKE - $this: GET_VAR 'value-parameter f: (Y) -> Z' type=(Y) -> Z origin=VARIABLE_AS_FUNCTION - p1: CALL 'invoke(X): Y' type=Y origin=INVOKE - $this: GET_VAR 'value-parameter g: (X) -> Y' type=(X) -> Y origin=VARIABLE_AS_FUNCTION - p1: GET_VAR 'value-parameter x: X' type=X origin=null - FUN public fun test(): kotlin.Int - BLOCK_BODY - RETURN type=kotlin.Nothing from='test(): Int' - CALL 'foo((Int) -> Int, (String) -> Int, String): Int' type=kotlin.Int origin=null - : String - : Int - : Int - f: BLOCK type=(kotlin.Int) -> kotlin.Int origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun (it: kotlin.Int): kotlin.Int - VALUE_PARAMETER value-parameter it: kotlin.Int - BLOCK_BODY - RETURN type=kotlin.Nothing from='(Int): Int' - CALL 'plus(Int): Int' type=kotlin.Int origin=PLUS - $this: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null - other: CONST Int type=kotlin.Int value='1' - FUNCTION_REFERENCE '(Int): Int' type=(kotlin.Int) -> kotlin.Int origin=LAMBDA - g: BLOCK type=(kotlin.String) -> kotlin.Int origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun (it: kotlin.String): kotlin.Int - VALUE_PARAMETER value-parameter it: kotlin.String - BLOCK_BODY - RETURN type=kotlin.Nothing from='(String): Int' - CALL '(): Int' type=kotlin.Int origin=GET_PROPERTY - $this: GET_VAR 'value-parameter it: String' type=kotlin.String origin=null - FUNCTION_REFERENCE '(String): Int' type=(kotlin.String) -> kotlin.Int origin=LAMBDA - x: CONST String type=kotlin.String value='' diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index fa9fa3c1741..6398f5afdc2 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10060,6 +10060,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("fixationOrderForProperConstraints.kt") + public void testFixationOrderForProperConstraints() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.kt"); + doTest(fileName); + } + @TestMetadata("flexibleTypesAsUpperBound.kt") public void testFlexibleTypesAsUpperBound() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/flexibleTypesAsUpperBound.kt"); @@ -10150,6 +10156,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("lambdaInValInitializerWithAnonymousFunctions.kt") + public void testLambdaInValInitializerWithAnonymousFunctions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.kt"); + doTest(fileName); + } + @TestMetadata("listConstructor.kt") public void testListConstructor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/listConstructor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 109a6c1b981..00b23025df5 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1104,12 +1104,6 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/regressions/newInference/fixationOrder1.kt"); doTest(fileName); } - - @TestMetadata("fixationOrder2.kt") - public void testFixationOrder2() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/regressions/newInference/fixationOrder2.kt"); - doTest(fileName); - } } }