KT-6751 References to type arguments of a type argument not resolved when wrong number of them

#KT-6751 Fixed
This commit is contained in:
Svetlana Isakova
2015-02-16 19:01:58 +03:00
parent f1774bd6fb
commit 204e9a0c34
17 changed files with 117 additions and 21 deletions
@@ -165,6 +165,7 @@ public class TypeResolver(
else {
c.trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type.getTypeArgumentList(), expectedArgumentCount))
}
result = type(ErrorUtils.createErrorTypeWithArguments("" + typeConstructor, arguments))
}
else {
if (Flexibility.FLEXIBLE_TYPE_CLASSIFIER.asSingleFqName() == DescriptorUtils.getFqName(classifierDescriptor)
@@ -12,7 +12,7 @@ package p {
public final class M1 {
public constructor M1()
public final val a: [ERROR : A<Int>]
public final val a: [ERROR : A]<kotlin.Int>
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
@@ -24,7 +24,7 @@ package p {
package
package p {
public fun foo(/*0*/ a: [ERROR : A<Int>]): kotlin.Unit
public fun foo(/*0*/ a: [ERROR : A]<kotlin.Int>): kotlin.Unit
public final class A</*0*/ X, /*1*/ Y> {
public constructor A</*0*/ X, /*1*/ Y>()
@@ -41,7 +41,7 @@ package
internal fun test(): kotlin.Unit
package p {
public fun foo(/*0*/ a: [ERROR : A<Int>]): kotlin.Unit
public fun foo(/*0*/ a: [ERROR : A]<kotlin.Int>): kotlin.Unit
public final class A</*0*/ X, /*1*/ Y> {
// -- Module: <m1> --
@@ -1,6 +1,6 @@
package
internal val b: [ERROR : B<*>]
internal val b: [ERROR : B]<out [ERROR : *]>
internal final class B {
public constructor B()
@@ -48,7 +48,7 @@ internal trait Test</*0*/ in I, /*1*/ out O, /*2*/ P> {
internal abstract fun neOk32(/*0*/ i: [ERROR : Inv]): kotlin.Unit
internal abstract fun neOk33(/*0*/ i: Inv<[ERROR : No type element]>): kotlin.Unit
internal abstract fun neOk34(/*0*/ i: Inv<[ERROR : C]>): kotlin.Unit
internal abstract fun neOk35(/*0*/ i: [ERROR : Inv<P, P>]): kotlin.Unit
internal abstract fun neOk35(/*0*/ i: [ERROR : Inv]<P, P>): kotlin.Unit
internal abstract fun neOk4(/*0*/ i: Inv<I>): kotlin.Unit
internal abstract fun neOk5(/*0*/ i: Inv<O>): kotlin.Unit
internal abstract fun neOk6(/*0*/ i: In<In<O>>): kotlin.Unit
@@ -45,7 +45,7 @@ internal trait Test</*0*/ in I, /*1*/ out O, /*2*/ P> {
internal abstract var neOk32: [ERROR : Inv]
internal abstract var neOk33: Inv<[ERROR : No type element]>
internal abstract var neOk34: Inv<[ERROR : C]>
internal abstract var neOk35: [ERROR : Inv<P, P>]
internal abstract var neOk35: [ERROR : Inv]<P, P>
internal abstract var neOk4: Inv<I>
internal abstract var neOk5: Inv<O>
internal abstract var neOk6: In<In<O>>
@@ -37,7 +37,7 @@ internal trait Test</*0*/ in I, /*1*/ out O, /*2*/ P> {
internal abstract fun neOk32(): [ERROR : Inv]
internal abstract fun neOk33(): Inv<[ERROR : No type element]>
internal abstract fun neOk34(): Inv<[ERROR : C]>
internal abstract fun neOk35(): [ERROR : Inv<P, P>]
internal abstract fun neOk35(): [ERROR : Inv]<P, P>
internal abstract fun neOk4(): Inv<I>
internal abstract fun neOk5(): Inv<O>
internal abstract fun neOk6(): Pair<In<O>, I>
@@ -1,11 +1,11 @@
val foo: Pair<Pair<List<Int>>, String> = null!!
/*
psi: Pair<Pair<List<Int>>, String>
type: Pair<[ERROR : Pair<List<Int>>], String>
type: Pair<[ERROR : Pair]<List<Int>>, String>
typeParameter: <out A> defined in kotlin.Pair
typeProjection: [ERROR : Pair<List<Int>>]
typeProjection: [ERROR : Pair]<List<Int>>
psi: Pair<List<Int>>
type: [ERROR : Pair<List<Int>>]
type: [ERROR : Pair]<List<Int>>
typeParameter: null
typeProjection: List<Int>
psi: List<Int>
@@ -1,7 +1,7 @@
val foo: List<in Int, out Int> = null!!
/*
psi: List<in Int, out Int>
type: [ERROR : List<in Int, out Int>]
type: [ERROR : List]<in Int, out Int>
typeParameter: null
typeProjection: Int
psi: Int
@@ -1,7 +1,7 @@
val foo: List<String, List<Int>> = null!!
/*
psi: List<String, List<Int>>
type: [ERROR : List<String, List<Int>>]
type: [ERROR : List]<String, List<Int>>
typeParameter: null
typeProjection: String
psi: String
@@ -3,11 +3,19 @@ fun <T> getT(): T = null!!
val foo = getT<Pair<Pair<List<Int>>, String>>()
/*
psi: val foo = getT<Pair<Pair<List<Int>>, String>>()
type: Pair<[ERROR : Pair<List<Int>>], String>
type: Pair<[ERROR : Pair]<List<Int>>, String>
typeParameter: <out A> defined in kotlin.Pair
typeProjection: [ERROR : Pair<List<Int>>]
typeProjection: [ERROR : Pair]<List<Int>>
psi: val foo = getT<Pair<Pair<List<Int>>, String>>()
type: [ERROR : Pair<List<Int>>]
type: [ERROR : Pair]<List<Int>>
typeParameter: null
typeProjection: List<Int>
psi: val foo = getT<Pair<Pair<List<Int>>, String>>()
type: List<Int>
typeParameter: <out E> defined in kotlin.List
typeProjection: Int
psi: val foo = getT<Pair<Pair<List<Int>>, String>>()
type: Int
typeParameter: <out B> defined in kotlin.Pair
typeProjection: String
@@ -3,5 +3,14 @@ fun <T> getT(): T = null!!
val foo = getT<List<in Int, out Int>>()
/*
psi: val foo = getT<List<in Int, out Int>>()
type: [ERROR : List<in Int, out Int>]
type: [ERROR : List]<in Int, out Int>
typeParameter: null
typeProjection: in Int
psi: val foo = getT<List<in Int, out Int>>()
type: Int
typeParameter: null
typeProjection: out Int
psi: val foo = getT<List<in Int, out Int>>()
type: Int
*/
@@ -3,5 +3,18 @@ fun <T> getT(): T = null!!
val foo = getT<List<String, List<Int>>>()
/*
psi: val foo = getT<List<String, List<Int>>>()
type: [ERROR : List<String, List<Int>>]
type: [ERROR : List]<String, List<Int>>
typeParameter: null
typeProjection: String
psi: val foo = getT<List<String, List<Int>>>()
type: String
typeParameter: null
typeProjection: List<Int>
psi: val foo = getT<List<String, List<Int>>>()
type: List<Int>
typeParameter: <out E> defined in kotlin.List
typeProjection: Int
psi: val foo = getT<List<String, List<Int>>>()
type: Int
*/
@@ -36,6 +36,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import static kotlin.KotlinPackage.joinToString;
public class ErrorUtils {
private static final ModuleDescriptor ERROR_MODULE;
@@ -346,7 +348,7 @@ public class ErrorUtils {
@NotNull
public static JetType createErrorType(@NotNull String debugMessage) {
return new ErrorTypeImpl(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage));
return createErrorTypeWithArguments(debugMessage, Collections.<TypeProjection>emptyList());
}
@NotNull
@@ -354,6 +356,11 @@ public class ErrorUtils {
return new ErrorTypeImpl(createErrorTypeConstructorWithCustomDebugName(debugName), createErrorScope(debugName));
}
@NotNull
public static JetType createErrorTypeWithArguments(@NotNull String debugMessage, @NotNull List<TypeProjection> arguments) {
return new ErrorTypeImpl(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments);
}
@NotNull
public static TypeConstructor createErrorTypeConstructor(@NotNull String debugMessage) {
return createErrorTypeConstructorWithCustomDebugName("[ERROR : " + debugMessage + "]");
@@ -398,10 +405,20 @@ public class ErrorUtils {
private static class ErrorTypeImpl implements JetType {
private final TypeConstructor constructor;
private final JetScope memberScope;
private final List<TypeProjection> arguments;
private ErrorTypeImpl(@NotNull TypeConstructor constructor, @NotNull JetScope memberScope) {
private ErrorTypeImpl(
@NotNull TypeConstructor constructor,
@NotNull JetScope memberScope,
@NotNull List<TypeProjection> arguments
) {
this.constructor = constructor;
this.memberScope = memberScope;
this.arguments = arguments;
}
private ErrorTypeImpl(@NotNull TypeConstructor constructor, @NotNull JetScope memberScope) {
this(constructor, memberScope, Collections.<TypeProjection>emptyList());
}
@NotNull
@@ -413,7 +430,7 @@ public class ErrorUtils {
@NotNull
@Override
public List<TypeProjection> getArguments() {
return Collections.emptyList();
return arguments;
}
@Override
@@ -446,7 +463,7 @@ public class ErrorUtils {
@Override
public String toString() {
return constructor.toString();
return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "..."));
}
}
@@ -0,0 +1,10 @@
package foo
class A
class C<T>
class C1<T>
val v1 = C<C1<A, <caret>A>>()
// REF: (foo).A
@@ -0,0 +1,10 @@
package foo
class A
class C<T>
class C2<T1, T2>
val v1 = C<C2<<caret>A>>()
// REF: (foo).A
@@ -0,0 +1,10 @@
package foo
class A
class C<T>
class C1<T>
class D: C<C1<A, <caret>A>>()
// REF: (foo).A
@@ -301,6 +301,24 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
doTest(fileName);
}
@TestMetadata("WrongNumberOfTypeArguments.kt")
public void testWrongNumberOfTypeArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/WrongNumberOfTypeArguments.kt");
doTest(fileName);
}
@TestMetadata("WrongNumberOfTypeArguments2.kt")
public void testWrongNumberOfTypeArguments2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/WrongNumberOfTypeArguments2.kt");
doTest(fileName);
}
@TestMetadata("WrongNumberOfTypeArgumentsInSupertype.kt")
public void testWrongNumberOfTypeArgumentsInSupertype() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/WrongNumberOfTypeArgumentsInSupertype.kt");
doTest(fileName);
}
@TestMetadata("idea/testData/resolve/references/delegatedPropertyAccessors")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({DelegatedPropertyAccessors.InSource.class, DelegatedPropertyAccessors.InStandardLibrary.class})