Commit 2e814a7
Kotlin: anchor synthetic exhaustive-when throw to the
An exhaustive `when` expression (one with no explicit `else` that the
compiler proves total) gets a synthetic `throw NoWhenBranchMatchedException(...)`
as its fallback branch. The two frontends locate that synthetic call
differently:
* K2 gives the call the source offsets of the enclosing `when`
expression, so the throw (and the `new NoWhenBranchMatchedException`)
are located at the `when` block, e.g. `6:3:9:3`.
* K1 leaves the synthetic call with undefined offsets, so the extractor
emits a `0:0:0:0` (no-source) location for both nodes.
A real source location is strictly more useful than none, and anchoring
the implicit fallback to the `when` it belongs to is the intuitive
choice, so we adopt the K2 behaviour for both frontends.
`extractCall` now records the enclosing `when`'s location while
extracting its branches (`currentSyntheticWhenLocation`) and uses it as
the fallback for the `noWhenBranchMatchedException` builtin whenever the
synthetic call itself has undefined offsets. This only changes K1: under
K2 the call already carries valid offsets, so `tw.getLocation(c)` is used
unchanged and K2 output is byte-identical.
Relearned both suites: all 3333 tests pass and the only changed row is
test-kotlin1/library-tests/no-when-branch-found, which now matches
test-kotlin2 exactly (`0:0:0:0` -> `6:3:9:3`).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>when
1 parent edaa710 commit 2e814a7
2 files changed
Lines changed: 21 additions & 3 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin
- ql/test-kotlin1/library-tests/no-when-branch-found
Lines changed: 20 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
| |||
5042 | 5049 | | |
5043 | 5050 | | |
5044 | 5051 | | |
5045 | | - | |
| 5052 | + | |
| 5053 | + | |
| 5054 | + | |
| 5055 | + | |
| 5056 | + | |
| 5057 | + | |
5046 | 5058 | | |
5047 | 5059 | | |
5048 | 5060 | | |
| |||
6834 | 6846 | | |
6835 | 6847 | | |
6836 | 6848 | | |
6837 | | - | |
| 6849 | + | |
| 6850 | + | |
| 6851 | + | |
| 6852 | + | |
| 6853 | + | |
| 6854 | + | |
| 6855 | + | |
6838 | 6856 | | |
6839 | 6857 | | |
6840 | 6858 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments