Skip to content
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

idempotency bug (including operators) #522

Closed
mheinzel opened this issue Mar 9, 2020 · 4 comments · Fixed by #592
Closed

idempotency bug (including operators) #522

mheinzel opened this issue Mar 9, 2020 · 4 comments · Fixed by #592
Assignees
Labels
bug Something isn't working idempotence Idempotence issues and solutions.

Comments

@mheinzel
Copy link

mheinzel commented Mar 9, 2020

I saw #451, but there is a related PR that claims to solve the issue.

Minimal example:

foo = f
    . g
  =<< h . i

first turns into

foo =
  f
    . g
    =<< h . i

and then

foo =
  f
    . g
    =<< h
    . i

Version:

$ stack exec -- ormolu --version
Stack has not been tested with GHC versions above 8.6, and using 8.8.2, this ma
y fail
Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 wa
s found, this may fail
ormolu 0.0.3.1 master 55d8b7f8c482655ea575425e55352e650f304ea0
using ghc-lib-parser 8.8.2.20200205
@mrkkrp mrkkrp added bug Something isn't working idempotence Idempotence issues and solutions. labels Mar 9, 2020
@utdemir
Copy link
Contributor

utdemir commented Apr 9, 2020

Thanks!

Tricky issue. There's a heuristic trying to figure out the operator precedence, which gets confused when the same operator is used in two different ways. In this case, (.) is both used as the beginning of a line which suggests lower associativity, but then used inline which suggests the opposite. So the heuristic can not decide consistently.

One solution I can think of is to try to decide on the operator precedence just according to the first use of that specific operator instead of averaging all uses. But this might also have another set of corner cases.

I'll spend some time thinking about it.

@mrkkrp
Copy link
Member

mrkkrp commented May 14, 2020

Another example:

foo n
  | x || y && z || n ** x
      || x && n =
        42

@mrkkrp mrkkrp self-assigned this May 15, 2020
@mrkkrp
Copy link
Member

mrkkrp commented May 15, 2020

Another example from Idris:

prettyBv env op sc n t v debug =
  text op <> pretty n <+> colon <+> prettySe 10 env t debug <+> text "=" <+>
    prettySe 10 env v debug <> text sc

@mrkkrp
Copy link
Member

mrkkrp commented May 15, 2020

Yet another example form Idris:

prettyPs all g bnd ((n, _, Let rig t v) : bs) =
  line <> bindingOf n False <+> text "=" <+> tPretty bnd v <+> colon <+>
    align (tPretty bnd t) <> prettyPs all g ((n, False):bnd) bs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working idempotence Idempotence issues and solutions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants