haskell / happy

The Happy parser generator for Haskell
Other
291 stars 84 forks source link

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

Closed andreasabel closed 2 months ago

andreasabel commented 2 months ago

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: https://github.com/haskell/happy/blob/17d3c937e9d469a5bb3b0e90b77c394eb8a4ba3b/lib/data/HappyTemplate.hs#L90-L97 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 commented 2 months ago

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.