Commit 2b156c6
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 8b1188b commit 2b156c6
File tree
2 files changed
+32
-7
lines changed- compiler/src/dotty/tools/dotc/typer
- tests/neg
2 files changed
+32
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
865 | 865 | | |
866 | 866 | | |
867 | 867 | | |
868 | | - | |
| 868 | + | |
869 | 869 | | |
870 | | - | |
| 870 | + | |
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
| |||
3761 | 3761 | | |
3762 | 3762 | | |
3763 | 3763 | | |
3764 | | - | |
3765 | | - | |
3766 | | - | |
3767 | | - | |
3768 | | - | |
| 3764 | + | |
| 3765 | + | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
3769 | 3778 | | |
3770 | 3779 | | |
3771 | 3780 | | |
| |||
| 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