Star projections in type alias expansions are substituted to star projections
for corresponding type parameters in expanded type. Test that type alias arguments are substituted literally, and no type approximation is performed on substitution.
This commit is contained in:
@@ -103,6 +103,10 @@ class TypeAliasExpander(
|
||||
argumentVariance
|
||||
}
|
||||
|
||||
if (typeAliasArgument.isStarProjection) {
|
||||
return TypeUtils.makeStarProjection(typeParameterDescriptor!!)
|
||||
}
|
||||
|
||||
val substitutedType = TypeUtils.makeNullableIfNeeded(typeAliasArgument.type, originalType.isMarkedNullable)
|
||||
|
||||
return TypeProjectionImpl(substitutedVariance, substitutedType)
|
||||
@@ -165,7 +169,7 @@ class TypeAliasExpander(
|
||||
val typeSubstitutor = TypeSubstitutor.create(substitutedType)
|
||||
|
||||
substitutedType.arguments.forEachIndexed { i, substitutedArgument ->
|
||||
if (!substitutedArgument.type.containsTypeAliasParameters()) {
|
||||
if (!substitutedArgument.isStarProjection && !substitutedArgument.type.containsTypeAliasParameters()) {
|
||||
val unsubstitutedArgument = unsubstitutedType.arguments[i]
|
||||
val typeParameter = unsubstitutedType.constructor.parameters[i]
|
||||
DescriptorResolver.checkBoundsInTypeAlias(reportStrategy, unsubstitutedArgument.type, substitutedArgument.type, typeParameter, typeSubstitutor)
|
||||
|
||||
Vendored
+11
-4
@@ -1,7 +1,14 @@
|
||||
typealias Array2D<T> = Array<Array<T>>
|
||||
|
||||
fun foo(a: Array2D<out Number>) = a
|
||||
fun foo1(a: Array2D<out Number>) = a
|
||||
|
||||
fun bar(a: Array2D<Int>) {
|
||||
foo(<!TYPE_MISMATCH!>a<!>)
|
||||
}
|
||||
fun bar1(a: Array2D<Int>) =
|
||||
foo1(<!TYPE_MISMATCH(Array2D<out Number> [= Array<Array<out Number>>]; Array2D<Int> [= Array<Array<Int>>])!>a<!>)
|
||||
|
||||
|
||||
typealias TMap<T> = Map<T, T>
|
||||
|
||||
fun <T> foo2(m: TMap<T>) = m
|
||||
|
||||
fun bar2(m: TMap<*>) =
|
||||
<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>foo2<!>(m)
|
||||
|
||||
Vendored
+5
-2
@@ -1,5 +1,8 @@
|
||||
package
|
||||
|
||||
public typealias Array2D</*0*/ T> = kotlin.Array<kotlin.Array<T>>
|
||||
public fun bar(/*0*/ a: Array2D<kotlin.Int> [= kotlin.Array<kotlin.Array<kotlin.Int>>]): kotlin.Unit
|
||||
public fun foo(/*0*/ a: Array2D<out kotlin.Number> [= kotlin.Array<kotlin.Array<out kotlin.Number>>]): Array2D<out kotlin.Number> [= kotlin.Array<kotlin.Array<out kotlin.Number>>]
|
||||
public typealias TMap</*0*/ T> = kotlin.collections.Map<T, T>
|
||||
public fun bar1(/*0*/ a: Array2D<kotlin.Int> [= kotlin.Array<kotlin.Array<kotlin.Int>>]): Array2D<out kotlin.Number> [= kotlin.Array<kotlin.Array<out kotlin.Number>>]
|
||||
public fun bar2(/*0*/ m: TMap<*> [= kotlin.collections.Map<*, *>]): [ERROR : Error function type]
|
||||
public fun foo1(/*0*/ a: Array2D<out kotlin.Number> [= kotlin.Array<kotlin.Array<out kotlin.Number>>]): Array2D<out kotlin.Number> [= kotlin.Array<kotlin.Array<out kotlin.Number>>]
|
||||
public fun </*0*/ T> foo2(/*0*/ m: TMap<T> [= kotlin.collections.Map<T, out T>]): TMap<T> [= kotlin.collections.Map<T, out T>]
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class NumCharSeq<N : Number, M : CharSequence>(val n: N, val m: M)
|
||||
|
||||
typealias Test<X, Y> = NumCharSeq<X, Y>
|
||||
|
||||
fun getN(t: Test<*, *>) = t.n
|
||||
fun getM(t: Test<*, *>) = t.m
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package
|
||||
|
||||
public typealias Test</*0*/ X, /*1*/ Y> = NumCharSeq<X, Y>
|
||||
public fun getM(/*0*/ t: Test<*, *> [= NumCharSeq<*, *>]): kotlin.CharSequence
|
||||
public fun getN(/*0*/ t: Test<*, *> [= NumCharSeq<*, *>]): kotlin.Number
|
||||
|
||||
public final class NumCharSeq</*0*/ N : kotlin.Number, /*1*/ M : kotlin.CharSequence> {
|
||||
public constructor NumCharSeq</*0*/ N : kotlin.Number, /*1*/ M : kotlin.CharSequence>(/*0*/ n: N, /*1*/ m: M)
|
||||
public final val m: M
|
||||
public final val n: N
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -19605,6 +19605,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("starProjectionInTypeAliasArgument.kt")
|
||||
public void testStarProjectionInTypeAliasArgument() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/starProjectionInTypeAliasArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("substitutionVariance.kt")
|
||||
public void testSubstitutionVariance() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/substitutionVariance.kt");
|
||||
|
||||
Reference in New Issue
Block a user