Commit bbd8084
committed
Fix #9740: harden type checking for pattern match on objects
We enforce that when pattern match on an object, the object should be
a subtype of the scrutinee type.
Reasons for doing so:
- such code patterns usually implies hidden errors in the code
- it's always safe/sound to reject the code
We could check whether `equals` is overridden in the object, but
- it complicates the protocol
- overriding `equals` of object is also a bad practice
- there is no sign that the slightly improved completeness is useful1 parent 53a2dc5 commit bbd8084
File tree
2 files changed
+30
-5
lines changed- compiler/src/dotty/tools/dotc/typer
- tests/neg
2 files changed
+30
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3780 | 3780 | | |
3781 | 3781 | | |
3782 | 3782 | | |
3783 | | - | |
3784 | | - | |
3785 | | - | |
3786 | | - | |
3787 | | - | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
| 3793 | + | |
| 3794 | + | |
| 3795 | + | |
| 3796 | + | |
3788 | 3797 | | |
3789 | 3798 | | |
3790 | 3799 | | |
| |||
| 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 | + | |
0 commit comments