Skip to content

Confusing pretty print for method call on if expression #5997

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
fhackett opened this issue Feb 28, 2019 · 1 comment
Closed

Confusing pretty print for method call on if expression #5997

fhackett opened this issue Feb 28, 2019 · 1 comment

Comments

@fhackett
Copy link
Contributor

import quoted.Toolbox.Default._
val v = '{ (if true then Some(1) else None).map(v => v+1) }
v.show

will output (in REPL, Dotty 0.12.0):

val res0: String = if (true) scala.Some.apply[scala.Int](1) else scala.None.map[scala.Int](((v: scala.Int) => v.+(1)))
...

The confusing part is scala.None.map[scala.Int](..., which unless closely inspected suggests that we are calling None.map instead of (if ...).map.

Perhaps adding brackets around if expressions that are in this situation (the LHS of a method call) might help?

@nicolasstucki
Copy link
Contributor

It is clearly missing a pair of ( and ) around the if then else

It should print

val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1)))

nicolasstucki added a commit that referenced this issue Mar 28, 2019
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

4 participants