Commit 2b1d5c0
committed
More precise type for typed patterns, less precise for literal patterns
In `x @ Nil`, `Nil` is a _stable identifier pattern_ and will be compiled
to an `==` test, so the type of `x` is unrelated to the type of `Nil`.
This was handled correctly before this commit, but the check to use the
moe restrictive patten typing was too wide and also included typed
patterns like `x: Nil.type`, even though such patterns compile to `eq`
tests and therefore it's safe to assume that `x` has type `Nil.type`.
Additionally, a _literal pattern_ will also be compiled to an `==` test
and therefore should be less precisely typed, like a stable identifier
patterns.1 parent f64e879 commit 2b1d5c0
File tree
3 files changed
+41
-4
lines changed- compiler/src/dotty/tools/dotc/typer
- tests
- neg
- run
3 files changed
+41
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1718 | 1718 | | |
1719 | 1719 | | |
1720 | 1720 | | |
1721 | | - | |
1722 | | - | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
1723 | 1729 | | |
1724 | | - | |
| 1730 | + | |
1725 | 1731 | | |
1726 | 1732 | | |
1727 | 1733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments