0e2b3ce845
Entering a `finally` block can happen from many different places:
through an exception, a jump, or normal exit from the `try` block. When
in the `finally` block, all DFA flows must be merged to have correct
smart casting. However, after the `finally` block, if exiting normally
or because of a jump, the combined flow from within the `finally` block
should not be used, but rather an alternate flow which combines the
correct flows from before the `finally` block.
```
try {
str as String // Potential cast exception
} finally {
str.length // Shouldn`t be resolved
}
str.length // Should be resolved
```
When building DFA flows, track the start of possible alternate flows,
and continue building them until they end. Both of these situations are
now marked on CFGNodes via interfaces.
When building the default DFA flow, and the source node is the end node
of alternate flows, attempt to use the alternate flow with the same edge
label instead of the default flow of the source node.
#KT-56888 Fixed
24 lines
381 B
Kotlin
Vendored
24 lines
381 B
Kotlin
Vendored
// ISSUE: KT-51759
|
|
|
|
fun testBreak(b: Boolean, s: String?) {
|
|
while (b) {
|
|
val x: String?
|
|
try {
|
|
x = s ?: break
|
|
} finally {
|
|
}
|
|
x!!.length
|
|
}
|
|
}
|
|
|
|
fun testContinue(b: Boolean, s: String?) {
|
|
while (b) {
|
|
val x: String?
|
|
try {
|
|
x = s ?: continue
|
|
} finally {
|
|
}
|
|
x!!.length
|
|
}
|
|
}
|