Commit a325641
committed
Fix #10178: Put the wildcard demon back in the bottle
This was a very interesting bug. Why did `any2stringadd` appear out of the blue?
The first observation was that it was resolved by an import of an identifier with
`_` as its name. Why? Because we have a standard predefined import
```scala
import Predef.{any2stringadd => _, _}
```
This is represented as a "rename" from `anyToStringAdd` to `_`, assuming that
no real identifier could be `_`. But that assumption turned out to be wrong.
How did we end up with an identifier `_` that needed to be resolved? This was a
second bug in Desugar, method `makeIdPat`. Here we needed to create binds for parts
of a pattern. If the pattern was already a Bind, we used that one instead. But the
`Bind` in question was anonymous, using `_` as the pattern variable. So we did not
replace that by a fresh identifier, but used `_` as the identifier instead. However,
`_` is treated specially as a binder; it does not generate a symbol in the enclosing
scope. So resolving the `_` identifier did not see the enclosing bind and searched
further out instead, until it found the "renamed" import. Beautiful! It shows that
treating wildcards as some sort of identifiers is fraught with surprises.1 parent 1ab76c1 commit a325641
File tree
3 files changed
+13
-3
lines changed- compiler/src/dotty/tools/dotc
- ast
- typer
- tests/run
3 files changed
+13
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1456 | 1456 | | |
1457 | 1457 | | |
1458 | 1458 | | |
1459 | | - | |
| 1459 | + | |
| 1460 | + | |
1460 | 1461 | | |
1461 | 1462 | | |
1462 | | - | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
1463 | 1468 | | |
1464 | 1469 | | |
1465 | 1470 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments