diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index 19ca2983848..3ad3ceb12ef 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -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) diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.txt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.txt index ef4328d8e61..87752eda4ca 100644 --- a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.txt +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.txt @@ -12,7 +12,7 @@ package p { public final class M1 { public constructor M1() - public final val a: [ERROR : A] + public final val a: [ERROR : A] 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]): kotlin.Unit + public fun foo(/*0*/ a: [ERROR : A]): kotlin.Unit public final class A { public constructor A() @@ -41,7 +41,7 @@ package internal fun test(): kotlin.Unit package p { - public fun foo(/*0*/ a: [ERROR : A]): kotlin.Unit + public fun foo(/*0*/ a: [ERROR : A]): kotlin.Unit public final class A { // -- Module: -- diff --git a/compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.txt b/compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.txt index 3db995633dc..3b7288309c2 100644 --- a/compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.txt +++ b/compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.txt @@ -1,6 +1,6 @@ package -internal val b: [ERROR : B<*>] +internal val b: [ERROR : B] internal final class B { public constructor B() diff --git a/compiler/testData/diagnostics/tests/variance/InPosition.txt b/compiler/testData/diagnostics/tests/variance/InPosition.txt index da4ab828be8..3b26735009e 100644 --- a/compiler/testData/diagnostics/tests/variance/InPosition.txt +++ b/compiler/testData/diagnostics/tests/variance/InPosition.txt @@ -48,7 +48,7 @@ internal trait Test { 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]): kotlin.Unit + internal abstract fun neOk35(/*0*/ i: [ERROR : Inv]): kotlin.Unit internal abstract fun neOk4(/*0*/ i: Inv): kotlin.Unit internal abstract fun neOk5(/*0*/ i: Inv): kotlin.Unit internal abstract fun neOk6(/*0*/ i: In>): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/variance/InvariantPosition.txt b/compiler/testData/diagnostics/tests/variance/InvariantPosition.txt index 2d726581961..8a693c7ac9d 100644 --- a/compiler/testData/diagnostics/tests/variance/InvariantPosition.txt +++ b/compiler/testData/diagnostics/tests/variance/InvariantPosition.txt @@ -45,7 +45,7 @@ internal trait Test { 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] + internal abstract var neOk35: [ERROR : Inv] internal abstract var neOk4: Inv internal abstract var neOk5: Inv internal abstract var neOk6: In> diff --git a/compiler/testData/diagnostics/tests/variance/OutPosition.txt b/compiler/testData/diagnostics/tests/variance/OutPosition.txt index b1db67127f4..5c44a5b01e3 100644 --- a/compiler/testData/diagnostics/tests/variance/OutPosition.txt +++ b/compiler/testData/diagnostics/tests/variance/OutPosition.txt @@ -37,7 +37,7 @@ internal trait Test { 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] + internal abstract fun neOk35(): [ERROR : Inv] internal abstract fun neOk4(): Inv internal abstract fun neOk5(): Inv internal abstract fun neOk6(): Pair, I> diff --git a/compiler/testData/type/binding/explicit/errorPair.kt b/compiler/testData/type/binding/explicit/errorPair.kt index b4bceb63d14..85d755d370b 100644 --- a/compiler/testData/type/binding/explicit/errorPair.kt +++ b/compiler/testData/type/binding/explicit/errorPair.kt @@ -1,11 +1,11 @@ val foo: Pair>, String> = null!! /* psi: Pair>, String> -type: Pair<[ERROR : Pair>], String> +type: Pair<[ERROR : Pair]>, String> typeParameter: defined in kotlin.Pair - typeProjection: [ERROR : Pair>] + typeProjection: [ERROR : Pair]> psi: Pair> - type: [ERROR : Pair>] + type: [ERROR : Pair]> typeParameter: null typeProjection: List psi: List diff --git a/compiler/testData/type/binding/explicit/errorWithProjection.kt b/compiler/testData/type/binding/explicit/errorWithProjection.kt index 0523feba9a6..d794b6186c5 100644 --- a/compiler/testData/type/binding/explicit/errorWithProjection.kt +++ b/compiler/testData/type/binding/explicit/errorWithProjection.kt @@ -1,7 +1,7 @@ val foo: List = null!! /* psi: List -type: [ERROR : List] +type: [ERROR : List] typeParameter: null typeProjection: Int psi: Int diff --git a/compiler/testData/type/binding/explicit/list2.kt b/compiler/testData/type/binding/explicit/list2.kt index a089c0364a9..87e22e48cab 100644 --- a/compiler/testData/type/binding/explicit/list2.kt +++ b/compiler/testData/type/binding/explicit/list2.kt @@ -1,7 +1,7 @@ val foo: List> = null!! /* psi: List> -type: [ERROR : List>] +type: [ERROR : List]> typeParameter: null typeProjection: String psi: String diff --git a/compiler/testData/type/binding/implicit/errorPair.kt b/compiler/testData/type/binding/implicit/errorPair.kt index ba4b886d2df..c4e82dc5eff 100644 --- a/compiler/testData/type/binding/implicit/errorPair.kt +++ b/compiler/testData/type/binding/implicit/errorPair.kt @@ -3,11 +3,19 @@ fun getT(): T = null!! val foo = getT>, String>>() /* psi: val foo = getT>, String>>() -type: Pair<[ERROR : Pair>], String> +type: Pair<[ERROR : Pair]>, String> typeParameter: defined in kotlin.Pair - typeProjection: [ERROR : Pair>] + typeProjection: [ERROR : Pair]> psi: val foo = getT>, String>>() - type: [ERROR : Pair>] + type: [ERROR : Pair]> + typeParameter: null + typeProjection: List + psi: val foo = getT>, String>>() + type: List + typeParameter: defined in kotlin.List + typeProjection: Int + psi: val foo = getT>, String>>() + type: Int typeParameter: defined in kotlin.Pair typeProjection: String diff --git a/compiler/testData/type/binding/implicit/errorWithProjection.kt b/compiler/testData/type/binding/implicit/errorWithProjection.kt index 23eb5fe3931..0386e3f820e 100644 --- a/compiler/testData/type/binding/implicit/errorWithProjection.kt +++ b/compiler/testData/type/binding/implicit/errorWithProjection.kt @@ -3,5 +3,14 @@ fun getT(): T = null!! val foo = getT>() /* psi: val foo = getT>() -type: [ERROR : List] +type: [ERROR : List] + typeParameter: null + typeProjection: in Int + psi: val foo = getT>() + type: Int + + typeParameter: null + typeProjection: out Int + psi: val foo = getT>() + type: Int */ \ No newline at end of file diff --git a/compiler/testData/type/binding/implicit/list2.kt b/compiler/testData/type/binding/implicit/list2.kt index 1a0a29739b8..627aa137aa1 100644 --- a/compiler/testData/type/binding/implicit/list2.kt +++ b/compiler/testData/type/binding/implicit/list2.kt @@ -3,5 +3,18 @@ fun getT(): T = null!! val foo = getT>>() /* psi: val foo = getT>>() -type: [ERROR : List>] +type: [ERROR : List]> + typeParameter: null + typeProjection: String + psi: val foo = getT>>() + type: String + + typeParameter: null + typeProjection: List + psi: val foo = getT>>() + type: List + typeParameter: defined in kotlin.List + typeProjection: Int + psi: val foo = getT>>() + type: Int */ \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index 502a4e07c77..1bde2ed48ca 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -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.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 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 arguments; - private ErrorTypeImpl(@NotNull TypeConstructor constructor, @NotNull JetScope memberScope) { + private ErrorTypeImpl( + @NotNull TypeConstructor constructor, + @NotNull JetScope memberScope, + @NotNull List arguments + ) { this.constructor = constructor; this.memberScope = memberScope; + this.arguments = arguments; + } + + private ErrorTypeImpl(@NotNull TypeConstructor constructor, @NotNull JetScope memberScope) { + this(constructor, memberScope, Collections.emptyList()); } @NotNull @@ -413,7 +430,7 @@ public class ErrorUtils { @NotNull @Override public List 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, "...")); } } diff --git a/idea/testData/resolve/references/WrongNumberOfTypeArguments.kt b/idea/testData/resolve/references/WrongNumberOfTypeArguments.kt new file mode 100644 index 00000000000..fca2ff6eaf0 --- /dev/null +++ b/idea/testData/resolve/references/WrongNumberOfTypeArguments.kt @@ -0,0 +1,10 @@ +package foo + +class A + +class C +class C1 + +val v1 = CA>>() + +// REF: (foo).A diff --git a/idea/testData/resolve/references/WrongNumberOfTypeArguments2.kt b/idea/testData/resolve/references/WrongNumberOfTypeArguments2.kt new file mode 100644 index 00000000000..22647bdbf99 --- /dev/null +++ b/idea/testData/resolve/references/WrongNumberOfTypeArguments2.kt @@ -0,0 +1,10 @@ +package foo + +class A + +class C +class C2 + +val v1 = CA>>() + +// REF: (foo).A diff --git a/idea/testData/resolve/references/WrongNumberOfTypeArgumentsInSupertype.kt b/idea/testData/resolve/references/WrongNumberOfTypeArgumentsInSupertype.kt new file mode 100644 index 00000000000..0e8071fd19c --- /dev/null +++ b/idea/testData/resolve/references/WrongNumberOfTypeArgumentsInSupertype.kt @@ -0,0 +1,10 @@ +package foo + +class A + +class C +class C1 + +class D: CA>>() + +// REF: (foo).A diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveTestGenerated.java index db96e6e3646..10350831310 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveTestGenerated.java @@ -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})