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

Regression in happy 2.0: generated code uses PatternGuards without declaring it #309

Closed
andreasabel opened this issue Sep 22, 2024 · 1 comment · Fixed by #310
Closed

Comments

@andreasabel
Copy link
Member

With happy-2.0.1, I am getting this warning when building haskell-src:

[6 of 6] Compiling Language.Haskell.Parser
dist-newstyle/build/x86_64-osx/ghc-9.10.1/haskell-src-1.0.5/build/Language/Haskell/Parser.hs:4367:3: 
warning: [GHC-59119]
    accepting non-standard pattern guards
        ((Happy_GHC_Exts.tagToEnum# (off Happy_GHC_Exts.>=# 0#)) :: Bool),
        ((Happy_GHC_Exts.tagToEnum#
            (happyIndexOffAddr happyCheck off Happy_GHC_Exts.==# i)) ::
           Bool)
    Suggested fix: Perhaps you intended to use PatternGuards
     |
4367 |   | GTE(off, 0#), EQ(happyIndexOffAddr happyCheck off, i)
     |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

The generated code is:

{-# INLINE happyIndexActionTable #-}
happyIndexActionTable i st
  | GTE(off, 0#), EQ(happyIndexOffAddr happyCheck off, i)
  = Prelude.Just (Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off))
  | otherwise
  = Prelude.Nothing
  where
    off = PLUS(happyIndexOffAddr happyActOffsets st, i)

It seems to stem from the template at:

{-# INLINE happyIndexActionTable #-}
happyIndexActionTable i st
| GTE(off, 0#), EQ(happyIndexOffAddr happyCheck off, i)
= Prelude.Just (Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off))
| otherwise
= Prelude.Nothing
where
off = PLUS(happyIndexOffAddr happyActOffsets st, i)

So it is not the user's responsibility to declare LANGUAGE PatternGuards, but the one of the template.

Note that haskell-src is written in the Haskell98 language.
It could be that the happy testsuite lacks explicit Haskell98 entries, so this problem stayed under the radar.

@sgraf812
Copy link
Collaborator

Thanks. Indeed I could reproduce in #309 after adding -XHaskell98 to the testsuite (seems like the better default compared to implicit -XGHC20xx) and easily fixed as well. I'm preparing a release at branch release-2.0 and unless you have something to object, I will merge #309 this evening and prepare publish the new release afterwards.

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