Inner classes of generic classes can't extend Throwable
Do it in the same way as Java: prohibit inner classes (including anonymous inner classes) capturing type parameters from outer classes (but not outer methods) extending Throwable. See KT-17981: - Deprecated in 1.2 - Error in 1.3
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
// !LANGUAGE: +ProhibitInnerClassesOfGenericClassExtendingThrowable
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
class OuterGeneric<T> {
|
||||
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExn<!> : Exception()
|
||||
|
||||
inner class InnerA {
|
||||
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExn2<!> : Exception()
|
||||
}
|
||||
|
||||
class OkNestedExn : Exception()
|
||||
|
||||
val errorAnonymousObjectExn = <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>object<!> : Exception() {}
|
||||
|
||||
fun foo() {
|
||||
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class OkLocalExn<!> : Exception()
|
||||
|
||||
val errorAnonymousObjectExn = <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>object<!> : Exception() {}
|
||||
}
|
||||
|
||||
fun <X> genericFoo() {
|
||||
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class OkLocalExn<!> : Exception()
|
||||
|
||||
class LocalGeneric<Y> {
|
||||
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExnOfLocalGeneric<!> : Exception()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Outer {
|
||||
inner class InnerGeneric<T> {
|
||||
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExn<!> : Exception()
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> genericFoo() {
|
||||
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorLocalExnInGenericFun<!> : Exception()
|
||||
|
||||
val errorkAnonymousObjectExnInGenericFun = <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>object<!> : Exception() {}
|
||||
}
|
||||
Reference in New Issue
Block a user