From 60a0cd8cfdc700677ce5b45fc05cfe9b41ce126d Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 1 Jul 2016 17:35:53 +0300 Subject: [PATCH] Do not add error types as upper bounds in type parameter #KT-10237 Fixed #KT-11821 Fixed #KT-8200 Fixed --- .../LazyTypeParameterDescriptor.java | 5 +- .../diagnostics/tests/MultipleBounds.txt | 4 +- .../CasesWithOneTypeParameter.txt | 2 +- .../generics/invalidArgumentsNumberInWhere.kt | 19 ++++++++ .../invalidArgumentsNumberInWhere.txt | 47 +++++++++++++++++++ .../generics/unresolvedClassifierInWhere.kt | 14 ++++++ .../generics/unresolvedClassifierInWhere.txt | 26 ++++++++++ .../classHeader/classGenericParameters.txt | 12 ++--- .../checkers/DiagnosticsTestGenerated.java | 12 +++++ .../impl/TypeParameterDescriptorImpl.java | 1 + 10 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.kt create mode 100644 compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.txt create mode 100644 compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt create mode 100644 compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyTypeParameterDescriptor.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyTypeParameterDescriptor.java index 46a1d639c42..cfcd6338e7e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyTypeParameterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyTypeParameterDescriptor.java @@ -76,7 +76,10 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri List upperBounds = new ArrayList(1); for (KtTypeReference typeReference : getAllUpperBounds()) { - upperBounds.add(resolveBoundType(typeReference)); + KotlinType resolvedType = resolveBoundType(typeReference); + if (!resolvedType.isError()) { + upperBounds.add(resolvedType); + } } if (upperBounds.isEmpty()) { diff --git a/compiler/testData/diagnostics/tests/MultipleBounds.txt b/compiler/testData/diagnostics/tests/MultipleBounds.txt index d58cb798f18..fbef2503c3f 100644 --- a/compiler/testData/diagnostics/tests/MultipleBounds.txt +++ b/compiler/testData/diagnostics/tests/MultipleBounds.txt @@ -30,8 +30,8 @@ package Jet87 { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - public final class Buzz> where T : [ERROR : nioho] { - public constructor Buzz>() where T : [ERROR : nioho] + public final class Buzz> { + public constructor Buzz>() 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 diff --git a/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.txt b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.txt index acfd6366da3..d43f76edcd0 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.txt +++ b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.txt @@ -1,6 +1,6 @@ package -public interface A> { +public interface 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 diff --git a/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.kt b/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.kt new file mode 100644 index 00000000000..b011ba7ca5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.kt @@ -0,0 +1,19 @@ +class A +interface I0> +interface I1 where T : A +interface I2<T : A> where T : A + +fun > foo0() {} +fun foo1() where E : A {} +fun <E : A> foo2() where E : A {} + +val > E.p1: Int + get() = 1 +val E.p2: Int where E : A + get() = 1 +val <E : A> E.p3: Int where E : A + get() = 1 + +// See KT-8200 +interface X +public class EnumAttribute<T : X>(val klass: Class) where T : Enum diff --git a/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.txt b/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.txt new file mode 100644 index 00000000000..2036e88a9ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.txt @@ -0,0 +1,47 @@ +package + +public val E.p1: kotlin.Int +public val E.p2: kotlin.Int +public val E.p3: kotlin.Int +public fun foo0(): kotlin.Unit +public fun foo1(): kotlin.Unit +public fun foo2(): kotlin.Unit + +public final class A { + public constructor 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 +} + +public final class EnumAttribute> { + public constructor EnumAttribute>(/*0*/ klass: java.lang.Class) + public final val klass: java.lang.Class + 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 interface I0 { + 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 interface I1 { + 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 interface I2 { + 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 interface X { + 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 +} diff --git a/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt b/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt new file mode 100644 index 00000000000..644d648bda2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt @@ -0,0 +1,14 @@ +interface I0Unresolved0> +interface I1 where T : Unresolved1 +interface I2<T : Unresolved2> where T : Unresolved3 + +fun Unresolved4> foo0() {} +fun foo1() where E : Unresolved5 {} +fun <E : Unresolved6> foo2() where E : Unresolved7 {} + +val Unresolved7> E.p1: Int + get() = 1 +val E.p2: Int where E : Unresolved8 + get() = 1 +val <E : Unresolved9> E.p3: Int where E : Unresolved10 + get() = 1 diff --git a/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.txt b/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.txt new file mode 100644 index 00000000000..3b1713428c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.txt @@ -0,0 +1,26 @@ +package + +public val E.p1: kotlin.Int +public val E.p2: kotlin.Int +public val E.p3: kotlin.Int +public fun foo0(): kotlin.Unit +public fun foo1(): kotlin.Unit +public fun foo2(): kotlin.Unit + +public interface I0 { + 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 interface I1 { + 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 interface I2 { + 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 +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt index 0a32fe8edd5..dd8239279a3 100644 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt @@ -1,12 +1,12 @@ package -public final class A { - public constructor A() +public final class A { + public constructor 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 - public final inner class Inner /*captured type parameters: /*0*/ T : [ERROR : Nested], /*1*/ F : [ERROR : Inner], /*2*/ G : [ERROR : Interace]*/ { + public final inner class Inner /*captured type parameters: /*0*/ T, /*1*/ F, /*2*/ G*/ { public constructor Inner() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @@ -27,13 +27,13 @@ public final class A { - public constructor B() +public final class B { + public constructor 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 final inner class Inner /*captured type parameters: /*0*/ T : [ERROR : Nested], /*1*/ F : [ERROR : Inner], /*2*/ G : [ERROR : Interace]*/ { + public final inner class Inner /*captured type parameters: /*0*/ T, /*1*/ F, /*2*/ G*/ { public constructor Inner() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 939a2a32f42..3dd2d147ee7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -7500,6 +7500,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("invalidArgumentsNumberInWhere.kt") + public void testInvalidArgumentsNumberInWhere() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.kt"); + doTest(fileName); + } + @TestMetadata("kt1575-Class.kt") public void testKt1575_Class() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/kt1575-Class.kt"); @@ -7596,6 +7602,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("unresolvedClassifierInWhere.kt") + public void testUnresolvedClassifierInWhere() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt"); + doTest(fileName); + } + @TestMetadata("wildcardInValueParameter.kt") public void testWildcardInValueParameter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/wildcardInValueParameter.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java index da6cbb1298f..ed1542eddfb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java @@ -126,6 +126,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor } private void doAddUpperBound(KotlinType bound) { + if (bound.isError()) return; upperBounds.add(bound); // TODO : Duplicates? }