Magnus pushed to branch wip/mangoiv/28038 at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • changelog.d/28038
    1 1
     section: compiler
    
    2 2
     synopsis:
    
    3
    -  Fix a panic when trying to bind a type variable in patterns.
    
    3
    +  When encountering a required type argument in a pattern binding, don't panic, report an error instead.
    
    4 4
     description:
    
    5
    -  GHC currently does not allow to bind type variables in patterns. When
    
    6
    -  a user would try that, in some situations, we didn't abort eagerly
    
    7
    -  enough after discovering the error and thus ran into a panic looking up
    
    8
    -  the type in the env while trying to update the local context. Instead,
    
    9
    -  when discovering the error,
    
    10
    -  we now abort eagerly.
    
    5
    +  GHC does not currently support pattern bindings that bind a required type argument. Now GHC reports an 
    
    6
    +  error in that situation, instead of panicking.
    
    11 7
     mrs: !16868
    
    12 8
     issues: #28038

  • compiler/GHC/Tc/Gen/Bind.hs
    ... ... @@ -1557,8 +1557,8 @@ lookupMBI :: Name -> TcM MonoBindInfo
    1557 1557
     lookupMBI name
    
    1558 1558
       = do { mono_id_e <- tcLookupTermBndr name
    
    1559 1559
            ; case mono_id_e of
    
    1560
    -         Left _ -> failIllegalTyVar (noUserRdr name)
    
    1561
    -         Right mono_id ->
    
    1560
    +         TyVarBndr _ -> failIllegalTyVar (noUserRdr name)
    
    1561
    +         TermBndr mono_id ->
    
    1562 1562
                return (MBI { mbi_poly_name = name
    
    1563 1563
                            , mbi_sig       = Nothing
    
    1564 1564
                            , mbi_mono_id   = mono_id
    

  • compiler/GHC/Tc/Utils/Env.hs
    ... ... @@ -43,7 +43,7 @@ module GHC.Tc.Utils.Env(
    43 43
     
    
    44 44
             tcLookup, tcLookupLocated, tcLookupLocalIds,
    
    45 45
             tcLookupId, tcLookupIdMaybe, tcLookupTyVar,
    
    46
    -        tcLookupTermBndr, NotATermBndr (..),
    
    46
    +        tcLookupTermBndr, TermBndr (..),
    
    47 47
             tcLookupTcTyCon,
    
    48 48
             tcLookupLcl_maybe,
    
    49 49
             getInLocalScope,
    
    ... ... @@ -769,16 +769,17 @@ tcLookupIdMaybe name
    769 769
     
    
    770 770
     -- | Encountered a thing that is not a term binder when
    
    771 771
     --  calling 'tcLookupTermBndr'.
    
    772
    -newtype NotATermBndr
    
    773
    -  = ButATyVar TcTyVar
    
    772
    +data TermBndr
    
    773
    +  = TermBndr !Id
    
    774
    +  | TyVarBndr !TcTyVar
    
    774 775
     
    
    775
    -tcLookupTermBndr :: Name -> TcM (Either NotATermBndr Id)
    
    776
    +tcLookupTermBndr :: Name -> TcM TermBndr
    
    776 777
     tcLookupTermBndr name = do
    
    777 778
       thing <- tcLookup name
    
    778 779
       case thing of
    
    779
    -    ATcId { tct_id } -> pure $ Right $! tct_id
    
    780
    -    AGlobal (AnId id) -> pure $ Right $! id
    
    781
    -    ATyVar _ var -> pure $ Left $! ButATyVar var
    
    780
    +    ATcId { tct_id } -> pure $ TermBndr tct_id
    
    781
    +    AGlobal (AnId id) -> pure $ TermBndr id
    
    782
    +    ATyVar _ var -> pure $ TyVarBndr var
    
    782 783
         _ -> pprPanic "tcLookupTermBndr: unexpected thing" (ppr thing)
    
    783 784
     
    
    784 785
     tcLookupLocalIds :: [Name] -> TcM [TcId]