FIR: introduce ThrowableSubclassChecker

This commit is contained in:
eugenpolytechnic
2021-02-02 14:38:17 +03:00
committed by Mikhail Glukhikh
parent cd189c0812
commit a564f92eef
22 changed files with 209 additions and 90 deletions
@@ -2,11 +2,11 @@
// See KT-9816, KT-9742
// Not allowed in Java
class ZException<T>(val p: T) : Exception()
class ZException<<!GENERIC_THROWABLE_SUBCLASS!>T<!>>(val p: T) : Exception()
class YException<T>(val p: T): java.lang.RuntimeException()
class YException<<!GENERIC_THROWABLE_SUBCLASS!>T<!>>(val p: T): java.lang.RuntimeException()
class XException<T>(val p: T): Throwable()
class XException<<!GENERIC_THROWABLE_SUBCLASS!>T<!>>(val p: T): Throwable()
fun bar() {
try {
@@ -1,41 +0,0 @@
// !LANGUAGE: +ProhibitInnerClassesOfGenericClassExtendingThrowable
// !DIAGNOSTICS: -UNUSED_VARIABLE
// JAVAC_EXPECTED_FILE
class OuterGeneric<T> {
inner class ErrorInnerExn : Exception()
inner class InnerA {
inner class ErrorInnerExn2 : Exception()
}
class OkNestedExn : Exception()
val errorAnonymousObjectExn = object : Exception() {}
fun foo() {
class OkLocalExn : Exception()
val errorAnonymousObjectExn = object : Exception() {}
}
fun <X> genericFoo() {
class OkLocalExn : Exception()
class LocalGeneric<Y> {
inner class ErrorInnerExnOfLocalGeneric : Exception()
}
}
}
class Outer {
inner class InnerGeneric<T> {
inner class ErrorInnerExn : Exception()
}
}
fun <T> genericFoo() {
class ErrorLocalExnInGenericFun : Exception()
val errorkAnonymousObjectExnInGenericFun = object : Exception() {}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ProhibitInnerClassesOfGenericClassExtendingThrowable
// !DIAGNOSTICS: -UNUSED_VARIABLE
// JAVAC_EXPECTED_FILE
@@ -3,39 +3,39 @@
// JAVAC_EXPECTED_FILE
class OuterGeneric<T> {
inner class ErrorInnerExn : Exception()
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExn<!> : Exception()
inner class InnerA {
inner class ErrorInnerExn2 : Exception()
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExn2<!> : Exception()
}
class OkNestedExn : Exception()
val errorAnonymousObjectExn = object : Exception() {}
val errorAnonymousObjectExn = <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>object<!> : Exception() {}
fun foo() {
class OkLocalExn : Exception()
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class OkLocalExn<!> : Exception()
val errorAnonymousObjectExn = object : Exception() {}
val errorAnonymousObjectExn = <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>object<!> : Exception() {}
}
fun <X> genericFoo() {
class OkLocalExn : Exception()
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class OkLocalExn<!> : Exception()
class LocalGeneric<Y> {
inner class ErrorInnerExnOfLocalGeneric : Exception()
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExnOfLocalGeneric<!> : Exception()
}
}
}
class Outer {
inner class InnerGeneric<T> {
inner class ErrorInnerExn : Exception()
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorInnerExn<!> : Exception()
}
}
fun <T> genericFoo() {
class ErrorLocalExnInGenericFun : Exception()
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class ErrorLocalExnInGenericFun<!> : Exception()
val errorkAnonymousObjectExnInGenericFun = object : Exception() {}
val errorkAnonymousObjectExnInGenericFun = <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>object<!> : Exception() {}
}
@@ -1,27 +0,0 @@
// !LANGUAGE: +ProhibitInnerClassesOfGenericClassExtendingThrowable
package test
var global: Throwable? = null
fun <T> foo(x: Throwable, z: T, b: (T) -> Unit) {
class A(val y : T) : Exception()
try {
throw x
} catch (a: A) {
b(a.y)
} catch (e: Throwable) {
global = A(z)
}
}
fun main() {
foo(RuntimeException(), 1) { throw IllegalStateException() }
foo(global!!, "") { it.length } // (*)
}
// (*):
//Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
// at test.TestKt$main$2.invoke(test.kt)
// at test.TestKt.foo(test.kt:12)
// at test.TestKt.main(test.kt:21)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ProhibitInnerClassesOfGenericClassExtendingThrowable
package test