Perform additional checks on catch parameter declaration

KT-8320 It should not be possible to catch a type parameter type
KT-7645 Prohibit default value for `catch`-block parameter
This commit is contained in:
Dmitry Petrov
2017-04-13 13:01:30 +03:00
parent 5ccfbcbe22
commit e0ebaac70c
9 changed files with 52 additions and 10 deletions
+3 -3
View File
@@ -2,12 +2,12 @@
package foo
public fun <T : Throwable> failsWith(block: () -> Any): T {
public inline fun <reified T : Throwable> failsWith(block: () -> Any): T {
try {
block()
}
catch (e: T) {
return e
catch (e: Throwable) {
if (e is T) return e
}
throw Exception("Should have failed")