Skip to content

Union types LUB Object in nested function application #6565

Closed
@bishabosha

Description

@bishabosha

The following example type checks in 0.14.0-RC1 but fails in 0.15.0-RC1, should this be the case?

On the inner call to map from a flatMap in bad, Object is being inferred as the LUB, despite the correct type being inferred for map in ok.

Tested in both VS Code worksheet mode and sbt project compilation

class Err

type Lifted[A] = Err | A

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

val error: Err = Err()

lazy val ok: Lifted[String] = { // ok despite map returning a union
  point("a").map(_ => if true then "foo" else error)
}

lazy val bad: Lifted[String] = { // found Lifted[Object]
  point("a").flatMap(_ => point("b").map(_ => if true then "foo" else error))
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions