K2: Use correct position for substitution constrains in builder inference
Before, we were wrapping the original constraint position into ConeBuilderInferenceSubstitutionConstraintPosition twice during the constraint substitution in builder inference. It was causing problems with diagnostic reporting. Remove TODOs about diagnostic reporting from FirBuilderInferenceSession. Propagation of errors from the common system is now implemented Diagnostic reporting in updateCalls isn't needed, since we report errors after the system completion unlike K1 Relates to KT-53749
This commit is contained in:
committed by
Space Team
parent
2f367b013a
commit
d46075a9db
+15
-14
@@ -174,11 +174,6 @@ class FirBuilderInferenceSession(
|
||||
if (hasConstraints) effectivelyEmptyCommonSystem = false
|
||||
}
|
||||
|
||||
// TODO: add diagnostics holder
|
||||
// for (diagnostic in diagnostics) {
|
||||
// commonSystem.addError(diagnostic)
|
||||
// }
|
||||
|
||||
return commonSystem to effectivelyEmptyCommonSystem
|
||||
}
|
||||
|
||||
@@ -252,11 +247,9 @@ class FirBuilderInferenceSession(
|
||||
receiver.updateTypeInBuilderInference(substitutor.substituteOrSelf(receiver.type))
|
||||
}
|
||||
|
||||
// TODO: support diagnostics, see [CoroutineInferenceSession#updateCalls]
|
||||
val completionResultsWriter = components.callCompleter.createCompletionResultsWriter(substitutor)
|
||||
for ((call, _) in partiallyResolvedCalls) {
|
||||
call.transformSingle(completionResultsWriter, null)
|
||||
// TODO: support diagnostics, see [CoroutineInferenceSession#updateCalls]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,12 +300,15 @@ class FirBuilderInferenceSession(
|
||||
substitutor: TypeSubstitutorMarker,
|
||||
fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>
|
||||
): InitialConstraint {
|
||||
val substituted = substitute(substitutor)
|
||||
// TODO: invalid naming. It doesn't make sense case of equality constraints
|
||||
val substitutedLowerType = substitutor.safeSubstitute(resolutionContext.typeContext, this.a)
|
||||
val substitutedUpperType = substitutor.safeSubstitute(resolutionContext.typeContext, this.b)
|
||||
|
||||
val a = a
|
||||
// In situation when some type variable _T is fixed to Stub(_T)?,
|
||||
// we are not allowed just to substitute Stub(_T) with T because nullabilities are different here!
|
||||
// To compensate this, we have to substitute Stub(_T) <: SomeType constraint with T <: SomeType? adding nullability to upper type
|
||||
if (a is ConeStubTypeForChainInference && substituted.a !is ConeStubTypeForChainInference) {
|
||||
if (a is ConeStubTypeForChainInference && substitutedLowerType !is ConeStubTypeForChainInference) {
|
||||
val constructor = a.constructor
|
||||
val fixedTypeVariableType = fixedTypeVariables[constructor.variable.typeConstructor]
|
||||
if (fixedTypeVariableType is ConeStubTypeForChainInference &&
|
||||
@@ -320,14 +316,19 @@ class FirBuilderInferenceSession(
|
||||
fixedTypeVariableType.isMarkedNullable
|
||||
) {
|
||||
return InitialConstraint(
|
||||
substituted.a,
|
||||
(substituted.b as ConeKotlinType).withNullability(ConeNullability.NULLABLE, resolutionContext.typeContext),
|
||||
substituted.constraintKind,
|
||||
substituted.position
|
||||
substitutedLowerType,
|
||||
(substitutedUpperType as ConeKotlinType).withNullability(ConeNullability.NULLABLE, resolutionContext.typeContext),
|
||||
constraintKind,
|
||||
position
|
||||
)
|
||||
}
|
||||
}
|
||||
return substituted
|
||||
return InitialConstraint(
|
||||
substitutedLowerType,
|
||||
substitutedUpperType,
|
||||
constraintKind,
|
||||
position
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -13,7 +13,7 @@ fun main() {
|
||||
override fun foo(): MutableList<String> = <!RETURN_TYPE_MISMATCH!>this@buildList<!>
|
||||
}
|
||||
}
|
||||
<!NEW_INFERENCE_ERROR!>buildList {
|
||||
<!TYPE_MISMATCH!>buildList {
|
||||
add(3)
|
||||
val x: String = <!INITIALIZER_TYPE_MISMATCH!>get(0)<!>
|
||||
}<!>
|
||||
@@ -26,7 +26,7 @@ fun main() {
|
||||
add(y)
|
||||
val x: MutableList<String> = <!INITIALIZER_TYPE_MISMATCH!>this@buildList<!>
|
||||
}
|
||||
<!NEW_INFERENCE_ERROR!>buildList {
|
||||
<!TYPE_MISMATCH!>buildList {
|
||||
add("")
|
||||
val x: StringBuilder = <!INITIALIZER_TYPE_MISMATCH!>get(0)<!>
|
||||
}<!>
|
||||
|
||||
Vendored
+3
-3
@@ -1,8 +1,8 @@
|
||||
// ISSUE: KT-55168
|
||||
fun foo(arg: Boolean) = <!NEW_INFERENCE_ERROR!>buildList {
|
||||
fun foo(arg: Boolean) = buildList {
|
||||
if (arg) {
|
||||
removeLast()
|
||||
} else {
|
||||
add(42)
|
||||
add(<!ARGUMENT_TYPE_MISMATCH!>42<!>)
|
||||
}
|
||||
}<!>
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
/inconsistentTypeInference.fir.kt:(62,127): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList<TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call from position Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call: kotlin/String <!: kotlin/Int].
|
||||
/inconsistentTypeInference.fir.kt:(62,127): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList<TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call from position Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call: kotlin/String <!: kotlin/Int].
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
/inconsistentTypeInference2.fir.kt:(62,132): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList<TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call from position Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call: kotlin/String <!: kotlin/Int].
|
||||
/inconsistentTypeInference2.fir.kt:(62,132): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList<TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call from position Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call: kotlin/String <!: kotlin/Int].
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ fun <T : Any> myBuilder(block: Foo<T>.() -> Unit) : Foo<T> = Foo<T>().apply(bloc
|
||||
|
||||
fun main(arg: Any) {
|
||||
val x = 57
|
||||
val value = <!NEW_INFERENCE_ERROR!>myBuilder {
|
||||
val value = <!TYPE_MISMATCH, TYPE_MISMATCH!>myBuilder {
|
||||
doSmthng("one ")
|
||||
run { a; this }.a = 10
|
||||
<!BUILDER_INFERENCE_STUB_RECEIVER!>a += 1<!>
|
||||
|
||||
Vendored
+6
-6
@@ -60,18 +60,18 @@ fun main(arg: Any, condition: Boolean) {
|
||||
}
|
||||
|
||||
// See KT-54664
|
||||
val value3 = <!NEW_INFERENCE_ERROR!>myBuilder {
|
||||
val value3 = myBuilder {
|
||||
accept("")
|
||||
a = 45
|
||||
bar(::a)
|
||||
}<!>
|
||||
bar(<!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>::a<!>)
|
||||
}
|
||||
|
||||
fun baz(t: Int) {}
|
||||
|
||||
val value4 = <!NEW_INFERENCE_ERROR!>myBuilder {
|
||||
val value4 = myBuilder {
|
||||
accept("")
|
||||
a = 45
|
||||
b[0] = 123
|
||||
baz(a)
|
||||
}<!>
|
||||
baz(<!ARGUMENT_TYPE_MISMATCH!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1 +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 <!: kotlin/Number].
|
||||
/upperBoundViolation.fir.kt:(150,260): error: New inference error [NewConstraintError at Incorporate TypeVariable(E) <: kotlin/Number from Incorporated builder inference constraint TypeVariable(T) <: kotlin/Number from DeclaredUpperBound into some call from position Incorporated builder inference constraint TypeVariable(T) <: kotlin/Number from DeclaredUpperBound into some call: kotlin/String <!: kotlin/Number].
|
||||
|
||||
+3
-3
@@ -7,6 +7,6 @@ class Controller<T : Number> {
|
||||
|
||||
fun <S : Number> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
|
||||
|
||||
val test = <!NEW_INFERENCE_ERROR!>generate {
|
||||
yield("foo")
|
||||
}<!>
|
||||
val test = generate {
|
||||
yield(<!ARGUMENT_TYPE_MISMATCH!>"foo"<!>)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user