[Git][ghc/ghc][wip/int-index/decl-invis-binders] Comments and error messages

Vladislav Zavialov (@int-index) gitlab at gitlab.haskell.org
Fri Feb 3 10:37:35 UTC 2023



Vladislav Zavialov pushed to branch wip/int-index/decl-invis-binders at Glasgow Haskell Compiler / GHC


Commits:
99821af2 by Vladislav Zavialov at 2023-02-03T13:37:26+03:00
Comments and error messages

- - - - -


6 changed files:

- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/TyCl.hs
- testsuite/tests/th/T12045TH2.hs
- testsuite/tests/typecheck/should_fail/T22560_fail_a.stderr
- testsuite/tests/typecheck/should_fail/T22560_fail_b.stderr
- testsuite/tests/typecheck/should_fail/T22560_fail_d.stderr


Changes:

=====================================
compiler/GHC/Tc/Errors/Ppr.hs
=====================================
@@ -1314,17 +1314,21 @@ instance Diagnostic TcRnMessage where
 
     TcRnInvalidInvisTyVarBndr name hs_bndr ->
       mkSimpleDecorated $
-        vcat [ text "Invalid invisible type variable binder:"
-             , nest 2 (ppr hs_bndr)
+        vcat [ hang (text "Invalid invisible type variable binder:")
+                  2 (ppr hs_bndr)
              , text "There is no matching forall-bound variable"
-             , text "in the standalone kind signature for" <+> quotes (ppr name) <> dot ]
+             , text "in the standalone kind signature for" <+> quotes (ppr name) <> dot
+             , text "NB." <+> vcat [
+                text "Only" <+> quotes (text "forall a.") <+> text "-quantification matches invisible binders,",
+                text "whereas" <+> quotes (text "forall {a}.") <+> text "and" <+> quotes (text "forall a ->") <+> text "do not."
+             ]]
 
     TcRnInvisBndrWithoutSig _ hs_bndr ->
       mkSimpleDecorated $
-        vcat [ text "Invalid invisible type variable binder:"
-             , nest 2 (ppr hs_bndr)
+        vcat [ hang (text "Invalid invisible type variable binder:")
+                  2 (ppr hs_bndr)
              , text "Either a standalone kind signature (SAKS)"
-             , nest 2 (text "or a complete user-supplied kind (CUSK)")
+             , text "or a complete user-supplied kind (CUSK, legacy feature)"
              , text "is required to use invisible binders." ]
 
   diagnosticReason = \case


=====================================
compiler/GHC/Tc/TyCl.hs
=====================================
@@ -352,7 +352,7 @@ Note [TcTyCon, MonoTcTyCon, and PolyTcTyCon]
 A TcTyCon is one of the variants of TyCon.  First, here are its invariants:
 
 * TcTyCon: a TyCon built with the TcTyCon constructor
-  A TcTyCon contain TcTyVars in its binders and kind
+  A TcTyCon contains TcTyVars in its binders and kind
 
 * TcTyConBinder: a TyConBinder with a TcTyVar inside (not a TyVar)
 
@@ -448,7 +448,7 @@ S3) Still in kcTyClGroup, we use generaliseTyClDecl to generalize
     each MonoTcTyCon to get a PolyTcTyCon, with skolem TcTyVars in it,
     and a final, fixed kind.
 
-S4) Finally, back in TcTyClDecls, we extend the environment with
+S4) Finally, back in tcTyClDecls, we extend the environment with
     the PolyTcTyCons, and typecheck each declaration (regardless
     of kind signatures etc) to get final TyCon.
 
@@ -539,11 +539,14 @@ But notice that (#16344 comment:3)
 * The algorithm successfully kind-checks this declaration:
     data T2 ka (a::ka) = MkT2 (T2 Type a)
 
-  Starting with (inferInitialKinds)
-    T2 :: (kappa1 :: kappa2 :: *) -> (kappa3 :: kappa4 :: *) -> *
-  we get
-    kappa4 := kappa1   -- from the (a:ka) kind signature
-    kappa1 := Type     -- From application T2 Type
+  Starting with inferInitialKinds:
+    MonoTcTyCon binders:
+      ka[tyv] :: (kappa1[tau] :: Type)
+      ia[tyv] :: (ka[tyv]     :: Type)
+    MonoTcTyCon kind:
+      T2 :: kappa1[tau] -> ka[tyv] -> Type
+    From (ka :: kappa1) and (ka :: Type) we learned that
+      kappa1 := Type
 
   These constraints are soluble so generaliseTcTyCon gives
     T2 :: forall (k::Type) -> k -> *


=====================================
testsuite/tests/th/T12045TH2.hs
=====================================
@@ -1,6 +1,6 @@
 {-# LANGUAGE Haskell2010 #-}
-{-# LANGUAGE TemplateHaskell, TypeApplications, TypeAbstractions,
-             PolyKinds, TypeFamilies, DataKinds #-}
+{-# LANGUAGE TemplateHaskell, TypeApplications, PolyKinds
+             , TypeFamilies, DataKinds #-}
 
 module T12045TH2 where
 


=====================================
testsuite/tests/typecheck/should_fail/T22560_fail_a.stderr
=====================================
@@ -1,7 +1,8 @@
 
 T22560_fail_a.hs:7:1: error: [GHC-57916]
-    • Invalid invisible type variable binder:
-        @k
+    • Invalid invisible type variable binder: @k
       There is no matching forall-bound variable
       in the standalone kind signature for ‘P’.
+      NB. Only ‘forall a.’ -quantification matches invisible binders,
+          whereas ‘forall {a}.’ and ‘forall a ->’ do not.
     • In the data type declaration for ‘P’


=====================================
testsuite/tests/typecheck/should_fail/T22560_fail_b.stderr
=====================================
@@ -1,7 +1,8 @@
 
 T22560_fail_b.hs:6:1: error: [GHC-57916]
-    • Invalid invisible type variable binder:
-        @a
+    • Invalid invisible type variable binder: @a
       There is no matching forall-bound variable
       in the standalone kind signature for ‘P’.
+      NB. Only ‘forall a.’ -quantification matches invisible binders,
+          whereas ‘forall {a}.’ and ‘forall a ->’ do not.
     • In the data type declaration for ‘P’


=====================================
testsuite/tests/typecheck/should_fail/T22560_fail_d.stderr
=====================================
@@ -1,9 +1,8 @@
 
 T22560_fail_d.hs:5:1: error: [GHC-92337]
-    • Invalid invisible type variable binder:
-        @k
+    • Invalid invisible type variable binder: @k
       Either a standalone kind signature (SAKS)
-        or a complete user-supplied kind (CUSK)
+      or a complete user-supplied kind (CUSK, legacy feature)
       is required to use invisible binders.
     • In the data type declaration for ‘T’
     Suggested fix: Add a standalone kind signature for ‘T’



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/99821af2d9bb747adce207357c10f0989ecbe575

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/99821af2d9bb747adce207357c10f0989ecbe575
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230203/101e754d/attachment-0001.html>


More information about the ghc-commits mailing list