[GHC] #16314: Improve confusing error message with MINIMAL pragma

GHC ghc-devs at haskell.org
Thu Feb 14 05:30:54 UTC 2019


#16314: Improve confusing error message with MINIMAL pragma
-------------------------------------+-------------------------------------
        Reporter:  lerkok            |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.6.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by lerkok):

 Here's a modest proposal to handle this case.

 The user guide says the syntax for `MINIMAL` is:

 {{{#!hs
 mindef ::= name
         |  '(' mindef ')'
         |  mindef '|' mindef
         |  mindef ',' mindef
 }}}

 Strictly speaking the above is actually incorrect because it doesn't
 capture the fact that you can simply write `{-# MINIMAL #-}`, i.e., no
 methods listed at all, but that obviously would correspond to the empty
 set.

 Abusing the notation in the obvious way, define the following function
 from a `MINIMAL` expression to a set of names:

 {{{#!hs
 required empty_decls      = Set.empty      -- the missing case in the
 grammar
 required name             = Set.singleton name
 required ('(' expr ')')   = required expr
 required (left '|' right) = required left `Set.intersection` required
 right
 required (left ',' right) = required left `Set.union`            required
 right
 }}}

 For each class declaration with a `MINIMAL` pragma, compute:

 {{{#!hs
 D = set of all methods with default definitions
 R = the required set, as defined above
 E = D `Set.difference` R
 }}}

 If `E` is ''not'' empty, then GHC should emit a warning saying the methods
 in `E` are required by the `MINIMAL` pragma but also are given a default
 definition. If `E` is empty, no warning is generated.

 I don't think we want to put definitions given with the "default
 signatures" extension into the set `D`; because they can be arguably
 considered as missing for the general case. But perhaps including them in
 `D` can be even a stricter check. I'd vote to leave them out to avoid
 false positives.

 This sounds simple enough to be worth an explicit GHC proposal, but I'm
 happy to create one if you deem it's worth it.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16314#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list