Inference for type alias constructor type arguments: better error reporting.

This commit is contained in:
Dmitry Petrov
2016-11-09 16:32:19 +03:00
parent 94d7bd7a6b
commit 549ae59562
10 changed files with 123 additions and 40 deletions
@@ -1,26 +1,30 @@
class Num<Tn : Number>(val x: Tn)
typealias N<T> = Num<T>
val test0 = N(1)
val test1 = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED(Type parameter bound for Tn in type inferred from type alias expansion for fun <T> <init>\(x: T\): Num<T>
is not satisfied: inferred type String is not a subtype of Number)!>N<!>("1")
class Cons<T>(val head: T, val tail: Cons<T>?)
typealias C<T> = Cons<T>
typealias CC<T> = C<C<T>>
val test2 = <!TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>C<!>(1, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>)
val test3 = <!TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>CC<!>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>)
val test4 = CC(C(1, null), null)
class Pair<X, Y>(val x: X, val y: Y)
typealias PL<T> = Pair<T, List<T>>
typealias PN<T> = Pair<T, Num<T>>
val test5 = <!TYPE_INFERENCE_INCORPORATION_ERROR!>PL<!>(1, <!NULL_FOR_NONNULL_TYPE!>null<!>)
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)
@@ -3,23 +3,14 @@ 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 val test3: [ERROR : Type for CC(1, 2)]
public val test4: Cons<Cons<kotlin.Int>>
public val test5: Pair<kotlin.Int, kotlin.collections.List<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
@@ -53,9 +44,9 @@ public final class Pair</*0*/ X, /*1*/ Y> {
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>>
public typealias PN</*0*/ T> = Pair<T, Num<T>>
@@ -0,0 +1,5 @@
class Cons<T : Number>(val head: T, val tail: Cons<T>?)
typealias C<T> = Cons<T>
val test1 = C(1, C(2, null))
val test2 = C(1, <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>C<!>("", null))
@@ -0,0 +1,14 @@
package
public val test1: Cons<kotlin.Int>
public val test2: Cons<kotlin.Int>
public final class Cons</*0*/ T : kotlin.Number> {
public constructor Cons</*0*/ T : kotlin.Number>(/*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 typealias C</*0*/ T> = Cons<T>
@@ -0,0 +1,16 @@
class Foo<A : Number>
class Bar<B : CharSequence>
class Hr<A, B, C, D>(val a: A, val b: B)
typealias Test<A, B> = Hr<A, B, Foo<A>, Bar<B>>
val test1 = Test(1, "")
val test2 = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED(Type parameter bound for B in type inferred from type alias expansion for fun <A, B> <init>\(a: A, b: B\): Hr<A, B, Foo<A>, Bar<B>>
is not satisfied: inferred type Int is not a subtype of CharSequence)!>Test<!>(1, 2)
typealias Bas<T> = Hr<T, T, Foo<T>, Bar<T>>
val test3 = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED(Type parameter bound for B in type inferred from type alias expansion for fun <T> <init>\(a: T, b: T\): Hr<T, T, Foo<T>, Bar<T>>
is not satisfied: inferred type Int is not a subtype of CharSequence)!>Bas<!>(1, 1)
@@ -0,0 +1,30 @@
package
public val test1: Hr<kotlin.Int, kotlin.String, Foo<kotlin.Int>, Bar<kotlin.String>>
public val test2: [ERROR : Type for Test(1, 2)]
public val test3: [ERROR : Type for Bas(1, 1)]
public final class Bar</*0*/ B : kotlin.CharSequence> {
public constructor Bar</*0*/ B : kotlin.CharSequence>()
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*/ A : kotlin.Number> {
public constructor Foo</*0*/ A : kotlin.Number>()
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 Hr</*0*/ A, /*1*/ B, /*2*/ C, /*3*/ D> {
public constructor Hr</*0*/ A, /*1*/ B, /*2*/ C, /*3*/ D>(/*0*/ a: A, /*1*/ b: B)
public final val a: A
public final val b: B
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 Bas</*0*/ T> = Hr<T, T, Foo<T>, Bar<T>>
public typealias Test</*0*/ A, /*1*/ B> = Hr<A, B, Foo<A>, Bar<B>>