Commit 36e8bcba authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

HsPat: Assume that no spliced patterns are irrefutable

This is a conservative assumption which will limit some uses of spliced
patterns, but it fixes #13984.

Test Plan: Validate

Reviewers: RyanGlScott, AaronFriel, austin

Reviewed By: RyanGlScott

Subscribers: rwbarton, thomie

GHC Trac Issues: #13984

Differential Revision: https://phabricator.haskell.org/D3766
parent ccac387b
...@@ -620,7 +620,7 @@ isIrrefutableHsPat pat ...@@ -620,7 +620,7 @@ isIrrefutableHsPat pat
go1 (SigPatOut pat _) = go pat go1 (SigPatOut pat _) = go pat
go1 (TuplePat pats _ _) = all go pats go1 (TuplePat pats _ _) = all go pats
go1 (SumPat pat _ _ _) = go pat go1 (SumPat pat _ _ _) = go pat
go1 (ListPat {}) = False go1 (ListPat {}) = False
go1 (PArrPat {}) = False -- ? go1 (PArrPat {}) = False -- ?
go1 (ConPatIn {}) = False -- Conservative go1 (ConPatIn {}) = False -- Conservative
...@@ -632,15 +632,13 @@ isIrrefutableHsPat pat ...@@ -632,15 +632,13 @@ isIrrefutableHsPat pat
go1 (ConPatOut{ pat_con = L _ (PatSynCon _pat) }) go1 (ConPatOut{ pat_con = L _ (PatSynCon _pat) })
= False -- Conservative = False -- Conservative
go1 (LitPat {}) = False go1 (LitPat {}) = False
go1 (NPat {}) = False go1 (NPat {}) = False
go1 (NPlusKPat {}) = False go1 (NPlusKPat {}) = False
-- Both should be gotten rid of by renamer before -- We conservatively assume that no TH splices are irrefutable
-- isIrrefutablePat is called -- since we cannot know until the splice is evaluated.
go1 (SplicePat {}) = urk pat go1 (SplicePat {}) = False
urk pat = pprPanic "isIrrefutableHsPat:" (ppr pat)
hsPatNeedsParens :: Pat a -> Bool hsPatNeedsParens :: Pat a -> Bool
hsPatNeedsParens (NPlusKPat {}) = True hsPatNeedsParens (NPlusKPat {}) = True
......
{-# LANGUAGE TemplateHaskell #-}
module Panic where
import Language.Haskell.TH
expr :: IO Exp
expr = runQ $ do
name <- newName "foo"
[| do $(varP name) <- pure (); pure () |]
...@@ -570,3 +570,4 @@ test('T13879', normal, compile, ['']) ...@@ -570,3 +570,4 @@ test('T13879', normal, compile, [''])
test('T13881', normal, compile, ['']) test('T13881', normal, compile, [''])
test('T13915a', normal, multimod_compile, ['T13915a', '-v0']) test('T13915a', normal, multimod_compile, ['T13915a', '-v0'])
test('T13915b', normal, compile, ['']) test('T13915b', normal, compile, [''])
test('T13984', normal, compile, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment