From 2f367b013ae6438b00f92b5ff39119a098d3a6fb Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 29 Nov 2023 11:58:29 +0100 Subject: [PATCH] K2: Don't lose constraint errors in the builder inference session Pass constraint errors from the integration system into a candidate to make sure it is reported later. Related to KT-59426, KT-59437, KT-53749 #KT-55168 Submitted --- .../builderInference/ifInBuildMap.fir.txt | 2 +- .../builderInference/ifInBuildMap.kt | 4 +- .../inference/FirBuilderInferenceSession.kt | 10 ++++- .../FirDelegatedPropertyInferenceSession.kt | 3 +- .../resolve/inference/FirInferenceSession.kt | 5 ++- .../inference/PostponedArgumentsAnalyzer.kt | 2 +- .../model/FirConstraintPositionAndErrors.kt | 40 +++++++++++++++---- .../constraints/violating.fir.kt | 8 ++-- .../stubTypes/capturedTypes.fir.kt | 4 +- .../stubTypes/capturedTypesId.fir.kt | 4 +- .../stubTypes/memberScope.fir.kt | 28 ++++++------- .../buildListRemoveAddInBranches.fir.kt | 4 +- .../inconsistentTypeInference.fir.diag.txt | 1 + .../inconsistentTypeInference.fir.kt | 4 +- .../inconsistentTypeInference.fir.txt | 2 +- .../inconsistentTypeInference2.fir.diag.txt | 1 + .../inconsistentTypeInference2.fir.kt | 6 +-- .../inconsistentTypeInference2.fir.txt | 2 +- .../builderInference/unsafeAssignment.fir.kt | 4 +- .../unsafeAssignmentExtra.fir.kt | 8 ++-- .../unsafeAssignmentExtra.fir.txt | 4 +- .../upperBoundViolation.fir.diag.txt | 1 + .../upperBoundViolation.fir.kt | 4 +- .../upperBoundViolation.fir.txt | 2 +- ...extensionWithNonValuableConstraints.fir.kt | 4 +- .../coroutines/inference/kt35684.fir.kt | 4 +- 26 files changed, 99 insertions(+), 62 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.diag.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.diag.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.diag.txt diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.fir.txt index 99a02b2f38a..c3a4e3980c7 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.fir.txt @@ -1,6 +1,6 @@ FILE: ifInBuildMap.kt public final fun main(): R|kotlin/Unit| { - R|kotlin/collections/buildMap|( = buildMap@fun R|kotlin/collections/MutableMap|.(): R|kotlin/Unit| { + R|kotlin/collections/buildMap#|( = buildMap@fun R|kotlin/collections/MutableMap|.(): R|kotlin/Unit| { when () { Boolean(true) -> { R|kotlin/io/println|(String(test)) diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.kt b/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.kt index b8c4ebc2474..49573748f7c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.kt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/builderInference/ifInBuildMap.kt @@ -2,11 +2,11 @@ // ISSUE: KT-51143 fun main() { - buildMap { + buildMap { if (true) { println("test") } else { put("foo", "bar") } - } + } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt index df31b4f5019..f29c29240bf 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.resolve.inference +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction @@ -13,6 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.hasAnnotation import org.jetbrains.kotlin.fir.expressions.FirResolvable import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.languageVersionSettings import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext @@ -117,7 +119,8 @@ class FirBuilderInferenceSession( override fun inferPostponedVariables( lambda: ResolvedLambdaAtom, constraintSystemBuilder: ConstraintSystemBuilder, - completionMode: ConstraintSystemCompletionMode + completionMode: ConstraintSystemCompletionMode, + candidate: Candidate ): Map? { val (commonSystem, effectivelyEmptyConstraintSystem) = buildCommonSystem(constraintSystemBuilder.currentStorage()) val resultingSubstitutor by lazy { getResultingSubstitutor(commonSystem) } @@ -142,6 +145,11 @@ class FirBuilderInferenceSession( constraintSystemBuilder.substituteFixedVariables(resultingSubstitutor) } + if (!session.languageVersionSettings.supportsFeature(LanguageFeature.NoAdditionalErrorsInK1DiagnosticReporter)) { + for (error in commonSystem.errors) { + candidate.system.addError(error) + } + } updateCalls(resultingSubstitutor) @Suppress("UNCHECKED_CAST") diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt index 8c20a0f06b6..4e5283f7dc0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt @@ -79,7 +79,8 @@ class FirDelegatedPropertyInferenceSession( override fun inferPostponedVariables( lambda: ResolvedLambdaAtom, constraintSystemBuilder: ConstraintSystemBuilder, - completionMode: ConstraintSystemCompletionMode + completionMode: ConstraintSystemCompletionMode, + candidate: Candidate ): Map? = null fun completeCandidates(): List { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt index fdfd6b04039..13c37c6918e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt @@ -39,7 +39,7 @@ abstract class FirInferenceSession { lambda: ResolvedLambdaAtom, constraintSystemBuilder: ConstraintSystemBuilder, completionMode: ConstraintSystemCompletionMode, - // TODO: diagnostic holder + candidate: Candidate ): Map? abstract fun clear() @@ -55,7 +55,8 @@ abstract class FirStubInferenceSession : FirInferenceSession() { override fun inferPostponedVariables( lambda: ResolvedLambdaAtom, constraintSystemBuilder: ConstraintSystemBuilder, - completionMode: ConstraintSystemCompletionMode + completionMode: ConstraintSystemCompletionMode, + candidate: Candidate ): Map? = null override fun registerStubTypes(map: Map) {} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt index 7d55da93d83..da59c999ec8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt @@ -214,7 +214,7 @@ class PostponedArgumentsAnalyzer( c.resolveForkPointsConstraints() if (inferenceSession != null) { - val postponedVariables = inferenceSession.inferPostponedVariables(lambda, builder, completionMode) + val postponedVariables = inferenceSession.inferPostponedVariables(lambda, builder, completionMode, candidate) if (postponedVariables == null) { builder.removePostponedVariables() diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt index 18da64d9042..37b13313336 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt @@ -8,28 +8,52 @@ package org.jetbrains.kotlin.fir.resolve.inference.model import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.render +import org.jetbrains.kotlin.fir.types.ConeTypeVariable import org.jetbrains.kotlin.fir.types.FirTypeProjection import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.types.model.TypeVariableMarker -class ConeDeclaredUpperBoundConstraintPosition : DeclaredUpperBoundConstraintPosition(null) +class ConeDeclaredUpperBoundConstraintPosition : DeclaredUpperBoundConstraintPosition(null) { + override fun toString(): String = "DeclaredUpperBound" +} -class ConeFixVariableConstraintPosition(variable: TypeVariableMarker) : FixVariableConstraintPosition(variable, null) +class ConeFixVariableConstraintPosition(variable: TypeVariableMarker) : FixVariableConstraintPosition(variable, null) { + override fun toString(): String = "Fix variable ${(variable as ConeTypeVariable).typeConstructor.name}" +} -class ConeArgumentConstraintPosition(argument: FirElement) : ArgumentConstraintPosition(argument) +class ConeArgumentConstraintPosition(argument: FirElement) : ArgumentConstraintPosition(argument) { + override fun toString(): String { + return "Argument ${argument.render()}" + } +} -object ConeExpectedTypeConstraintPosition : ExpectedTypeConstraintPosition(null) +object ConeExpectedTypeConstraintPosition : ExpectedTypeConstraintPosition(null) { + override fun toString(): String = "ExpectedType for some call" +} class ConeExplicitTypeParameterConstraintPosition( typeArgument: FirTypeProjection, -) : ExplicitTypeParameterConstraintPosition(typeArgument) +) : ExplicitTypeParameterConstraintPosition(typeArgument) { + override fun toString(): String = "TypeParameter ${typeArgument.render()}" +} class ConeLambdaArgumentConstraintPosition( anonymousFunction: FirAnonymousFunction -) : LambdaArgumentConstraintPosition(anonymousFunction) +) : LambdaArgumentConstraintPosition(anonymousFunction) { + override fun toString(): String { + return "LambdaArgument" + } +} class ConeBuilderInferenceSubstitutionConstraintPosition(initialConstraint: InitialConstraint) : - BuilderInferenceSubstitutionConstraintPosition(null, initialConstraint) // TODO + BuilderInferenceSubstitutionConstraintPosition(null, initialConstraint) { + override fun toString(): String = "Incorporated builder inference constraint $initialConstraint " + + "into some call" +} -class ConeReceiverConstraintPosition(receiver: FirExpression) : ReceiverConstraintPosition(receiver) +class ConeReceiverConstraintPosition(receiver: FirExpression) : ReceiverConstraintPosition(receiver) { + override fun toString(): String = "Receiver ${argument.render()}" + +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt index cfd7f7be523..684db09bf6c 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt @@ -13,10 +13,10 @@ fun main() { override fun foo(): MutableList = this@buildList } } - buildList { + buildList { add(3) val x: String = get(0) - } + } buildList { add("3") val x: MutableList = this@buildList @@ -26,8 +26,8 @@ fun main() { add(y) val x: MutableList = this@buildList } - buildList { + buildList { add("") val x: StringBuilder = get(0) - } + } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt index 2f277f0f465..8c5bef933d3 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt @@ -26,7 +26,7 @@ fun captureIn(x: Inv): K = null as K fun capture(x: Inv): K = null as K fun main() { - build { + build { emit("") getInv() captureOut(getInv()) @@ -35,7 +35,7 @@ fun main() { // K is fixed into CapturedType(out NotFixed: TypeVariable(R)) capture(getOut()) "" - } + } build { emit("") // K is fixed into CapturedType(in NotFixed: TypeVariable(R)) diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt index 5d3650f590b..772c869896b 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt @@ -19,13 +19,13 @@ fun capture(x: Inv): K = null as K fun id(x: I): I = null as I fun main() { - build { + build { emit("") // K is fixed into CapturedType(out NotFixed: TypeVariable(R) capture(id(getOut())) // unexpected TYPE_MISMATCH (KT-63996) // capture(getOut()) // OK!!! Unit - } + } build { emit("") // K is fixed into CapturedType(out NotFixed: TypeVariable(R) diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt index c0b696939d5..752eace55bf 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt @@ -17,7 +17,7 @@ fun Any.test() {} fun Any?.test2() {} fun test() { - val ret1 = build { + val ret1 = build { emit(1) emit(null) get()?.test() @@ -27,8 +27,8 @@ fun test() { get()?.equals(1) // there is `String?.equals` extension get().equals("") - } - val ret2 = build { + } + val ret2 = build { emit(1) emit(null) get()?.test() @@ -40,8 +40,8 @@ fun test() { x?.hashCode() x?.equals(1) x.equals("") - } - val ret3 = build { + } + val ret3 = build { emit(1) emit(null) get()?.test() @@ -68,7 +68,7 @@ fun test() { } "" - } + } val ret4 = build { emit(1) emit(null) @@ -149,15 +149,15 @@ fun test() { "" } - val ret408 = build { + val ret408 = build { emit(1) emit(null) val x = get() x.test() "" - } - val ret41 = build { + } + val ret41 = build { emit(1) emit(null) get()?.test() @@ -205,7 +205,7 @@ fun test() { } "" - } + } val ret5 = build { emit(1) emit(null) @@ -280,14 +280,14 @@ fun test() { } "" } - val ret508 = build { + val ret508 = build { emit(1) emit(null) val x = get() x.test() "" - } - val ret51 = build { + } + val ret51 = build { emit(1) emit(null) get()?.test() @@ -310,5 +310,5 @@ fun test() { } "" - } + } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListRemoveAddInBranches.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListRemoveAddInBranches.fir.kt index 59e95babbc7..59d01212ac0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListRemoveAddInBranches.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListRemoveAddInBranches.fir.kt @@ -1,8 +1,8 @@ // ISSUE: KT-55168 -fun foo(arg: Boolean) = buildList { +fun foo(arg: Boolean) = buildList { if (arg) { removeLast() } else { add(42) } -} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.diag.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.diag.txt new file mode 100644 index 00000000000..c66826a0ea9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.diag.txt @@ -0,0 +1 @@ +/inconsistentTypeInference.fir.kt:(62,127): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList <: kotlin/collections/Collection from Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Receiver this@R|special/anonymous| into some call into some call from position Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Receiver this@R|special/anonymous| into some call into some call: kotlin/String buildList { add("Boom") println(plus(1)[0]) - } + } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt index 82139b95be6..9db449a5b2f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt @@ -1,6 +1,6 @@ FILE: inconsistentTypeInference.fir.kt public final fun foo(): R|kotlin/Unit| { - R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + R|kotlin/collections/buildList#|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|SubstitutionOverride|(String(Boom)) R|kotlin/io/println|(this@R|special/anonymous|.R|kotlin/collections/plus|(Int(1)).R|SubstitutionOverride|(Int(0))) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.diag.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.diag.txt new file mode 100644 index 00000000000..8da00671c6b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.diag.txt @@ -0,0 +1 @@ +/inconsistentTypeInference2.fir.kt:(62,132): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList <: kotlin/collections/Collection from Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Receiver this@R|special/anonymous| into some call into some call from position Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Incorporated builder inference constraint kotlin/collections/MutableList <: kotlin/collections/Collection from Receiver this@R|special/anonymous| into some call into some call: kotlin/String buildList { add("Boom") println(this.plus(1)[0]) - } -} \ No newline at end of file + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt index 7f74bfb99e0..160d14f56e2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt @@ -1,6 +1,6 @@ FILE: inconsistentTypeInference2.fir.kt public final fun bar(): R|kotlin/Unit| { - R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + R|kotlin/collections/buildList#|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|SubstitutionOverride|(String(Boom)) R|kotlin/io/println|(this@R|special/anonymous|.R|kotlin/collections/plus|(Int(1)).R|SubstitutionOverride|(Int(0))) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.fir.kt index 37881c5d718..45e780862a1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.fir.kt @@ -7,7 +7,7 @@ fun myBuilder(block: Foo.() -> Unit) : Foo = Foo().apply(bloc fun main(arg: Any) { val x = 57 - val value = myBuilder { + val value = myBuilder { doSmthng("one ") run { a; this }.a = 10 a += 1 @@ -19,6 +19,6 @@ fun main(arg: Any) { if (arg is String) { a = arg } - } + } println(value.a?.count { it in 'l' .. 'q' }) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.kt index 5473410b04a..cc39de190c8 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.kt @@ -60,18 +60,18 @@ fun main(arg: Any, condition: Boolean) { } // See KT-54664 - val value3 = myBuilder { + val value3 = myBuilder { accept("") a = 45 bar(::a) - } + } fun baz(t: Int) {} - val value4 = myBuilder { + val value4 = myBuilder { accept("") a = 45 b[0] = 123 baz(a) - } + } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt index 09adea5d716..0de1e0aafa6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt @@ -91,7 +91,7 @@ FILE: unsafeAssignmentExtra.fir.kt } ) - lval value3: R|Foo| = R|/myBuilder|( = myBuilder@fun R|Foo|.(): R|kotlin/Unit| { + lval value3: R|Foo| = R|/myBuilder#|( = myBuilder@fun R|Foo|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|SubstitutionOverride|(String()) this@R|special/anonymous|.R|SubstitutionOverride| = Int(45) R|/bar|(::R|SubstitutionOverride|) @@ -100,7 +100,7 @@ FILE: unsafeAssignmentExtra.fir.kt local final fun baz(t: R|kotlin/Int|): R|kotlin/Unit| { } - lval value4: R|Foo & java/io/Serializable)>| = R|/myBuilder| & java/io/Serializable)|>( = myBuilder@fun R|Foo & java/io/Serializable)>|.(): R|kotlin/Unit| { + lval value4: R|Foo & java/io/Serializable)>| = R|/myBuilder#| & java/io/Serializable)|>( = myBuilder@fun R|Foo & java/io/Serializable)>|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|SubstitutionOverride|(String()) this@R|special/anonymous|.R|SubstitutionOverride| = Int(45) this@R|special/anonymous|.R|SubstitutionOverride|>|.R|SubstitutionOverride|(Int(0), Int(123)) diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.diag.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.diag.txt new file mode 100644 index 00000000000..43456d803d3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.diag.txt @@ -0,0 +1 @@ +/upperBoundViolation.fir.kt:(150,260): error: New inference error [NewConstraintError at Incorporate TypeVariable(E) <: kotlin/Number from Incorporated builder inference constraint Stub (chain inference): TypeVariable(E) <: kotlin/Number from Incorporated builder inference constraint TypeVariable(T) <: kotlin/Number from DeclaredUpperBound into some call into some call from position Incorporated builder inference constraint Stub (chain inference): TypeVariable(E) <: kotlin/Number from Incorporated builder inference constraint TypeVariable(T) <: kotlin/Number from DeclaredUpperBound into some call into some call: kotlin/String printGenericNumber(t: T) = println("Number is $t") fun main() { - buildList { // inferred into MutableList + buildList { // inferred into MutableList add("Boom") printGenericNumber(this[0]) - } + } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.txt index a1bd80e056d..178c1a165b0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.fir.txt @@ -3,7 +3,7 @@ FILE: upperBoundViolation.fir.kt ^printGenericNumber R|kotlin/io/println|((String(Number is ), R|/t|)) } public final fun main(): R|kotlin/Unit| { - R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + R|kotlin/collections/buildList#|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|SubstitutionOverride|(String(Boom)) R|/printGenericNumber|(this@R|special/anonymous|.R|SubstitutionOverride|(Int(0))) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt index c5dd98d7c5d..e2af7d4371a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt @@ -50,10 +50,10 @@ val test6 = generate { invNullableAnyExtension() } -val test7 = generate { +val test7 = generate { yield("baz") genericExtension() -} +} val test8 = generate { safeExtension() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt index 2ec35f51572..a8933940d5d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt @@ -12,8 +12,8 @@ fun test_1() { } fun test_2() { - sequence { - yield(materialize()) + sequence { + yield(materialize()) } }