Infer type arguments of type alias constructors.

This commit is contained in:
Dmitry Petrov
2016-11-08 15:38:03 +03:00
parent 9b55ad82a0
commit 03d8aa272b
14 changed files with 265 additions and 18 deletions
@@ -0,0 +1,13 @@
class Bound<X, Y : X>(val x: X, val y: Y)
typealias B<X, Y> = Bound<X, Y>
typealias BOutIn<T> = Bound<out List<T>, in T>
typealias BInIn<T> = Bound<in List<T>, in T>
fun <T> listOf(): List<T> = null!!
// Unresolved reference is ok here:
// we can't create a substituted signature for type alias constructor
// since it has 'out' type projection in 'in' position.
val test1 = <!UNRESOLVED_REFERENCE!>BOutIn<!>(<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>listOf<!>(), null!!)
val test2 = BInIn(listOf(), null!!)
@@ -0,0 +1,17 @@
package
public val test1: [ERROR : Type for BOutIn(listOf(), null!!)]
public val test2: Bound<in kotlin.collections.List<kotlin.Nothing>, in kotlin.Nothing>
public fun </*0*/ T> listOf(): kotlin.collections.List<T>
public final class Bound</*0*/ X, /*1*/ Y : X> {
public constructor Bound</*0*/ X, /*1*/ Y : X>(/*0*/ x: X, /*1*/ y: Y)
public final val x: X
public final val y: Y
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
}
public typealias B</*0*/ X, /*1*/ Y> = Bound<X, Y>
public typealias BInIn</*0*/ T> = Bound<in kotlin.collections.List<T>, in T>
public typealias BOutIn</*0*/ T> = Bound<out kotlin.collections.List<T>, in T>
@@ -0,0 +1,27 @@
class Num<Tn : Number>(val x: Tn)
typealias N<T> = Num<T>
class Cons<T>(val head: T, val tail: Cons<T>?)
typealias C<T> = Cons<T>
typealias CC<T> = C<C<T>>
class Pair<X, Y>(val x: X, val y: Y)
typealias PL<T> = Pair<T, List<T>>
class Bound<X, Y : X>(val x: X, val y: Y)
typealias B<X, Y> = Bound<X, Y>
class Foo<T>(val p: Pair<T, T>)
typealias F<T> = Foo<T>
val test0 = N(1)
val test1 = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>N<!>("1")
val test2 = <!TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>C<!>(1, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>)
val test3 = <!TYPE_INFERENCE_INCORPORATION_ERROR!>PL<!>(1, <!NULL_FOR_NONNULL_TYPE!>null<!>)
val test4 = <!TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>CC<!>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>)
val test4a = CC(C(1, null), null)
fun testProjections1(x: Pair<in Int, out String>) = <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>F<!>(x)
fun testProjections2(x: Pair<in Int, out Number>) = <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>F<!>(x)
fun testProjections3(x: Pair<in Number, out Int>) = <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>F<!>(x)
fun testProjections4(x: Pair<in Int, in Int>) = <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>F<!>(x)
@@ -0,0 +1,61 @@
package
public val test0: Num<kotlin.Int>
public val test1: [ERROR : Type for N("1")]
public val test2: Cons<kotlin.Int>
public val test3: Pair<kotlin.Int, kotlin.collections.List<kotlin.Int>>
public val test4: [ERROR : Type for CC(1, 2)]
public val test4a: Cons<Cons<kotlin.Int>>
public fun testProjections1(/*0*/ x: Pair<in kotlin.Int, out kotlin.String>): [ERROR : Error function type]
public fun testProjections2(/*0*/ x: Pair<in kotlin.Int, out kotlin.Number>): [ERROR : Error function type]
public fun testProjections3(/*0*/ x: Pair<in kotlin.Number, out kotlin.Int>): [ERROR : Error function type]
public fun testProjections4(/*0*/ x: Pair<in kotlin.Int, in kotlin.Int>): [ERROR : Error function type]
public final class Bound</*0*/ X, /*1*/ Y : X> {
public constructor Bound</*0*/ X, /*1*/ Y : X>(/*0*/ x: X, /*1*/ y: Y)
public final val x: X
public final val y: Y
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
}
public final class Cons</*0*/ T> {
public constructor Cons</*0*/ T>(/*0*/ head: T, /*1*/ tail: Cons<T>?)
public final val head: T
public final val tail: Cons<T>?
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
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ T>(/*0*/ p: Pair<T, T>)
public final val p: Pair<T, T>
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
}
public final class Num</*0*/ Tn : kotlin.Number> {
public constructor Num</*0*/ Tn : kotlin.Number>(/*0*/ x: Tn)
public final val x: Tn
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
}
public final class Pair</*0*/ X, /*1*/ Y> {
public constructor Pair</*0*/ X, /*1*/ Y>(/*0*/ x: X, /*1*/ y: Y)
public final val x: X
public final val y: Y
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
}
public typealias B</*0*/ X, /*1*/ Y> = Bound<X, Y>
public typealias C</*0*/ T> = Cons<T>
public typealias CC</*0*/ T> = C<C<T>>
public typealias F</*0*/ T> = Foo<T>
public typealias N</*0*/ T> = Num<T>
public typealias PL</*0*/ T> = Pair<T, kotlin.collections.List<T>>
@@ -6,18 +6,18 @@ typealias P2<T> = Pair<T, T>
typealias PR<T1, T2> = Pair<T2, T1>
val test0 = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>P<!>(1, 2)
val test0 = P(1, 2)
val test1 = P<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>(1, 2)
val test2 = P<Int, Int>(1, 2)
val test3 = P<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>(1, 2)
val test0p2 = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>P2<!>(1, 1)
val test0p2a = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>P2<!>(1, "")
val test0p2 = P2(1, 1)
val test0p2a = P2(1, "")
val test1p2 = P2<Int>(1, 1)
val test2p2 = P2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int><!>(1, 1)
val test3p2 = P2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>(1, 1)
val test0pr = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>PR<!>(1, "")
val test0pr = PR(1, "")
val test1pr = PR<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>(1, <!TYPE_MISMATCH!>""<!>)
val test2pr = PR<Int, String>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!TYPE_MISMATCH!>""<!>)
val test2pra = PR<String, Int>(1, "")
@@ -26,7 +26,7 @@ val test3pr = P2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, Int, Int><!>(<!CONSTA
class Num<T : Number>(val x: T)
typealias N<T> = Num<T>
val testN0 = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>N<!>("")
val testN0 = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>N<!>("")
val testN1 = N<Int>(1)
val testN1a = N<<!UPPER_BOUND_VIOLATED!>String<!>>("")
val testN2 = N<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int><!>(1)
@@ -14,7 +14,7 @@ public val test2pra: Pair<kotlin.Int, kotlin.String>
public val test3: Pair<kotlin.Int, kotlin.Int>
public val test3p2: Pair<kotlin.Int, kotlin.Int>
public val test3pr: Pair<kotlin.String, kotlin.String>
public val testN0: Num<kotlin.String>
public val testN0: [ERROR : Type for N("")]
public val testN1: Num<kotlin.Int>
public val testN1a: Num<kotlin.String>
public val testN2: Num<kotlin.Int>