Skip to content

Aliases to Hard Unions don't reduce #10129

Closed
@bishabosha

Description

@bishabosha

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions