Generic types may not extend kotlin.Throwable #KT-9816 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-11-30 12:05:23 +03:00
parent c6be69a483
commit de37cb8f40
5 changed files with 38 additions and 11 deletions
@@ -107,6 +107,7 @@ public interface Errors {
DiagnosticFactory0<KtTypeArgumentList> TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtParameter> REIFIED_TYPE_IN_CATCH_CLAUSE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeParameterList> GENERIC_THROWABLE_SUBCLASS = DiagnosticFactory0.create(ERROR);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -517,6 +517,7 @@ public class DefaultErrorMessages {
MAP.put(TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED, "Type arguments for outer class are redundant when nested class is referenced");
MAP.put(REIFIED_TYPE_IN_CATCH_CLAUSE, "Reified type is forbidden for catch parameter");
MAP.put(GENERIC_THROWABLE_SUBCLASS, "Subclass of 'kotlin.Throwable' may not have type parameters");
MAP.put(TYPE_MISMATCH_IN_FOR_LOOP, "The loop iterates over values of type {0} but the parameter is declared to be {1}", RENDER_TYPE,
RENDER_TYPE);
@@ -67,6 +67,7 @@ public class BodyResolver {
@NotNull private final FunctionAnalyzerExtension functionAnalyzerExtension;
@NotNull private final ValueParameterResolver valueParameterResolver;
@NotNull private final BodyResolveCache bodyResolveCache;
@NotNull private final KotlinBuiltIns builtIns;
public BodyResolver(
@NotNull AnnotationResolver annotationResolver,
@@ -79,7 +80,8 @@ public class BodyResolver {
@NotNull FunctionAnalyzerExtension functionAnalyzerExtension,
@NotNull BindingTrace trace,
@NotNull ValueParameterResolver valueParameterResolver,
@NotNull AnnotationChecker annotationChecker
@NotNull AnnotationChecker annotationChecker,
@NotNull KotlinBuiltIns builtIns
) {
this.annotationResolver = annotationResolver;
this.bodyResolveCache = bodyResolveCache;
@@ -92,6 +94,7 @@ public class BodyResolver {
this.annotationChecker = annotationChecker;
this.trace = new ObservableBindingTrace(trace);
this.valueParameterResolver = valueParameterResolver;
this.builtIns = builtIns;
}
private void resolveBehaviorDeclarationBodies(@NotNull BodiesResolveContext c) {
@@ -457,6 +460,11 @@ public class BodyResolver {
trace.report(DATA_CLASS_CANNOT_HAVE_CLASS_SUPERTYPES.on(typeReference));
addSupertype = false;
}
else if (DescriptorUtils.isSubclass(classDescriptor, builtIns.getThrowable()) &&
!supertypeOwner.getDeclaredTypeParameters().isEmpty()) {
trace.report(GENERIC_THROWABLE_SUBCLASS.on(jetClass.getTypeParameterList()));
addSupertype = false;
}
if (classAppeared) {
trace.report(MANY_CLASSES_IN_SUPERTYPE_LIST.on(typeReference));
@@ -1,15 +1,11 @@
// See KT-9816, KT-9742
// Not allowed in Java
open class ZException<T>(val p: T) : Exception()
class ZException<!GENERIC_THROWABLE_SUBCLASS!><T><!>(val p: T) : Exception()
fun foo(): String {
try {
throw ZException(11)
} catch (e: ZException<String>) {
return e.p
}
}
class YException<!GENERIC_THROWABLE_SUBCLASS!><T><!>(val p: T): java.lang.RuntimeException()
class XException<!GENERIC_THROWABLE_SUBCLASS!><T><!>(val p: T): Throwable()
fun bar() {
try {
@@ -1,10 +1,31 @@
package
public fun bar(): kotlin.Unit
public fun foo(): kotlin.String
public inline fun </*0*/ reified E : java.lang.Exception, /*1*/ R> tryCatch(/*0*/ lazy: () -> R, /*1*/ failure: (E) -> R): R
public open class ZException</*0*/ T> : java.lang.Exception {
public final class XException</*0*/ T> : kotlin.Throwable {
public constructor XException</*0*/ T>(/*0*/ p: T)
public final override /*1*/ /*fake_override*/ val cause: kotlin.Throwable?
public final override /*1*/ /*fake_override*/ val message: kotlin.String?
public final val p: T
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 final override /*1*/ /*fake_override*/ fun printStackTrace(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class YException</*0*/ T> : java.lang.RuntimeException {
public constructor YException</*0*/ T>(/*0*/ p: T)
public final override /*1*/ /*fake_override*/ val cause: kotlin.Throwable?
public final override /*1*/ /*fake_override*/ val message: kotlin.String?
public final val p: T
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 final override /*1*/ /*fake_override*/ fun printStackTrace(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class ZException</*0*/ T> : java.lang.Exception {
public constructor ZException</*0*/ T>(/*0*/ p: T)
public final override /*1*/ /*fake_override*/ val cause: kotlin.Throwable?
public final override /*1*/ /*fake_override*/ val message: kotlin.String?