Skip to content

Union types LUB Object in nested function application #6565

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 May 25, 2019 · 2 comments
Closed

Union types LUB Object in nested function application #6565

bishabosha opened this issue May 25, 2019 · 2 comments

Comments

@bishabosha
Copy link
Member

bishabosha commented May 25, 2019

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))
}
@bishabosha bishabosha changed the title Union types LUB Any in nested function application Union types LUB Object in nested function application May 25, 2019
@smarter
Copy link
Member

smarter commented May 27, 2019

Probably related to #6299, in particular the changes to orDominator might have broken something.

@odersky odersky closed this as completed in ade3492 Mar 5, 2020
odersky added a commit that referenced this issue Mar 5, 2020
@bishabosha
Copy link
Member Author

More discussion for union widening: #4867

in the example below, I would expect if true then "foo" else error to have type String | Err, aka Lifted[String], which would make the argument to map String => Lifted[String] which should infer the result of map as Lifted[Lifted[String]] which flattens to Lifted[String]. Instead it appears the closure is inferred as String => Object

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

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