Commit 5fb13aa
committed
Don't dealias when matching type constructors
Not only can this prevent some constraints from being inferred, it can
lead to the wrong constraints being inferred due to partial unification,
see comment.
This change broke one test, in i6565.scala we had:
type Lifted[A] = Err | A
extension [O, U](o: Lifted[O]) def map(f: O => U): Lifted[U] = ???
val error: Err = Err()
lazy val ok: Lifted[String] = {
point("a").map(_ => if true then "foo" else error)
// now fails because error does not have type String
}
Because `isMatchingApply` can now deal with aliased types, when typing
the lambda we get the constraint `U <: String` from
`Lifted[U] <: Lifted[String]`, so `Err` is no longer a subtype of the
expected result type of the lambda. This can be fixed in a number of
ways: I changed the test to use `flatMap` instead of `map`, but one
could also remove the expected type, or replace it by
`Lifted[Lifted[String]` or `Err | String`.
I think the new behavior is arguably better since using type aliases now
gives you more control on how type inference proceeds, even if it means
that some things that used to typecheck don't anymore.
This change is also necessary to get shapeless to compile after the
following commit which makes partial unification work in more
situation.1 parent 1fb2082 commit 5fb13aa
File tree
3 files changed
+50
-5
lines changed- compiler/src/dotty/tools/dotc/core
- tests
- pos
- run
3 files changed
+50
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
863 | | - | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
864 | 886 | | |
865 | 887 | | |
866 | 888 | | |
867 | 889 | | |
868 | 890 | | |
869 | | - | |
| 891 | + | |
870 | 892 | | |
871 | 893 | | |
872 | 894 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
| 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 | + | |
0 commit comments