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:
Dmitry Petrov
2017-10-03 13:13:44 +03:00
parent 27e319a279
commit 3405ae30a1
12 changed files with 392 additions and 4 deletions
@@ -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() {}
}