Exception fix: diagnose an error for a generic type which is a subtype of itself, a set of tests #EA-64453 Fixed
This commit is contained in:
@@ -249,6 +249,8 @@ public interface Errors {
|
||||
DiagnosticFactory0<JetDeclaration> TYPE_PARAMETERS_NOT_ALLOWED
|
||||
= DiagnosticFactory0.create(ERROR, TYPE_PARAMETERS_OR_DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<PsiElement> CYCLIC_GENERIC_UPPER_BOUND = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Members
|
||||
|
||||
DiagnosticFactory0<JetModifierListOwner> PACKAGE_MEMBER_CANNOT_BE_PROTECTED =
|
||||
|
||||
+1
@@ -421,6 +421,7 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(TYPE_MISMATCH_IN_RANGE, "Type mismatch: incompatible types of range and element checked in it");
|
||||
MAP.put(CYCLIC_INHERITANCE_HIERARCHY, "There's a cycle in the inheritance hierarchy for this type");
|
||||
MAP.put(CYCLIC_GENERIC_UPPER_BOUND, "Type parameter has itself as an upper bound");
|
||||
|
||||
MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list");
|
||||
MAP.put(SUPERTYPE_NOT_A_CLASS_OR_TRAIT, "Only classes and interfaces may serve as supertypes");
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.*;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.JetKeywordToken;
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
@@ -476,6 +477,10 @@ public class DescriptorResolver {
|
||||
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
|
||||
if (extendsBound != null) {
|
||||
JetType type = typeResolver.resolveType(scope, extendsBound, trace, false);
|
||||
if (type.getConstructor().equals(typeParameterDescriptor.getTypeConstructor())) {
|
||||
trace.report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(extendsBound));
|
||||
type = ErrorUtils.createErrorType("Cyclic upper bound: " + type);
|
||||
}
|
||||
typeParameterDescriptor.addUpperBound(type);
|
||||
deferredUpperBoundCheckerTasks.add(new UpperBoundCheckerTask(extendsBound, type));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
// !DIAGNOSTICS: -MUST_BE_INITIALIZED
|
||||
fun <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T?<!>> foo() {}
|
||||
val <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T?<!>> prop
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal val </*0*/ T : [ERROR : Cyclic upper bound: T?]> prop: [ERROR : No type, no body]
|
||||
internal fun </*0*/ T : [ERROR : Cyclic upper bound: T?]> foo(): kotlin.Unit
|
||||
@@ -0,0 +1,4 @@
|
||||
fun bar() {
|
||||
fun <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T?<!>> foo() {}
|
||||
foo()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
internal fun bar(): kotlin.Unit
|
||||
@@ -0,0 +1,5 @@
|
||||
// !DIAGNOSTICS: -MUST_BE_INITIALIZED_OR_BE_ABSTRACT
|
||||
class My {
|
||||
fun <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T?<!>> foo() {}
|
||||
val <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T?<!>> prop: T
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
internal final class My {
|
||||
public constructor My()
|
||||
internal final val </*0*/ T : [ERROR : Cyclic upper bound: T?]> prop: [ERROR : ?]
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun </*0*/ T : [ERROR : Cyclic upper bound: T?]> foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// !DIAGNOSTICS: -MUST_BE_INITIALIZED
|
||||
fun <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T<!>> foo() {}
|
||||
val <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T?<!>> prop: T
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal val </*0*/ T : [ERROR : Cyclic upper bound: T?]> prop: [ERROR : ?]
|
||||
internal fun </*0*/ T : [ERROR : Cyclic upper bound: T]> foo(): kotlin.Unit
|
||||
@@ -10224,6 +10224,30 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("itselfAsUpperBound.kt")
|
||||
public void testItselfAsUpperBound() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/itselfAsUpperBound.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("itselfAsUpperBoundLocal.kt")
|
||||
public void testItselfAsUpperBoundLocal() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundLocal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("itselfAsUpperBoundMember.kt")
|
||||
public void testItselfAsUpperBoundMember() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundMember.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("itselfAsUpperBoundNotNull.kt")
|
||||
public void testItselfAsUpperBoundNotNull() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundNotNull.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Jet11.kt")
|
||||
public void testJet11() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/Jet11.kt");
|
||||
|
||||
Reference in New Issue
Block a user