diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/complexLambdaWithTypeVariableAsExpectedType.txt b/compiler/fir/analysis-tests/testData/resolve/problems/complexLambdaWithTypeVariableAsExpectedType.txt index 1ce8ca4e960..212f7b6226c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problems/complexLambdaWithTypeVariableAsExpectedType.txt +++ b/compiler/fir/analysis-tests/testData/resolve/problems/complexLambdaWithTypeVariableAsExpectedType.txt @@ -6,8 +6,8 @@ FILE: complexLambdaWithTypeVariableAsExpectedType.kt ^select R|kotlin/TODO|() } public final fun test(): R|kotlin/Unit| { - R|/select| kotlin/Unit|>(R|/id| kotlin/Int|>( = id@fun (it: R|kotlin/Int|): R|kotlin/Int| { - R|/it|.R|kotlin/Int.inv|() + R|/select| kotlin/Any|>(R|/id| kotlin/Int|>( = id@fun (it: R|kotlin/Int|): R|kotlin/Int| { + ^ R|/it|.R|kotlin/Int.inv|() } ), R|/id| kotlin/Unit|>( = id@fun (it: R|kotlin/Int|): R|kotlin/Unit| { ^@id Unit diff --git a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.txt b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.txt index 29cae7f7e3c..64f4440b089 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.txt @@ -8,7 +8,7 @@ FILE: main.kt ^ R|/x|.R|kotlin/Any.toString|() } ) - R|/MyFunction|!|>( = MyFunction@fun (x: R|ft?|): R|kotlin/String| { + R|/MyFunction|( = MyFunction@fun (x: R|ft!|): R|ft?| { ^ String() } ) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index f60e198ab8b..02ded0f33d3 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.* import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints import org.jetbrains.kotlin.resolve.calls.model.PostponedAtomWithRevisableExpectedType +import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeConstructorMarker import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.cast @@ -212,11 +213,16 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents) { val variableWithConstraints = notFixedTypeVariables.getValue(variableForFixation.variable) if (variableForFixation.hasProperConstraint) { - fixVariable(asConstraintSystemCompletionContext(), variableWithConstraints) + fixVariable(asConstraintSystemCompletionContext(), topLevelType, variableWithConstraints, postponedArguments) return true } else { // TODO("Not enough information for parameter") - fixVariable(asConstraintSystemCompletionContext(), variableWithConstraints) // means Nothing/Any instead of Error type + fixVariable( + asConstraintSystemCompletionContext(), + topLevelType, + variableWithConstraints, + postponedArguments + ) // means Nothing/Any instead of Error type } } @@ -299,13 +305,12 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents) { private fun fixVariable( c: ConstraintSystemCompletionContext, + topLevelType: KotlinTypeMarker, variableWithConstraints: VariableWithConstraints, + postponedResolveKtPrimitives: List ) { - val resultType = inferenceComponents.resultTypeResolver.findResultType( - c, - variableWithConstraints, - TypeVariableDirectionCalculator.ResolveDirection.UNKNOWN - ) + val direction = TypeVariableDirectionCalculator(c, postponedResolveKtPrimitives, topLevelType).getDirection(variableWithConstraints) + val resultType = inferenceComponents.resultTypeResolver.findResultType(c, variableWithConstraints, direction) val variable = variableWithConstraints.typeVariable c.fixVariable(variable, resultType, ConeFixVariableConstraintPosition(variable)) // TODO: obtain atom for diagnostics } diff --git a/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.fir.kt index aec54f0d794..dc35cde2de0 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.fir.kt @@ -19,6 +19,6 @@ fun testFunctions() { fun testNestedCalls() { id(inferFromLambda { materialize() }) - id(inferFromLambda(fun() = materialize())) - id(inferFromLambda2(fun() = materialize())) + id(inferFromLambda(fun() = materialize())) + id(inferFromLambda2(fun() = materialize())) } diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt index ac4946072b5..1dac5d3aeb0 100644 --- a/compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt @@ -7,8 +7,7 @@ fun foo() = foo() as T fun foo2(): T = TODO() -// TODO: "not enough information" should be reported on foo2() instead -val test = foo2().plus("") as String +val test = foo2().plus("") as String fun T.bar() = this val barTest = "".bar() as Number \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.fir.kt b/compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.fir.kt new file mode 100644 index 00000000000..2aa0ed9abff --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE +// WITH_RUNTIME + +import kotlin.experimental.ExperimentalTypeInference + +@UseExperimental(ExperimentalTypeInference::class) +fun combined( + check: () -> Unit, + @BuilderInference block: TestInterface.() -> Unit +): R = TODO() + +interface TestInterface { + fun emit(r: R) +} + +fun test() { + val ret = combined({ }) { + emit(1) + } +} diff --git a/compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt b/compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt index 058d3959182..72bcb817bda 100644 --- a/compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt +++ b/compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt index 34b6f6f2254..d26c5f6a750 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt @@ -10,7 +10,7 @@ interface A interface TypeConstructor class Refiner { - val memoizedFunctionLambda = createMemoizedFunction { it.foo() } // error type infered, no diagnostic, BAD, backend fails + val memoizedFunctionLambda = createMemoizedFunction { it.foo() } // error type infered, no diagnostic, BAD, backend fails val memoizedFunctionReference = createMemoizedFunction(TypeConstructor::foo) // EXTENSION_IN_CLASS_REFERENCE_IS_NOT_ALLOWED, fine val memoizedFunctionTypes = createMemoizedFunction { it.foo() } // works fine diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.fir.kt deleted file mode 100644 index ad18793da9d..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -// !LANGUAGE: -ExperimentalBuilderInference -// !DIAGNOSTICS: -UNUSED_PARAMETER - -interface Base - -interface Controller : Base { - suspend fun yield(t: T) {} -} - -fun generate(g: suspend Controller.() -> Unit): S = TODO() - -suspend fun Base.baseExtension() {} - -val test1 = generate { - yield("foo") - baseExtension() -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt index 460262f44a4..bcd4041ad8a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: -ExperimentalBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER @@ -12,6 +13,6 @@ fun generate(g: suspend Controller.() -> Unit): S = TODO() suspend fun Base.baseExtension() {} val test1 = generate { - yield("foo") + yield("foo") baseExtension() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt index ac991e566ba..abafc519962 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt @@ -20,7 +20,7 @@ suspend fun yield() {} fun test() { builder { - send(run { + send(run { yield() // No error but `yield` is not inside "suspension" context actually }) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/callableReferences.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/callableReferences.fir.kt index 76fd6e28d98..621c01262cd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/callableReferences.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/callableReferences.fir.kt @@ -34,24 +34,24 @@ fun main() { select(::foo, { it }) select(id(::foo), { x: Number -> }, { it }) - val x1 = select(")!>id(::foo), ")!>id { x: Number -> x }) - ")!>x1 + val x1 = select(")!>id(::foo), ")!>id { x: Number -> x }) + ")!>x1 val x11 = select(id(::foo), id { x: Number -> }, id { it }) - ")!>x11 + ")!>x11 - select(id(::foo2), id { x: Int -> }, id { it }) + select(id(::foo2), id { x: Int -> }, id { it }) select(id(")!>::foo3), id { x: Int -> }, id { it }) select(id(")!>::foo3), id { x: Number -> }, id { it }) select(id(")!>::foo3), id { x: Number -> }, id { x: Int -> }, id { it }) - select(id(::foo4), id { x: A -> }, id { it }) - select(id(::foo4), id { x: B -> }, id { it }) + select(id(")!>::foo4), id { x: A -> }, id { it }) + select(id(")!>::foo4), id { x: B -> }, id { it }) // Expected ambiguity - select(id(::foo4), id { x: A -> }, id { x: B -> }, id { it }) + select(id(::foo4), id { x: A -> }, id { x: B -> }, id { it }) select(id(::foo5), id { x: A -> }, id { x: B -> }, id { it }) - val x2: (Int) -> Unit = selectNumber(id(")!>::foo6), id { x -> x }, id { it }) + val x2: (Int) -> Unit = selectNumber(id(")!>::foo6), id { x -> x }, id { ")!>it }) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt index e3a4c42ee63..5b464405de2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt @@ -14,12 +14,12 @@ fun main() { select(")!>id {}, id(suspend {})) select(")!>id {}, id Unit> {}) - takeSuspend( & kotlin.coroutines.SuspendFunction1")!>id { it }, ")!>{ x -> x }) + takeSuspend(")!>id { it }, ")!>{ x -> x }) val x1: suspend (Int) -> Unit = takeSuspend(")!>id { it }, ")!>{ x -> x }) // Here, the error should be - val x2: (Int) -> Unit = takeSuspend( & kotlin.Function1")!>id { it }, ")!>{ x -> x }) - val x3: suspend (Int) -> Unit = takeSimpleFunction( & kotlin.coroutines.SuspendFunction1")!>id { it }, ")!>{ x -> x }) + val x2: (Int) -> Unit = takeSuspend(")!>id { it }, ")!>{ x -> x }) + val x3: suspend (Int) -> Unit = takeSimpleFunction(")!>id { it }, ")!>{ x -> x }) val x4: (Int) -> Unit = takeSimpleFunction(id Unit> {}, {}) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt deleted file mode 100644 index 42d31a64950..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt +++ /dev/null @@ -1,8 +0,0 @@ -// FILE: test.kt -typealias RunnableT = java.lang.Runnable -typealias ComparatorT = java.util.Comparator -typealias ComparatorStrT = ComparatorT - -val test1 = RunnableT { } -val test2 = ComparatorT { s1, s2 -> s1.compareTo(s2) } -val test3 = ComparatorStrT { s1, s2 -> s1.compareTo(s2) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt index a5e4f8db692..cdb81eea98e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: test.kt typealias RunnableT = java.lang.Runnable typealias ComparatorT = java.util.Comparator diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt index 8738d71769e..650f42d5269 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt @@ -23,5 +23,5 @@ typealias C2 = JHost.Consumer2 val test1 = R { } val test2 = C { s -> println(s.length) } val test3 = CStr { s -> println(s.length) } -val test4 = CStrList { ss -> for (s in ss) { println(s.length) } } -val test5 = C2 { a, b -> val x: Int = a + b; println(x)} +val test4 = CStrList { ss -> for (s in ss) { println(s.length) } } +val test5 = C2 { a, b -> val x: Int = a + b; println(x)} diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt index 4b17a42c762..a8fd4601329 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt @@ -11,7 +11,7 @@ import libCase1.* import kotlin.text.format fun case1() { - val y2 : () ->String =(String)::format + val y2 : () ->String =(String)::format } // FILE: LibCase1.kt