[FIR] Pass bounds from original type to fully expanded ^KT-40203 Fixed
This commit is contained in:
committed by
teamcityserver
parent
f0f60907e2
commit
3dc0935da4
+26
-6
@@ -6,17 +6,15 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.calls
|
package org.jetbrains.kotlin.fir.resolve.calls
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRef
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
|
||||||
import org.jetbrains.kotlin.fir.renderWithType
|
import org.jetbrains.kotlin.fir.renderWithType
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
|
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeDeclaredUpperBoundConstraintPosition
|
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeDeclaredUpperBoundConstraintPosition
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExplicitTypeParameterConstraintPosition
|
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExplicitTypeParameterConstraintPosition
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||||
import org.jetbrains.kotlin.fir.typeContext
|
import org.jetbrains.kotlin.fir.typeContext
|
||||||
@@ -150,12 +148,34 @@ private fun createToFreshVariableSubstitutorAndAddInitialConstraints(
|
|||||||
for (index in typeParameters.indices) {
|
for (index in typeParameters.indices) {
|
||||||
val typeParameter = typeParameters[index]
|
val typeParameter = typeParameters[index]
|
||||||
val freshVariable = freshTypeVariables[index]
|
val freshVariable = freshTypeVariables[index]
|
||||||
//val position = DeclaredUpperBoundConstraintPosition(typeParameter)
|
|
||||||
|
|
||||||
for (upperBound in typeParameter.symbol.fir.bounds) {
|
val parameterSymbolFromExpandedClass = typeParameter.symbol.fir.getTypeParameterFromExpandedClass(index, session)
|
||||||
|
|
||||||
|
for (upperBound in parameterSymbolFromExpandedClass.bounds) {
|
||||||
freshVariable.addSubtypeConstraint(upperBound.coneType/*, position*/)
|
freshVariable.addSubtypeConstraint(upperBound.coneType/*, position*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return toFreshVariables to freshTypeVariables
|
return toFreshVariables to freshTypeVariables
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun FirTypeParameter.getTypeParameterFromExpandedClass(index: Int, session: FirSession): FirTypeParameter {
|
||||||
|
val containingDeclaration = containingDeclarationSymbol?.fir
|
||||||
|
if (containingDeclaration is FirRegularClass) {
|
||||||
|
return containingDeclaration.typeParameters.elementAtOrNull(index)?.symbol?.fir ?: this
|
||||||
|
} else if (containingDeclaration is FirTypeAlias) {
|
||||||
|
val typeParameterConeType = toConeType()
|
||||||
|
val expandedConeType = containingDeclaration.expandedTypeRef.coneType
|
||||||
|
val typeArgumentIndex = expandedConeType.typeArguments.indexOfFirst { it.type == typeParameterConeType }
|
||||||
|
val expandedTypeFir = expandedConeType.toSymbol(session)?.fir
|
||||||
|
if (expandedTypeFir is FirTypeParameterRefsOwner) {
|
||||||
|
val typeParameterFir = expandedTypeFir.typeParameters.elementAtOrNull(typeArgumentIndex)?.symbol?.fir ?: return this
|
||||||
|
if (expandedTypeFir is FirTypeAlias) {
|
||||||
|
return typeParameterFir.getTypeParameterFromExpandedClass(typeArgumentIndex, session)
|
||||||
|
}
|
||||||
|
return typeParameterFir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@ typealias N<T> = Num<T>
|
|||||||
typealias N2<T> = N<T>
|
typealias N2<T> = N<T>
|
||||||
|
|
||||||
val x1 = Num<<!UPPER_BOUND_VIOLATED!>String<!>>(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
val x1 = Num<<!UPPER_BOUND_VIOLATED!>String<!>>(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
||||||
val x2 = N<<!UPPER_BOUND_VIOLATED!>String<!>>("")
|
val x2 = N<<!UPPER_BOUND_VIOLATED!>String<!>>(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
||||||
val x3 = N2<<!UPPER_BOUND_VIOLATED!>String<!>>("")
|
val x3 = N2<<!UPPER_BOUND_VIOLATED!>String<!>>(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
||||||
|
|
||||||
class TColl<T, C : Collection<T>>
|
class TColl<T, C : Collection<T>>
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ class Num<Tn : Number>(val x: Tn)
|
|||||||
typealias N<T> = Num<T>
|
typealias N<T> = Num<T>
|
||||||
|
|
||||||
val test0 = N(1)
|
val test0 = N(1)
|
||||||
val test1 = N("1")
|
val test1 = N(<!ARGUMENT_TYPE_MISMATCH!>"1"<!>)
|
||||||
|
|
||||||
|
|
||||||
class Cons<T>(val head: T, val tail: Cons<T>?)
|
class Cons<T>(val head: T, val tail: Cons<T>?)
|
||||||
|
|||||||
+3
-3
@@ -14,6 +14,6 @@ typealias C<T> = Cons<T>
|
|||||||
typealias C2<T> = MapLike<T>
|
typealias C2<T> = MapLike<T>
|
||||||
|
|
||||||
val test1 = C(1, C(2, null))
|
val test1 = C(1, C(2, null))
|
||||||
val test2 = C(1, C("", null))
|
val test2 = C(1, C(<!ARGUMENT_TYPE_MISMATCH!>""<!>, null))
|
||||||
val test23 = C2(if (true) 1 else null)
|
val test23 = C2(<!ARGUMENT_TYPE_MISMATCH!>if (true) 1 else null<!>)
|
||||||
val test234 = C2(C2(if (true) 1 else null))
|
val test234 = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>C2<!>(C2(<!ARGUMENT_TYPE_MISMATCH!>if (true) 1 else null<!>))
|
||||||
|
|||||||
Vendored
+4
-4
@@ -28,14 +28,14 @@ val test3pr = <!INAPPLICABLE_CANDIDATE!>P2<!><String, Int, Int>(1, "")
|
|||||||
class Num<T : Number>(val x: T)
|
class Num<T : Number>(val x: T)
|
||||||
typealias N<T> = Num<T>
|
typealias N<T> = Num<T>
|
||||||
|
|
||||||
val testN0 = N("")
|
val testN0 = N(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
||||||
val testN1 = N<Int>(1)
|
val testN1 = N<Int>(1)
|
||||||
val testN1a = N<<!UPPER_BOUND_VIOLATED!>String<!>>("")
|
val testN1a = N<<!UPPER_BOUND_VIOLATED!>String<!>>(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
||||||
val testN2 = <!INAPPLICABLE_CANDIDATE!>N<!><Int, Int>(1)
|
val testN2 = <!INAPPLICABLE_CANDIDATE!>N<!><Int, Int>(1)
|
||||||
|
|
||||||
class MyPair<T1 : CharSequence, T2 : Number>(val string: T1, val number: T2)
|
class MyPair<T1 : CharSequence, T2 : Number>(val string: T1, val number: T2)
|
||||||
typealias MP<T1> = MyPair<String, T1>
|
typealias MP<T1> = MyPair<String, T1>
|
||||||
|
|
||||||
val testMP0 = MP<Int>("", 1)
|
val testMP0 = MP<Int>("", 1)
|
||||||
val testMP1 = MP(<!ARGUMENT_TYPE_MISMATCH!>1<!>, "")
|
val testMP1 = MP(<!ARGUMENT_TYPE_MISMATCH!>1<!>, <!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
||||||
val testMP2 = MP<String>("", "")
|
val testMP2 = MP<String>(<!ARGUMENT_TYPE_MISMATCH!>""<!>, <!ARGUMENT_TYPE_MISMATCH!>""<!>)
|
||||||
|
|||||||
Reference in New Issue
Block a user