haskell / haskell/happy

GLR: generated file `*Data.hs` doesn't declare its OPTIONS and LANGUAGE pragmas

Open
#183 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
322
Forks
86
PR merge metrics
No merged PRs in 30d

Description

The GLR generated file `*Data.hs` doesn't declare its OPTIONS and LANGUAGE pragmas.

Suggestion: Emit the following in the preamble when generating this file:
```haskell
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}

{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
```

Details
-------

I am getting errors like:
```
• Illegal instance declaration for ‘TreeDecode String’
(All instance types must be of the form (T t1 ... tn)
where T is not a synonym.
Use TypeSynonymInstances if you want to disable this.)

• Illegal instance declaration for ‘TreeDecode [AbsAlfa.Decl]’
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use FlexibleInstances if you want to disable this.)
```
With `-Wall` I am getting warnings like:
```
ParTestData.hs:16:1: error: [-Wunused-imports, -Werror=unused-imports]
The qualified import of ‘Data.Array’ is redundant
except perhaps to import instances from ‘Data.Array’
To import instances alone, use: import Data.Array()
|
16 | import qualified Data.Array as Happy_Data_Array
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ParTestData.hs:17:1: error: [-Wunused-imports, -Werror=unused-imports]
The qualified import of ‘Data.Bits’ is redundant
except perhaps to import instances from ‘Data.Bits’
To import instances alone, use: import Data.Bits()
|
17 | import qualified Data.Bits as Bits
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ParTestData.hs:18:1: error: [-Wunused-imports, -Werror=unused-imports]
The import of ‘Control.Applicative’ is redundant
except perhaps to import instances from ‘Control.Applicative’
To import instances alone, use: import Control.Applicative()
|
18 | import Control.Applicative(Applicative(..))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ParTestData.hs:19:1: error: [-Wunused-imports, -Werror=unused-imports]
The import of ‘Control.Monad’ is redundant
except perhaps to import instances from ‘Control.Monad’
To import instances alone, use: import Control.Monad()
|
19 | import Control.Monad (ap)
| ^^^^^^^^^^^^^^^^^^^^^^^^^

templates/GLR_Base.hs:53:10: error: [-Wunused-matches, -Werror=unused-matches]
Defined but not used: ‘i’

templates/GLR_Base.hs:68:1: error: [-Wmissing-signatures, -Werror=missing-signatures]
Top-level binding with no type signature:
cross_fn :: Monad m => [m (t -> b)] -> [m t] -> [m b]

```

Contributor guide

Open the contributing guide

Research direction

Start with templates/GLR_Base.hs and trace how the GLR generator builds the preamble for generated *Data.hs files. Ensure the generated preamble declares the requested LANGUAGE pragmas and suppresses the listed GHC warnings, then regenerate a sample file and verify it builds cleanly with -Wall.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.