Commit a68989d
Fix undercompilation when case class field type changes (issue #26231)
In Scala 3, the compiler generates `def unapply(x: C): C = x` for case
classes. Its signature is always `(C): C` regardless of field types, so
its API hash never changes when a field is renamed or retyped.
The PatternMatcher phase (which runs after ExtractDependencies) lowers
`case C(x)` to a direct call to the product selector `_1()`, `_2()`, etc.
Because ExtractDependencies ran before PatternMatcher, those selector
calls were never in the tree, so `_1` was never recorded as a used name
in the dependent file. Zinc therefore saw no reason to recompile the
file when the field type changed, producing a NoSuchMethodError at
runtime.
Fix: in `AbstractExtractDependenciesCollector.recordTree`, add a case for
`UnApply` that records each product selector (`_1`, `_2`, …) found on
the unapply's result type as a member-reference used name. When the
selector's return type changes (because the field type changed) its name
hash changes and Zinc correctly invalidates the dependent file.
The key detail is that `fun.tpe` in an `UnApply` node is a `TermRef`;
we must call `.widen.finalResultType` to reach the underlying case-class
type before asking `Applications.productSelectors` for the `_N` members.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 0ac3485 commit a68989d
2 files changed
Lines changed: 16 additions & 7 deletions
File tree
- compiler/src/dotty/tools/dotc/sbt
- sbt-bridge/test/xsbt
Lines changed: 15 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
21 | 20 | | |
22 | | - | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | 27 | | |
30 | 28 | | |
31 | 29 | | |
| |||
265 | 263 | | |
266 | 264 | | |
267 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
268 | 278 | | |
269 | 279 | | |
270 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
262 | | - | |
| 261 | + | |
263 | 262 | | |
264 | 263 | | |
265 | 264 | | |
| |||
0 commit comments