Skip to content

Pretty-printing precedence issue #4068

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
Blaisorblade opened this issue Mar 4, 2018 · 0 comments · Fixed by #4072
Closed

Pretty-printing precedence issue #4068

Blaisorblade opened this issue Mar 4, 2018 · 0 comments · Fixed by #4072

Comments

@Blaisorblade
Copy link
Contributor

Type (Int => Any) => List[Any] is shown without the parens:

scala> :type List(1, 2).map[T = Int]
Int => Any => List[Any]

while parens are omitted correctly here:

scala> val x: Int => (Int => Int) = _ => _ => 1
val x: Int => Int => Int = Lambda$1619/864078397@23310248

that is, the pretty-printer misses associativity of =>.

@Blaisorblade Blaisorblade self-assigned this Mar 4, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Mar 5, 2018
WIP. I consider this a hack, though I haven't found the adequate test to show
it.
Fix scala#4068.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Jul 30, 2018
WIP. I consider this a hack, though I haven't found the adequate test to show
it.
Fix scala#4068.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Jul 30, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Jul 30, 2018
`argText` will never add parentheses around its output, which makes sense for
arguments of type constructors: if we're printing `Foo[T1, T2]` we never
need parens around `T1` or `T2`, whatever its root operator.

But that's inappropriate for a function type `T1 => T2`; the code in
`toTextFunction` attempted to use `atPrec(InfixPrec)` to correct for that, but
that didn't work, because `argText` called `atPrec(GlobalPrec)` right away,
hence we ended up running
`atPrec(InfixPrec) { atPrec(GlobalPrec) { ... }}`, which means just
`atPrec(GlobalPrec) { ... }`.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 9, 2018
Using `atPrec(GlobalPrec)` ensures that `argText(args.head)` never adds
parentheses around its output, but that's inappropriate for a function type
`T1 => T2`. The nested calls to `atPrec` make no sense, but `argText` hid that
before it was refactored.
Jasper-M referenced this issue in Jasper-M/dotty Sep 27, 2018
Pretty-printing: handle type-operator precedence correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants