Skip to content

Commit

Permalink
Fix precedence inconsistency bug (#2470)
Browse files Browse the repository at this point in the history
Precedence inconsistency was not always correctly detected.
  • Loading branch information
lukaszcz authored Oct 25, 2023
1 parent 830b3be commit ef1148b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ resolveFixitySyntaxDef fdef@FixitySyntaxDef {..} = topBindings $ do
belowPrec = fromIntegral $ maximum (minInt + 1 : maybe [] (map (getPrec tab)) above)
abovePrec :: Integer
abovePrec = fromIntegral $ minimum (maxInt - 1 : maybe [] (map (getPrec tab)) below)
when (belowPrec >= abovePrec + 1) $
when (belowPrec + 1 >= abovePrec) $
throw (ErrPrecedenceInconsistency (PrecedenceInconsistencyError fdef))
when (isJust same && not (null below && null above)) $
throw (ErrPrecedenceInconsistency (PrecedenceInconsistencyError fdef))
Expand Down
7 changes: 7 additions & 0 deletions test/Scope/Negative.hs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ scoperErrorTests =
$ \case
ErrIncomparablePrecedences {} -> Nothing
_ -> wrongError,
NegTest
"Precedence inconsistency"
$(mkRelDir ".")
$(mkRelFile "PrecedenceInconsistency.juvix")
$ \case
ErrPrecedenceInconsistency {} -> Nothing
_ -> wrongError,
NegTest
"Alias cycle"
$(mkRelDir ".")
Expand Down
5 changes: 5 additions & 0 deletions tests/negative/PrecedenceInconsistency.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module PrecedenceInconsistency;

syntax fixity f1 := binary {assoc := left};
syntax fixity f2 := binary {assoc := left; same := f1};
syntax fixity f3 := binary {assoc := left; above := [f1]; below := [f2]};

0 comments on commit ef1148b

Please sign in to comment.