Skip to content

Aliases to Hard Unions don't reduce #10129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bishabosha opened this issue Oct 31, 2020 · 0 comments
Closed

Aliases to Hard Unions don't reduce #10129

bishabosha opened this issue Oct 31, 2020 · 0 comments
Assignees

Comments

@bishabosha
Copy link
Member

bishabosha commented Oct 31, 2020

Minimized code

When we make an alias to a union type, it is not reduced compared to a raw union type, i.e. in the following Lifted[Int] is not the same as Err | Int, despite being an alias

class Err                                                                                                        

type Lifted[A] = Err | A

def point[O](o: O): Lifted[O] = o
extension [O, U](o: Lifted[O]) def map(f: O => U): Lifted[U] = ???

val error: Err = Err()

def ok: Int | Err =
  point("a").map(_ => if true then 1 else error)

def fail: Lifted[Int] =
  point("a").map(_ => if true then 1 else error) // error

Output

14 |  point("a").map(_ => if true then 1 else error) // error
   |                                          ^^^^^
   |                                          Found:    (error : Err)
   |                                          Required: Int

Expectation

both ok and fail should compile

@odersky odersky self-assigned this Nov 2, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 7, 2020
Given

    type F[Xs] = ...
    F[As] <: F[Bs]

Do we dealias `F` or check the arguments directly? It turns out that neither choice
is correct in all instances. Checking the arguments directly is necessary for hk
type inference, but may narrow the constraint too much. The solution is to go to
an either that tries both options.
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 7, 2020
Given

    type F[Xs] = ...
    F[As] <: F[Bs]

Do we dealias `F` or check the arguments directly? It turns out that neither choice
is correct in all instances. Checking the arguments directly is necessary for hk
type inference, but may narrow the constraint too much. The solution is to go to
an either that tries both options.
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 9, 2020
Given

    type F[Xs] = ...
    F[As] <: F[Bs]

Do we dealias `F` or check the arguments directly? It turns out that neither choice
is correct in all instances. Checking the arguments directly is necessary for hk
type inference, but may narrow the constraint too much. The solution is to go to
an either that tries both options.
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 10, 2020
Given

    type F[Xs] = ...
    F[As] <: F[Bs]

Do we dealias `F` or check the arguments directly? It turns out that neither choice
is correct in all instances. Checking the arguments directly is necessary for hk
type inference, but may narrow the constraint too much. The solution is to go to
an either that tries both options.
odersky added a commit that referenced this issue Nov 14, 2020
Fix #10129: Fix comparisons of applied type aliases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants