Type patterns (#22478, #18986)
Improved name resolution and type checking of type patterns in constructors: 1. HsTyPat: a new dedicated data type that represents type patterns in HsConPatDetails instead of reusing HsPatSigType 2. rnHsTyPat: a new function that renames a type pattern and collects its binders into three groups: - explicitly bound type variables, excluding locally bound variables - implicitly bound type variables from kind signatures (only if ScopedTypeVariables are enabled) - named wildcards (only from kind signatures) 2a. rnHsPatSigTypeBindingVars: removed in favour of rnHsTyPat 2b. rnImplcitTvBndrs: removed because no longer needed 3. collect_pat: updated to collect type variable binders from type patterns (this means that types and terms use the same infrastructure to detect conflicting bindings, unused variables and name shadowing) 3a. CollVarTyVarBinders: a new CollectFlag constructor that enables collection of type variables 4. tcHsTyPat: a new function that typechecks type patterns, capable of handling polymorphic kinds. See Note [Type patterns: binders and unifiers] Examples of code that is now accepted: f = \(P @a) -> \(P @a) -> ... -- triggers -Wname-shadowing g :: forall a. Proxy a -> ... g (P @a) = ... -- also triggers -Wname-shadowing h (P @($(TH.varT (TH.mkName "t")))) = ... -- t is bound at splice time j (P @(a :: (x,x))) = ... -- (x,x) is no longer rejected data T where MkT :: forall (f :: forall k. k -> Type). f Int -> f Maybe -> T k :: T -> () k (MkT @f (x :: f Int) (y :: f Maybe)) = () -- f :: forall k. k -> Type Examples of code that is rejected with better error messages: f (Left @a @a _) = ... -- new message: -- • Conflicting definitions for ‘a’ -- Bound at: Test.hs:1:11 -- Test.hs:1:14 Examples of code that is now rejected: {-# OPTIONS_GHC -Werror=unused-matches #-} f (P @a) = () -- Defined but not used: type variable ‘a’
Showing
- compiler/GHC/Hs/Decls.hs 2 additions, 2 deletionscompiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/Instances.hs 5 additions, 0 deletionscompiler/GHC/Hs/Instances.hs
- compiler/GHC/Hs/Pat.hs 2 additions, 2 deletionscompiler/GHC/Hs/Pat.hs
- compiler/GHC/Hs/Type.hs 36 additions, 2 deletionscompiler/GHC/Hs/Type.hs
- compiler/GHC/Hs/Utils.hs 27 additions, 5 deletionscompiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Quote.hs 1 addition, 1 deletioncompiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Ext/Ast.hs 10 additions, 4 deletionscompiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser/PostProcess.hs 1 addition, 1 deletioncompiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Parser/Types.hs 1 addition, 1 deletioncompiler/GHC/Parser/Types.hs
- compiler/GHC/Rename/HsType.hs 50 additions, 100 deletionscompiler/GHC/Rename/HsType.hs
- compiler/GHC/Rename/Pat.hs 414 additions, 14 deletionscompiler/GHC/Rename/Pat.hs
- compiler/GHC/Rename/Splice.hs 21 additions, 1 deletioncompiler/GHC/Rename/Splice.hs
- compiler/GHC/Rename/Splice.hs-boot 2 additions, 0 deletionscompiler/GHC/Rename/Splice.hs-boot
- compiler/GHC/Rename/Utils.hs 9 additions, 1 deletioncompiler/GHC/Rename/Utils.hs
- compiler/GHC/Tc/Errors/Ppr.hs 1 addition, 22 deletionscompiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs 8 additions, 21 deletionscompiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/HsType.hs 171 additions, 20 deletionscompiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Gen/Pat.hs 1 addition, 6 deletionscompiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/TyCl.hs 1 addition, 1 deletioncompiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs 1 addition, 2 deletionscompiler/GHC/Tc/TyCl/Instance.hs
Loading
Please register or sign in to comment