Opened 5 months ago

Closed 5 months ago

#15139 closed bug (fixed)

EmptyCase produces incorrect SrcSpans

Reported by: RyanGlScott Owned by:
Priority: normal Milestone: 8.6.1
Component: Compiler (Parser) Version: 8.4.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Poor/confusing error message Test Case: parser/should_compile/T15139
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4685
Wiki Page:

Description

If you compile the following program, you'll get a warning for f with an improperly placed SrcSpan:

{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wincomplete-patterns #-}
module Bug where

import Data.Type.Equality

can'tHappen :: Int :~: Bool
can'tHappen = undefined

f, g :: Bool -> Bool
f True = case can'tHappen of {}
g True = case () of () -> True
$ /opt/ghc/8.4.2/bin/ghci Bug.hs
GHCi, version 8.4.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )

Bug.hs:12:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘f’: Patterns not matched: False
   |
12 | f True = case can'tHappen of {}
   | ^^^^^^^^^^^^^

Bug.hs:13:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘g’: Patterns not matched: False
   |
13 | g True = case () of () -> True
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ok, one module loaded.

Compare that to the warning for g, whose SrcSpan spans the entire clause, as expected.

The bug lies in the parser—patch incoming.

Change History (3)

comment:1 Changed 5 months ago by RyanGlScott

Differential Rev(s): Phab:D4685
Status: newpatch

comment:2 Changed 5 months ago by Ryan Scott <ryan.gl.scott@…>

In 78db41e/ghc:

Use correct source spans for EmptyCase

Summary:
The parser's calculation of source spans for `EmptyCase`
expressions was a bit off, leading to some wonky-looking error
messages. Easily fixed with some uses of `comb3` and `sLL`.

Test Plan: make test TEST=T15139

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, mpickering, carter

GHC Trac Issues: #15139

Differential Revision: https://phabricator.haskell.org/D4685

comment:3 Changed 5 months ago by RyanGlScott

Resolution: fixed
Status: patchclosed
Test Case: parser/should_compile/T15139
Note: See TracTickets for help on using tickets.