[FIR] Introduce TYPE_ARGUMENTS_NOT_ALLOWED & some other type errors

This commit introduces several different things, in particular:
- check type arguments in expressions
- new TypeArgumentList node to deal with diagnostic source
- ConeDiagnostic was moved to fir:cones
- ConeIntermediateDiagnostic to use in inference (?) without reporting
- detailed diagnostics on error type
This commit is contained in:
Mikhail Glukhikh
2020-07-22 10:29:59 +03:00
parent c744dfba9c
commit 0804c6a0f3
196 changed files with 774 additions and 484 deletions
@@ -1,7 +1,7 @@
package p
public fun foo(a: Any) {
a is Map<Int>
a is <!OTHER_ERROR!>Map<Int><!>
a is Map
a is Map<out Any?, Any?>
a is Map<*, *>
@@ -1,6 +1,6 @@
public fun foo(a: Any, b: Map) {
public fun foo(a: Any, b: <!OTHER_ERROR!>Map<!>) {
when (a) {
is Map<Int> -> {}
is <!OTHER_ERROR!>Map<Int><!> -> {}
is Map -> {}
is Map<out Any?, Any?> -> {}
is Map<*, *> -> {}
@@ -1,7 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun <T> foo(t: T<String, Int>) {}
fun <T> foo(t: <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<String, Int><!>) {}
interface A
class B<T: A>
fun <T> foo1(t: T<B<String>>) {}
fun <T> foo1(t: <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<B<String>><!>) {}
@@ -18,11 +18,11 @@ fun <E> foo(x: Any, y: Any) : Any {
}
// bare type
if (y is Outer.Inner) {
if (y is <!OTHER_ERROR!>Outer.Inner<!>) {
return y
}
y as Outer<*>.Inner
y as <!OTHER_ERROR, OTHER_ERROR!>Outer<*>.Inner<!>
return C()
}
@@ -51,19 +51,19 @@ interface MessageManager9 : Manager<Message3> {
fun <T : Message3> execute4() {}
}
object MessageManager10 : Message5<Int>() {
object MessageManager10 : <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Message5<Int><!>() {
fun <T : Int> execute() {}
}
class MessageManager11<A> : Message5<Message5<A>>() {
fun <T : Message5<A>> execute() {}
class MessageManager11<A> : <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Message5<Message5<A>><!>() {
fun <T : <!OTHER_ERROR!>Message5<A><!>> execute() {}
}
data class MessageManager12(val x: Int) : Message5<Message2>() {
data class MessageManager12(val x: Int) : <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Message5<Message2><!>() {
fun <T : Message2> execute() {}
}
sealed class MessageManager13<A> : Message5<A>() {
sealed class MessageManager13<A> : <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Message5<A><!>() {
fun <T : A> execute() {}
}
@@ -29,8 +29,8 @@ fun test() {
a<Foo.Bar<Int>.Baz>()
}
fun <T: Foo<String.Bar>> x() {}
fun <T: <!OTHER_ERROR!>Foo<String.Bar><!>> x() {}
fun Foo<String>.Bar.ext() {}
fun ex1(a: Foo<String>.Bar<String>): Foo<String>.Bar<String> {
fun ex1(a: <!OTHER_ERROR!>Foo<String>.Bar<String><!>): <!OTHER_ERROR!>Foo<String>.Bar<String><!> {
}
@@ -15,7 +15,7 @@ class A {
// Does not work, could be Outer<String>.Inner<Int>
// TODO: Should work?
fun foo(x: Inner<Int>) {
fun foo(x: <!OTHER_ERROR!>Inner<Int><!>) {
// Inner<Char>() call use companion as implicit receiver
val y: Outer<String>.Inner<Char> = Inner<Char>()
}
@@ -15,7 +15,7 @@ class A {
// Does not work, could be Outer<String>.Inner<Int>
// TODO: Should work?
fun foo(x: Inner<Int>) {
fun foo(x: <!OTHER_ERROR!>Inner<Int><!>) {
// Inner<Char>() call use companion as implicit receiver
val y: Outer<String>.Inner<Char> = Inner<Char>()
}
@@ -7,14 +7,14 @@ open class Outer<X, Y> {
class Derived : Outer<String, Int>() {
fun foo(): Inner<Char> = null!!
fun baz(): Alias<Char> = null!!
fun baz(): <!OTHER_ERROR, OTHER_ERROR!>Alias<Char><!> = null!!
}
class A : Outer<Double, Short>() {
class B : Outer<Float, Long>() {
fun bar(): Inner<String> = null!!
fun x(): Alias<String> = null!!
fun x(): <!OTHER_ERROR, OTHER_ERROR!>Alias<String><!> = null!!
}
}
@@ -10,12 +10,12 @@ private fun <E> foobar() = {
fun a() = A<E, X, Y, Z>()
}
typealias LocalAlias<W> = A<E, X, Y, W>
typealias LocalAlias<W> = <!OTHER_ERROR!>A<E, X, Y, W><!>
}
class Derived : LocalOuter<Double, Short>() {
fun foo(): LocalInner<Long> = null!!
fun bar(): LocalAlias<Char> = null!!
fun bar(): <!OTHER_ERROR, OTHER_ERROR!>LocalAlias<Char><!> = null!!
}
Derived()
@@ -27,12 +27,12 @@ private fun noParameters() = {
fun a() = A<Any, X, Y, Z>()
}
typealias LocalAlias2<W> = A<Any, X, Y, W>
typealias LocalAlias2<W> = <!OTHER_ERROR!>A<Any, X, Y, W><!>
}
class Derived2 : LocalOuter2<Double, Short>() {
fun foo(): LocalInner2<Long> = null!!
fun bar(): LocalAlias2<Char> = null!!
fun bar(): <!OTHER_ERROR, OTHER_ERROR!>LocalAlias2<Char><!> = null!!
}
Derived2()
@@ -12,12 +12,12 @@ class Outer<T> {
fun a() = A<T, F, E, X, Y, Z>()
}
typealias LocalAlias<W> = A<T, F, E, X, Y, W>
typealias LocalAlias<W> = <!OTHER_ERROR!>A<T, F, E, X, Y, W><!>
}
class Derived : LocalOuter<Double, Short>() {
fun foo(): LocalInner<Long> = null!!
fun bar(): LocalAlias<Char> = null!!
fun bar(): <!OTHER_ERROR, OTHER_ERROR!>LocalAlias<Char><!> = null!!
}
Derived()
@@ -29,12 +29,12 @@ class Outer<T> {
fun a() = A<T, F, Any, X, Y, Z>()
}
typealias LocalAlias2<W> = A<T, F, Any, X, Y, W>
typealias LocalAlias2<W> = <!OTHER_ERROR!>A<T, F, Any, X, Y, W><!>
}
class Derived2 : LocalOuter2<Double, Short>() {
fun foo(): LocalInner2<Long> = null!!
fun bar(): LocalAlias2<Char> = null!!
fun bar(): <!OTHER_ERROR, OTHER_ERROR!>LocalAlias2<Char><!> = null!!
}
Derived2()
}
@@ -10,7 +10,7 @@ open class BaseDerived2<X> : BaseDerived1<String, X>()
class Derived : BaseDerived2<Int>() {
fun foo(): Inner<Char> = null!!
fun baz(): Alias<Char> = null!!
fun baz(): <!OTHER_ERROR, OTHER_ERROR!>Alias<Char><!> = null!!
}
fun foo() {
@@ -17,4 +17,4 @@ class Outer<E> {
class E
fun bar(x: Inner) {}
fun bar(x: <!OTHER_ERROR!>Inner<!>) {}
@@ -15,9 +15,9 @@ class A<T> {
val y: B<String>.C<String>? = null
val z: B<String>.D? = null
val c: C<Int>? = null
val d: D? = null
val c: <!OTHER_ERROR, OTHER_ERROR!>C<Int>?<!> = null
val d: <!OTHER_ERROR, OTHER_ERROR!>D?<!> = null
val innerMost: Innermost<String>? = null
val innerMost: <!OTHER_ERROR, OTHER_ERROR!>Innermost<String>?<!> = null
}
}
@@ -4,7 +4,7 @@
class Outer<T> {
inner class Inner
fun foo(x: Outer<String>.Inner, y: Outer.Inner, z: Inner) {
fun foo(x: Outer<String>.Inner, y: <!OTHER_ERROR!>Outer.Inner<!>, z: Inner) {
var inner = Inner()
x.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Inner>() }
x.checkType { _<Outer<String>.Inner>() }
@@ -38,14 +38,14 @@ fun ok4(): Outer.Obj.Nested2<A>.Inner5<B> = null!!
fun ok5(): test.Outer.Obj.Nested2<A>.Inner5<B> = null!!
// All arguments are resolved
fun errorTypeWithArguments(): Q<A>.W<B, C, D>.R.M = null!!
fun errorTypeWithArguments(): <!OTHER_ERROR!>Q<A>.W<B, C, D>.R.M<!> = null!!
fun error1(): Outer<A>.Inner<B>.Inner3<C, D> = null!!
fun error2(): Outer<A>.Inner<B, C, D>.Inner2 = null!!
fun error3(): Outer.Inner<A, B>.Inner3<C> = null!!
fun error2(): <!OTHER_ERROR!>Outer<A>.Inner<B, C, D>.Inner2<!> = null!!
fun error3(): <!OTHER_ERROR!>Outer.Inner<A, B>.Inner3<C><!> = null!!
fun error4(): Outer<A>.Nested<B>.Inner4<C> = null!!
fun error5(): Outer<A>.Obj.Nested2<B>.Inner5<C> = null!!
fun error6(): Outer.Obj<A>.Nested2<B>.Inner5<C> = null!!
fun error4(): <!OTHER_ERROR!>Outer<A>.Nested<B>.Inner4<C><!> = null!!
fun error5(): <!OTHER_ERROR!>Outer<A>.Obj.Nested2<B>.Inner5<C><!> = null!!
fun error6(): <!OTHER_ERROR!>Outer.Obj<A>.Nested2<B>.Inner5<C><!> = null!!
fun error7(): test<String>.Outer.Obj.Nested2<A>.Inner5<B> = null!!
fun error7(): <!OTHER_ERROR!>test<String>.Outer.Obj.Nested2<A>.Inner5<B><!> = null!!
@@ -1,14 +1,14 @@
interface I0<T : Unresolved0<String>>
interface I1<T> where T : Unresolved1<String>
interface I2<T : Unresolved2<String>> where T : Unresolved3<String>
interface I0<T : <!OTHER_ERROR!>Unresolved0<String><!>>
interface I1<T> where T : <!OTHER_ERROR!>Unresolved1<String><!>
interface I2<T : <!OTHER_ERROR!>Unresolved2<String><!>> where T : <!OTHER_ERROR!>Unresolved3<String><!>
fun <E : Unresolved4<String>> foo0() {}
fun <E> foo1() where E : Unresolved5<String> {}
fun <E : Unresolved6<String>> foo2() where E : Unresolved7<String> {}
fun <E : <!OTHER_ERROR!>Unresolved4<String><!>> foo0() {}
fun <E> foo1() where E : <!OTHER_ERROR!>Unresolved5<String><!> {}
fun <E : <!OTHER_ERROR!>Unresolved6<String><!>> foo2() where E : <!OTHER_ERROR!>Unresolved7<String><!> {}
val <E : Unresolved7> E.p1: Int
val <E : <!OTHER_ERROR!>Unresolved7<!>> E.p1: Int
get() = 1
val <E> E.p2: Int where E : Unresolved8
val <E> E.p2: Int where E : <!OTHER_ERROR!>Unresolved8<!>
get() = 1
val <E : Unresolved9> E.p3: Int where E : Unresolved10
val <E : <!OTHER_ERROR!>Unresolved9<!>> E.p3: Int where E : <!OTHER_ERROR!>Unresolved10<!>
get() = 1