summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2015-12-24 14:33:19 -0500
committerRichard Eisenberg <eir@cis.upenn.edu>2015-12-24 14:37:39 -0500
commit2db18b8135335da2da9918b722699df684097be9 (patch)
tree660dd90916aa6568694bbe39cdab83c7af98c5d7
parent48db13d279d592ed3044cbaf3513854bcb0d3dce (diff)
downloadhaskell-2db18b8135335da2da9918b722699df684097be9.tar.gz
Visible type application
This re-working of the typechecker algorithm is based on the paper "Visible type application", by Richard Eisenberg, Stephanie Weirich, and Hamidhasan Ahmed, to be published at ESOP'16. This patch introduces -XTypeApplications, which allows users to say, for example `id @Int`, which has type `Int -> Int`. See the changes to the user manual for details. This patch addresses tickets #10619, #5296, #10589.
-rw-r--r--compiler/basicTypes/DataCon.hs6
-rw-r--r--compiler/basicTypes/MkId.hs36
-rw-r--r--compiler/basicTypes/PatSyn.hs6
-rw-r--r--compiler/coreSyn/MkCore.hs12
-rw-r--r--compiler/deSugar/Coverage.hs6
-rw-r--r--compiler/deSugar/DsArrows.hs4
-rw-r--r--compiler/deSugar/DsBinds.hs30
-rw-r--r--compiler/deSugar/DsExpr.hs8
-rw-r--r--compiler/deSugar/Match.hs2
-rw-r--r--compiler/hsSyn/HsBinds.hs39
-rw-r--r--compiler/hsSyn/HsExpr.hs35
-rw-r--r--compiler/hsSyn/HsUtils.hs26
-rw-r--r--compiler/hsSyn/PlaceHolder.hs5
-rw-r--r--compiler/iface/IfaceSyn.hs2
-rw-r--r--compiler/iface/IfaceType.hs15
-rw-r--r--compiler/main/DynFlags.hs2
-rw-r--r--compiler/main/PprTyThing.hs12
-rw-r--r--compiler/parser/Lexer.x48
-rw-r--r--compiler/parser/Parser.y9
-rw-r--r--compiler/prelude/PrimOp.hs2
-rw-r--r--compiler/prelude/TysPrim.hs16
-rw-r--r--compiler/prelude/TysWiredIn.hs6
-rw-r--r--compiler/rename/RnExpr.hs13
-rw-r--r--compiler/rename/RnSplice.hs4
-rw-r--r--compiler/rename/RnTypes.hs3
-rw-r--r--compiler/typecheck/Inst.hs126
-rw-r--r--compiler/typecheck/TcArrows.hs6
-rw-r--r--compiler/typecheck/TcBinds.hs298
-rw-r--r--compiler/typecheck/TcClassDcl.hs9
-rw-r--r--compiler/typecheck/TcErrors.hs8
-rw-r--r--compiler/typecheck/TcEvidence.hs53
-rw-r--r--compiler/typecheck/TcExpr.hs831
-rw-r--r--compiler/typecheck/TcExpr.hs-boot6
-rw-r--r--compiler/typecheck/TcGenDeriv.hs8
-rw-r--r--compiler/typecheck/TcHsSyn.hs28
-rw-r--r--compiler/typecheck/TcHsType.hs27
-rw-r--r--compiler/typecheck/TcInstDcls.hs23
-rw-r--r--compiler/typecheck/TcMType.hs30
-rw-r--r--compiler/typecheck/TcMatches.hs162
-rw-r--r--compiler/typecheck/TcPat.hs143
-rw-r--r--compiler/typecheck/TcPatSyn.hs60
-rw-r--r--compiler/typecheck/TcRnDriver.hs2
-rw-r--r--compiler/typecheck/TcRnMonad.hs14
-rw-r--r--compiler/typecheck/TcRnTypes.hs95
-rw-r--r--compiler/typecheck/TcSplice.hs15
-rw-r--r--compiler/typecheck/TcTyDecls.hs40
-rw-r--r--compiler/typecheck/TcType.hs77
-rw-r--r--compiler/typecheck/TcUnify.hs475
-rw-r--r--compiler/typecheck/TcValidity.hs15
-rw-r--r--compiler/types/TyCoRep.hs152
-rw-r--r--compiler/types/Type.hs28
-rw-r--r--docs/users_guide/7.12.1-notes.rst5
-rw-r--r--docs/users_guide/glasgow_exts.rst50
-rw-r--r--libraries/base/tests/T9681.stderr2
-rw-r--r--libraries/ghc-boot/GHC/LanguageExtensions.hs1
-rw-r--r--testsuite/tests/ado/ado002.stderr108
-rw-r--r--testsuite/tests/annotations/should_fail/annfail08.stderr2
-rw-r--r--testsuite/tests/arrows/should_fail/T5380.stderr3
-rw-r--r--testsuite/tests/boxy/all.T4
-rw-r--r--testsuite/tests/deSugar/should_compile/T2431.stderr8
-rw-r--r--testsuite/tests/driver/T2182.stderr4
-rw-r--r--testsuite/tests/driver/T4437.hs3
-rw-r--r--testsuite/tests/driver/werror.stderr20
-rw-r--r--testsuite/tests/gadt/T3169.stderr3
-rw-r--r--testsuite/tests/gadt/gadt-escape1.stderr4
-rw-r--r--testsuite/tests/gadt/gadt13.stderr9
-rw-r--r--testsuite/tests/gadt/gadt7.stderr1
-rw-r--r--testsuite/tests/gadt/rw.stderr11
-rw-r--r--testsuite/tests/ghc-api/annotations/T10280.stderr16
-rw-r--r--testsuite/tests/ghc-api/annotations/T10357.stderr24
-rw-r--r--testsuite/tests/ghci.debugger/scripts/break003.stderr6
-rw-r--r--testsuite/tests/ghci.debugger/scripts/break003.stdout8
-rw-r--r--testsuite/tests/ghci.debugger/scripts/break005.stdout4
-rw-r--r--testsuite/tests/ghci.debugger/scripts/break006.stderr12
-rw-r--r--testsuite/tests/ghci.debugger/scripts/break006.stdout10
-rw-r--r--testsuite/tests/ghci.debugger/scripts/hist001.stdout28
-rw-r--r--testsuite/tests/ghci/scripts/Defer02.stderr11
-rw-r--r--testsuite/tests/ghci/scripts/T10122.stdout2
-rw-r--r--testsuite/tests/ghci/scripts/T10508.stderr18
-rw-r--r--testsuite/tests/ghci/scripts/T7627.stdout10
-rw-r--r--testsuite/tests/ghci/scripts/T8649.stderr1
-rw-r--r--testsuite/tests/ghci/scripts/T8959b.stderr26
-rw-r--r--testsuite/tests/ghci/scripts/ghci013.stdout2
-rw-r--r--testsuite/tests/ghci/scripts/ghci025.stdout24
-rw-r--r--testsuite/tests/ghci/scripts/ghci047.stderr6
-rw-r--r--testsuite/tests/ghci/scripts/ghci050.stderr22
-rw-r--r--testsuite/tests/ghci/scripts/ghci052.stderr3
-rw-r--r--testsuite/tests/ghci/scripts/ghci053.stderr2
-rw-r--r--testsuite/tests/ghci/scripts/ghci055.stdout2
-rw-r--r--testsuite/tests/indexed-types/should_compile/PushedInAsGivens.stderr1
-rw-r--r--testsuite/tests/indexed-types/should_fail/GADTwrong1.stderr1
-rw-r--r--testsuite/tests/indexed-types/should_fail/T2544.stderr38
-rw-r--r--testsuite/tests/indexed-types/should_fail/T2693.stderr8
-rw-r--r--testsuite/tests/indexed-types/should_fail/T3330a.stderr2
-rw-r--r--testsuite/tests/indexed-types/should_fail/T3330c.stderr3
-rw-r--r--testsuite/tests/indexed-types/should_fail/T3440.stderr1
-rw-r--r--testsuite/tests/indexed-types/should_fail/T4099.stderr40
-rw-r--r--testsuite/tests/indexed-types/should_fail/T4179.stderr13
-rw-r--r--testsuite/tests/indexed-types/should_fail/T4485.stderr53
-rw-r--r--testsuite/tests/indexed-types/should_fail/T5439.stderr4
-rw-r--r--testsuite/tests/indexed-types/should_fail/T7010.stderr13
-rw-r--r--testsuite/tests/indexed-types/should_fail/T7194.stderr1
-rw-r--r--testsuite/tests/indexed-types/should_fail/T7354.stderr19
-rw-r--r--testsuite/tests/indexed-types/should_fail/T7354a.stderr11
-rw-r--r--testsuite/tests/indexed-types/should_fail/T7729.stderr19
-rw-r--r--testsuite/tests/indexed-types/should_fail/T7729a.stderr23
-rw-r--r--testsuite/tests/indexed-types/should_fail/T7788.stderr17
-rw-r--r--testsuite/tests/indexed-types/should_fail/T8227.stderr2
-rw-r--r--testsuite/tests/indexed-types/should_fail/T8518.stderr56
-rw-r--r--testsuite/tests/indexed-types/should_fail/T9554.stderr42
-rw-r--r--testsuite/tests/indexed-types/should_fail/T9662.stderr9
-rw-r--r--testsuite/tests/module/mod121.stderr8
-rw-r--r--testsuite/tests/module/mod147.stderr6
-rw-r--r--testsuite/tests/module/mod160.stderr12
-rw-r--r--testsuite/tests/module/mod69.stderr4
-rw-r--r--testsuite/tests/module/mod70.stderr4
-rw-r--r--testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail07.stderr11
-rw-r--r--testsuite/tests/parser/should_compile/T2245.stderr6
-rw-r--r--testsuite/tests/parser/should_compile/VtaParse.hs63
-rw-r--r--testsuite/tests/parser/should_compile/all.T1
-rw-r--r--testsuite/tests/parser/should_compile/read014.stderr8
-rw-r--r--testsuite/tests/parser/should_fail/readFail003.stderr4
-rw-r--r--testsuite/tests/partial-sigs/should_compile/T10403.stderr5
-rw-r--r--testsuite/tests/partial-sigs/should_compile/T10438.stderr2
-rw-r--r--testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInExpressionSignature.stderr8
-rw-r--r--testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInPatternSignature.stderr8
-rw-r--r--testsuite/tests/partial-sigs/should_fail/Forall1Bad.stderr8
-rw-r--r--testsuite/tests/partial-sigs/should_fail/NamedWildcardExplicitForall.stderr7
-rw-r--r--testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotEnabled.stderr1
-rw-r--r--testsuite/tests/partial-sigs/should_fail/ScopedNamedWildcardsBad.stderr9
-rw-r--r--testsuite/tests/patsyn/should_fail/records-poly-update.stderr7
-rw-r--r--testsuite/tests/perf/compiler/all.T3
-rw-r--r--testsuite/tests/polykinds/T10503.stderr2
-rw-r--r--testsuite/tests/polykinds/T6068.stdout2
-rw-r--r--testsuite/tests/polykinds/T7438.stderr8
-rw-r--r--testsuite/tests/polykinds/T7594.stderr1
-rw-r--r--testsuite/tests/polykinds/T9144.stderr16
-rw-r--r--testsuite/tests/polykinds/TidyClassKinds.hs13
-rw-r--r--testsuite/tests/polykinds/TidyClassKinds.stderr8
-rw-r--r--testsuite/tests/polykinds/all.T1
-rw-r--r--testsuite/tests/rename/should_compile/T3823.stderr3
-rw-r--r--testsuite/tests/rename/should_fail/T10618.stderr12
-rw-r--r--testsuite/tests/rename/should_fail/T2993.stderr4
-rw-r--r--testsuite/tests/rename/should_fail/T7937.stderr8
-rw-r--r--testsuite/tests/rename/should_fail/mc13.stderr4
-rw-r--r--testsuite/tests/rename/should_fail/rnfail016.stderr8
-rw-r--r--testsuite/tests/rename/should_fail/rnfail051.stderr3
-rw-r--r--testsuite/tests/roles/should_compile/Roles1.stderr74
-rw-r--r--testsuite/tests/roles/should_compile/T8958.stderr2
-rw-r--r--testsuite/tests/rts/T9045.hs2
-rw-r--r--testsuite/tests/safeHaskell/ghci/p16.stderr12
-rw-r--r--testsuite/tests/safeHaskell/ghci/p6.stderr20
-rw-r--r--testsuite/tests/simplCore/should_compile/T7360.stderr24
-rw-r--r--testsuite/tests/simplCore/should_compile/simpl017.stderr58
-rw-r--r--testsuite/tests/th/T10945.stderr59
-rw-r--r--testsuite/tests/th/T8577.stderr3
-rw-r--r--testsuite/tests/typecheck/bug1465/bug1465.stderr1
-rw-r--r--testsuite/tests/typecheck/should_compile/FD1.stderr2
-rw-r--r--testsuite/tests/typecheck/should_compile/FD2.stderr15
-rw-r--r--testsuite/tests/typecheck/should_compile/PushHRIf.hs7
-rw-r--r--testsuite/tests/typecheck/should_compile/T10072.stderr16
-rw-r--r--testsuite/tests/typecheck/should_compile/T10971a.stderr4
-rw-r--r--testsuite/tests/typecheck/should_compile/T2494.stderr58
-rw-r--r--testsuite/tests/typecheck/should_compile/Vta1.hs95
-rw-r--r--testsuite/tests/typecheck/should_compile/Vta2.hs14
-rw-r--r--testsuite/tests/typecheck/should_compile/all.T3
-rw-r--r--testsuite/tests/typecheck/should_compile/holes.stderr66
-rw-r--r--testsuite/tests/typecheck/should_compile/holes3.stderr72
-rw-r--r--testsuite/tests/typecheck/should_compile/tc141.stderr16
-rw-r--r--testsuite/tests/typecheck/should_compile/tc168.stderr24
-rw-r--r--testsuite/tests/typecheck/should_compile/tc211.stderr77
-rw-r--r--testsuite/tests/typecheck/should_compile/tc243.stderr4
-rw-r--r--testsuite/tests/typecheck/should_fail/CustomTypeErrors01.stderr8
-rw-r--r--testsuite/tests/typecheck/should_fail/ExpandSynsFail2.stderr19
-rw-r--r--testsuite/tests/typecheck/should_fail/T10495.stderr13
-rw-r--r--testsuite/tests/typecheck/should_fail/T10971d.stderr25
-rw-r--r--testsuite/tests/typecheck/should_fail/T11274.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/T1899.stderr1
-rw-r--r--testsuite/tests/typecheck/should_fail/T2414.stderr13
-rw-r--r--testsuite/tests/typecheck/should_fail/T2534.stderr15
-rw-r--r--testsuite/tests/typecheck/should_fail/T2688.stderr20
-rw-r--r--testsuite/tests/typecheck/should_fail/T2846b.stderr8
-rw-r--r--testsuite/tests/typecheck/should_fail/T3102.stderr23
-rw-r--r--testsuite/tests/typecheck/should_fail/T3613.stderr30
-rw-r--r--testsuite/tests/typecheck/should_fail/T3950.stderr15
-rw-r--r--testsuite/tests/typecheck/should_fail/T5095.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/T5689.stderr14
-rw-r--r--testsuite/tests/typecheck/should_fail/T5853.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/T6069.stderr39
-rw-r--r--testsuite/tests/typecheck/should_fail/T7264.stderr21
-rw-r--r--testsuite/tests/typecheck/should_fail/T7368.stderr1
-rw-r--r--testsuite/tests/typecheck/should_fail/T7453.stderr26
-rw-r--r--testsuite/tests/typecheck/should_fail/T7734.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/T7851.stderr19
-rw-r--r--testsuite/tests/typecheck/should_fail/T8142.stderr43
-rw-r--r--testsuite/tests/typecheck/should_fail/T8428.stderr16
-rw-r--r--testsuite/tests/typecheck/should_fail/T8603.stderr15
-rw-r--r--testsuite/tests/typecheck/should_fail/T9109.stderr7
-rw-r--r--testsuite/tests/typecheck/should_fail/T9774.stderr14
-rw-r--r--testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr12
-rw-r--r--testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr11
-rw-r--r--testsuite/tests/typecheck/should_fail/VtaFail.hs57
-rw-r--r--testsuite/tests/typecheck/should_fail/VtaFail.stderr94
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T3
-rw-r--r--testsuite/tests/typecheck/should_fail/mc19.stderr23
-rw-r--r--testsuite/tests/typecheck/should_fail/mc21.stderr24
-rw-r--r--testsuite/tests/typecheck/should_fail/mc22.stderr51
-rw-r--r--testsuite/tests/typecheck/should_fail/mc23.stderr17
-rw-r--r--testsuite/tests/typecheck/should_fail/mc24.stderr18
-rw-r--r--testsuite/tests/typecheck/should_fail/mc25.stderr30
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail001.stderr13
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail002.stderr6
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail004.stderr6
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail005.stderr6
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail007.stderr14
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail010.stderr10
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail013.stderr4
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail014.stderr1
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail016.stderr42
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail018.stderr8
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail029.stderr8
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail032.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail033.stderr17
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail034.stderr28
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail065.stderr11
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail068.stderr47
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail076.stderr1
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail099.stderr1
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail103.stderr43
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail104.stderr24
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail131.stderr7
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail133.stderr3
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail140.stderr8
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail143.stderr14
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail153.stderr35
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail165.hs3
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail165.stderr12
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail168.stderr28
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail174.hs2
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail174.stderr65
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail175.stderr4
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail178.stderr26
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail179.stderr11
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail181.stderr29
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail185.stderr26
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail189.stderr16
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail191.stderr24
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail193.stderr23
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail198.stderr28
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail201.stderr11
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail204.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail206.stderr110
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail208.stderr18
-rwxr-xr-xtestsuite/tests/typecheck/should_run/all.T2
-rw-r--r--testsuite/tests/typecheck/should_run/tcrun035.stderr11
-rw-r--r--testsuite/tests/warnings/should_compile/PluralS.stderr2
-rw-r--r--testsuite/tests/warnings/should_compile/T11077.stderr2
257 files changed, 4144 insertions, 2358 deletions
diff --git a/compiler/basicTypes/DataCon.hs b/compiler/basicTypes/DataCon.hs
index 712a9b2b86..466e3c1604 100644
--- a/compiler/basicTypes/DataCon.hs
+++ b/compiler/basicTypes/DataCon.hs
@@ -768,7 +768,7 @@ mkDataCon name declared_infix prom_info
tag = assoc "mkDataCon" (tyConDataCons rep_tycon `zip` [fIRST_TAG..]) con
rep_arg_tys = dataConRepArgTys con
- rep_ty = mkInvForAllTys univ_tvs $ mkInvForAllTys ex_tvs $
+ rep_ty = mkSpecForAllTys univ_tvs $ mkInvForAllTys ex_tvs $
mkFunTys rep_arg_tys $
mkTyConApp rep_tycon (mkTyVarTys univ_tvs)
@@ -1024,8 +1024,8 @@ dataConUserType (MkData { dcUnivTyVars = univ_tvs,
dcExTyVars = ex_tvs, dcEqSpec = eq_spec,
dcOtherTheta = theta, dcOrigArgTys = arg_tys,
dcOrigResTy = res_ty })
- = mkInvForAllTys ((univ_tvs `minusList` map eqSpecTyVar eq_spec) ++
- ex_tvs) $
+ = mkSpecForAllTys ((univ_tvs `minusList` map eqSpecTyVar eq_spec) ++
+ ex_tvs) $
mkFunTys theta $
mkFunTys arg_tys $
res_ty
diff --git a/compiler/basicTypes/MkId.hs b/compiler/basicTypes/MkId.hs
index 691e087ac2..f690732909 100644
--- a/compiler/basicTypes/MkId.hs
+++ b/compiler/basicTypes/MkId.hs
@@ -281,8 +281,8 @@ mkDictSelId name clas
arg_tys = dataConRepArgTys data_con -- Includes the dictionary superclasses
val_index = assoc "MkId.mkDictSelId" (sel_names `zip` [0..]) name
- sel_ty = mkInvForAllTys tyvars (mkFunTy (mkClassPred clas (mkTyVarTys tyvars))
- (getNth arg_tys val_index))
+ sel_ty = mkSpecForAllTys tyvars (mkFunTy (mkClassPred clas (mkTyVarTys tyvars))
+ (getNth arg_tys val_index))
base_info = noCafIdInfo
`setArityInfo` 1
@@ -930,7 +930,7 @@ mkPrimOpId prim_op
= id
where
(tyvars,arg_tys,res_ty, arity, strict_sig) = primOpSig prim_op
- ty = mkInvForAllTys tyvars (mkFunTys arg_tys res_ty)
+ ty = mkSpecForAllTys tyvars (mkFunTys arg_tys res_ty)
name = mkWiredInName gHC_PRIM (primOpOcc prim_op)
(mkPrimOpIdUnique (primOpTag prim_op))
(AnId id) UserSyntax
@@ -1014,7 +1014,7 @@ mkDictFunId dfun_name tvs theta clas tys
mkDictFunTy :: [TyVar] -> ThetaType -> Class -> [Type] -> Type
mkDictFunTy tvs theta clas tys
- = mkInvSigmaTy tvs theta (mkClassPred clas tys)
+ = mkSpecSigmaTy tvs theta (mkClassPred clas tys)
{-
************************************************************************
@@ -1062,7 +1062,7 @@ dollarId = pcMiscPrelId dollarName ty
(noCafIdInfo `setUnfoldingInfo` unf)
where
fun_ty = mkFunTy alphaTy openBetaTy
- ty = mkInvForAllTys [levity2TyVar, alphaTyVar, openBetaTyVar] $
+ ty = mkSpecForAllTys [levity2TyVar, alphaTyVar, openBetaTyVar] $
mkFunTy fun_ty fun_ty
unf = mkInlineUnfolding (Just 2) rhs
[f,x] = mkTemplateLocals [fun_ty, alphaTy]
@@ -1076,7 +1076,7 @@ proxyHashId
= pcMiscPrelId proxyName ty
(noCafIdInfo `setUnfoldingInfo` evaldUnfolding) -- Note [evaldUnfoldings]
where
- ty = mkInvForAllTys [kv, tv] (mkProxyPrimTy k t)
+ ty = mkSpecForAllTys [kv, tv] (mkProxyPrimTy k t)
kv = kKiVar
k = mkTyVarTy kv
[tv] = mkTemplateTyVars [k]
@@ -1091,9 +1091,9 @@ unsafeCoerceId
info = noCafIdInfo `setInlinePragInfo` alwaysInlinePragma
`setUnfoldingInfo` mkCompulsoryUnfolding rhs
- ty = mkInvForAllTys [ levity1TyVar, levity2TyVar
- , openAlphaTyVar, openBetaTyVar ]
- (mkFunTy openAlphaTy openBetaTy)
+ ty = mkSpecForAllTys [ levity1TyVar, levity2TyVar
+ , openAlphaTyVar, openBetaTyVar ]
+ (mkFunTy openAlphaTy openBetaTy)
[x] = mkTemplateLocals [openAlphaTy]
rhs = mkLams [ levity1TyVar, levity2TyVar
@@ -1125,8 +1125,8 @@ seqId = pcMiscPrelId seqName ty info
-- LHS of rules. That way we can have rules for 'seq';
-- see Note [seqId magic]
- ty = mkInvForAllTys [alphaTyVar,betaTyVar]
- (mkFunTy alphaTy (mkFunTy betaTy betaTy))
+ ty = mkSpecForAllTys [alphaTyVar,betaTyVar]
+ (mkFunTy alphaTy (mkFunTy betaTy betaTy))
[x,y] = mkTemplateLocals [alphaTy, betaTy]
rhs = mkLams [alphaTyVar,betaTyVar,x,y] (Case (Var x) x betaTy [(DEFAULT, [], Var y)])
@@ -1158,16 +1158,16 @@ lazyId :: Id -- See Note [lazyId magic]
lazyId = pcMiscPrelId lazyIdName ty info
where
info = noCafIdInfo
- ty = mkInvForAllTys [alphaTyVar] (mkFunTy alphaTy alphaTy)
+ ty = mkSpecForAllTys [alphaTyVar] (mkFunTy alphaTy alphaTy)
oneShotId :: Id -- See Note [The oneShot function]
oneShotId = pcMiscPrelId oneShotName ty info
where
info = noCafIdInfo `setInlinePragInfo` alwaysInlinePragma
`setUnfoldingInfo` mkCompulsoryUnfolding rhs
- ty = mkInvForAllTys [ levity1TyVar, levity2TyVar
- , openAlphaTyVar, openBetaTyVar ]
- (mkFunTy fun_ty fun_ty)
+ ty = mkSpecForAllTys [ levity1TyVar, levity2TyVar
+ , openAlphaTyVar, openBetaTyVar ]
+ (mkFunTy fun_ty fun_ty)
fun_ty = mkFunTy alphaTy betaTy
[body, x] = mkTemplateLocals [fun_ty, openAlphaTy]
x' = setOneShotLambda x
@@ -1188,7 +1188,7 @@ runRWId = pcMiscPrelId runRWName ty info
arg_ty = stateRW `mkFunTy` ret_ty
-- (State# RealWorld -> (# State# RealWorld, o #))
-- -> (# State# RealWorld, o #)
- ty = mkInvForAllTys [levity1TyVar, openAlphaTyVar] $
+ ty = mkSpecForAllTys [levity1TyVar, openAlphaTyVar] $
arg_ty `mkFunTy` ret_ty
--------------------------------------------------------------------------------
@@ -1196,7 +1196,7 @@ magicDictId :: Id -- See Note [magicDictId magic]
magicDictId = pcMiscPrelId magicDictName ty info
where
info = noCafIdInfo `setInlinePragInfo` neverInlinePragma
- ty = mkInvForAllTys [alphaTyVar] alphaTy
+ ty = mkSpecForAllTys [alphaTyVar] alphaTy
--------------------------------------------------------------------------------
@@ -1210,7 +1210,7 @@ coerceId = pcMiscPrelId coerceName ty info
eqRPrimTy = mkTyConApp eqReprPrimTyCon [ liftedTypeKind
, liftedTypeKind
, alphaTy, betaTy ]
- ty = mkInvForAllTys [alphaTyVar, betaTyVar] $
+ ty = mkSpecForAllTys [alphaTyVar, betaTyVar] $
mkFunTys [eqRTy, alphaTy] betaTy
[eqR,x,eq] = mkTemplateLocals [eqRTy, alphaTy, eqRPrimTy]
diff --git a/compiler/basicTypes/PatSyn.hs b/compiler/basicTypes/PatSyn.hs
index c35bcf3e13..a884e963b1 100644
--- a/compiler/basicTypes/PatSyn.hs
+++ b/compiler/basicTypes/PatSyn.hs
@@ -25,7 +25,7 @@ module PatSyn (
#include "HsVersions.h"
import Type
-import TcType( mkInvSigmaTy )
+import TcType( mkSpecSigmaTy )
import Name
import Outputable
import Unique
@@ -328,8 +328,8 @@ patSynType :: PatSyn -> Type
patSynType (MkPatSyn { psUnivTyVars = univ_tvs, psReqTheta = req_theta
, psExTyVars = ex_tvs, psProvTheta = prov_theta
, psArgs = orig_args, psOrigResTy = orig_res_ty })
- = mkInvSigmaTy univ_tvs req_theta $
- mkInvSigmaTy ex_tvs prov_theta $
+ = mkSpecSigmaTy univ_tvs req_theta $ -- use mkSpecSigmaTy because it
+ mkSpecSigmaTy ex_tvs prov_theta $ -- prints better
mkFunTys orig_args orig_res_ty
-- | Should the 'PatSyn' be presented infix?
diff --git a/compiler/coreSyn/MkCore.hs b/compiler/coreSyn/MkCore.hs
index 07db78a931..2f1b67fe79 100644
--- a/compiler/coreSyn/MkCore.hs
+++ b/compiler/coreSyn/MkCore.hs
@@ -62,7 +62,7 @@ import TysWiredIn
import PrelNames
import HsUtils ( mkChunkified, chunkify )
-import TcType ( mkInvSigmaTy )
+import TcType ( mkSpecSigmaTy )
import Type
import Coercion ( isCoVar )
import TysPrim
@@ -684,8 +684,8 @@ mkRuntimeErrorId name = pc_bottoming_Id1 name runtimeErrorTy
runtimeErrorTy :: Type
-- The runtime error Ids take a UTF8-encoded string as argument
-runtimeErrorTy = mkInvSigmaTy [levity1TyVar, openAlphaTyVar] []
- (mkFunTy addrPrimTy openAlphaTy)
+runtimeErrorTy = mkSpecSigmaTy [levity1TyVar, openAlphaTyVar] []
+ (mkFunTy addrPrimTy openAlphaTy)
errorName :: Name
errorName = mkWiredInIdName gHC_ERR (fsLit "error") errorIdKey eRROR_ID
@@ -694,7 +694,7 @@ eRROR_ID :: Id
eRROR_ID = pc_bottoming_Id2 errorName errorTy
errorTy :: Type -- See Note [Error and friends have an "open-tyvar" forall]
-errorTy = mkInvSigmaTy [levity1TyVar, openAlphaTyVar] []
+errorTy = mkSpecSigmaTy [levity1TyVar, openAlphaTyVar] []
(mkFunTys [ mkClassPred
ipClass
[ mkStrLitTy (fsLit "callStack")
@@ -709,7 +709,7 @@ uNDEFINED_ID :: Id
uNDEFINED_ID = pc_bottoming_Id1 undefinedName undefinedTy
undefinedTy :: Type -- See Note [Error and friends have an "open-tyvar" forall]
-undefinedTy = mkInvSigmaTy [levity1TyVar, openAlphaTyVar] []
+undefinedTy = mkSpecSigmaTy [levity1TyVar, openAlphaTyVar] []
(mkFunTy (mkClassPred
ipClass
[ mkStrLitTy (fsLit "callStack")
@@ -727,7 +727,7 @@ Notice the levity polymophism. This ensures that
* unboxed as well as boxed types
* polymorphic types
This is OK because it never returns, so the return type is irrelevant.
-See Note [Sort-polymorphic tyvars accept foralls] in TcUnify.
+See Note [Sort-polymorphic tyvars accept foralls] in TcMType.
************************************************************************
diff --git a/compiler/deSugar/Coverage.hs b/compiler/deSugar/Coverage.hs
index 57d77c7eef..2711925161 100644
--- a/compiler/deSugar/Coverage.hs
+++ b/compiler/deSugar/Coverage.hs
@@ -632,7 +632,7 @@ addTickHsExpr (ExprWithTySigOut e ty) =
(addTickLHsExprNever e) -- No need to tick the inner expression
(return ty) -- for expressions with signatures
-addTickHsExpr e@(HsType _) = return e
+addTickHsExpr e@(HsTypeOut _) = return e
-- Others should never happen in expression content.
addTickHsExpr e = pprPanic "addTickHsExpr" (ppr e)
@@ -870,8 +870,8 @@ addTickHsCmd (HsCmdArrForm e fix cmdtop) =
(return fix)
(mapM (liftL (addTickHsCmdTop)) cmdtop)
-addTickHsCmd (HsCmdCast co cmd)
- = liftM2 HsCmdCast (return co) (addTickHsCmd cmd)
+addTickHsCmd (HsCmdWrap w cmd)
+ = liftM2 HsCmdWrap (return w) (addTickHsCmd cmd)
-- Others should never happen in a command context.
--addTickHsCmd e = pprPanic "addTickHsCmd" (ppr e)
diff --git a/compiler/deSugar/DsArrows.hs b/compiler/deSugar/DsArrows.hs
index 56c44c59d5..cc831d7c05 100644
--- a/compiler/deSugar/DsArrows.hs
+++ b/compiler/deSugar/DsArrows.hs
@@ -614,9 +614,9 @@ dsCmd _ids local_vars _stack_ty _res_ty (HsCmdArrForm op _ args) env_ids = do
return (mkApps (App core_op (Type env_ty)) core_args,
unionVarSets fv_sets)
-dsCmd ids local_vars stack_ty res_ty (HsCmdCast coercion cmd) env_ids = do
+dsCmd ids local_vars stack_ty res_ty (HsCmdWrap wrap cmd) env_ids = do
(core_cmd, env_ids') <- dsCmd ids local_vars stack_ty res_ty cmd env_ids
- wrapped_cmd <- dsHsWrapper (mkWpCastN coercion) core_cmd
+ wrapped_cmd <- dsHsWrapper wrap core_cmd
return (wrapped_cmd, env_ids')
dsCmd _ _ _ _ _ c = pprPanic "dsCmd" (ppr c)
diff --git a/compiler/deSugar/DsBinds.hs b/compiler/deSugar/DsBinds.hs
index 7bc12cb2bd..a79e9fa7e7 100644
--- a/compiler/deSugar/DsBinds.hs
+++ b/compiler/deSugar/DsBinds.hs
@@ -160,20 +160,23 @@ dsHsBind dflags
(AbsBinds { abs_tvs = tyvars, abs_ev_vars = dicts
, abs_exports = [export]
, abs_ev_binds = ev_binds, abs_binds = binds })
- | ABE { abe_wrap = wrap, abe_poly = global
+ | ABE { abe_inst_wrap = inst_wrap, abe_wrap = wrap, abe_poly = global
, abe_mono = local, abe_prags = prags } <- export
, not (xopt LangExt.Strict dflags) -- handle strict binds
, not (anyBag (isBangedPatBind . unLoc) binds) -- in the next case
= -- push type constraints deeper for pattern match check
+ -- See Note [AbsBinds wrappers] in HsBinds
addDictsDs (toTcTypeBag (listToBag dicts)) $
do { (_, bind_prs) <- ds_lhs_binds binds
; let core_bind = Rec bind_prs
; ds_binds <- dsTcEvBinds_s ev_binds
+ ; inner_rhs <- dsHsWrapper inst_wrap $
+ Let core_bind $
+ Var local
; rhs <- dsHsWrapper wrap $ -- Usually the identity
mkLams tyvars $ mkLams dicts $
mkCoreLets ds_binds $
- Let core_bind $
- Var local
+ inner_rhs
; (spec_binds, rules) <- dsSpecs rhs prags
@@ -212,13 +215,17 @@ dsHsBind dflags
-- Note [Desugar Strict binds]
; (exported_force_vars, extra_exports) <- get_exports local_force_vars
- ; let mk_bind (ABE { abe_wrap = wrap, abe_poly = global
+ ; let mk_bind (ABE { abe_inst_wrap = inst_wrap, abe_wrap = wrap
+ , abe_poly = global
, abe_mono = local, abe_prags = spec_prags })
+ -- See Note [AbsBinds wrappers] in HsBinds
= do { tup_id <- newSysLocalDs tup_ty
+ ; inner_rhs <- dsHsWrapper inst_wrap $
+ mkTupleSelector all_locals local tup_id $
+ mkVarApps (Var poly_tup_id) (tyvars ++ dicts)
; rhs <- dsHsWrapper wrap $
- mkLams tyvars $ mkLams dicts $
- mkTupleSelector all_locals local tup_id $
- mkVarApps (Var poly_tup_id) (tyvars ++ dicts)
+ mkLams tyvars $ mkLams dicts $
+ inner_rhs
; let rhs_for_spec = Let (NonRec poly_tup_id poly_tup_rhs) rhs
; (spec_binds, rules) <- dsSpecs rhs_for_spec spec_prags
; let global' = (global `setInlinePragma` defaultInlinePragma)
@@ -277,6 +284,7 @@ dsHsBind dflags
return (ABE {abe_poly = global
,abe_mono = local
,abe_wrap = WpHole
+ ,abe_inst_wrap = WpHole
,abe_prags = SpecPrags []})
dsHsBind _ (PatSynBind{}) = panic "dsHsBind: PatSynBind"
@@ -963,10 +971,10 @@ dsHsWrapper (WpLet ev_binds) e = do bs <- dsTcEvBinds ev_binds
return (mkCoreLets bs e)
dsHsWrapper (WpCompose c1 c2) e = do { e1 <- dsHsWrapper c2 e
; dsHsWrapper c1 e1 }
-dsHsWrapper (WpFun c1 c2 t1 _) e = do { x <- newSysLocalDs t1
- ; e1 <- dsHsWrapper c1 (Var x)
- ; e2 <- dsHsWrapper c2 (mkCoreAppDs (text "dsHsWrapper") e e1)
- ; return (Lam x e2) }
+dsHsWrapper (WpFun c1 c2 t1) e = do { x <- newSysLocalDs t1
+ ; e1 <- dsHsWrapper c1 (Var x)
+ ; e2 <- dsHsWrapper c2 (mkCoreAppDs (text "dsHsWrapper") e e1)
+ ; return (Lam x e2) }
dsHsWrapper (WpCast co) e = ASSERT(coercionRole co == Representational)
return $ mkCastDs e co
dsHsWrapper (WpEvLam ev) e = return $ Lam ev e
diff --git a/compiler/deSugar/DsExpr.hs b/compiler/deSugar/DsExpr.hs
index 3b9a4cfbb0..999b945c0f 100644
--- a/compiler/deSugar/DsExpr.hs
+++ b/compiler/deSugar/DsExpr.hs
@@ -222,7 +222,10 @@ dsExpr (HsLamCase arg matches)
; return $ Lam arg_var $ bindNonRec discrim_var (Var arg_var) matching_code }
dsExpr e@(HsApp fun arg)
- = mkCoreAppDs (text "HsApp" <+> ppr e) <$> dsLExpr fun <*> dsLExpr arg
+ -- ignore type arguments here; they're in the wrappers instead at this point
+ | isLHsTypeExpr arg = dsLExpr fun
+ | otherwise = mkCoreAppDs (text "HsApp" <+> ppr e)
+ <$> dsLExpr fun <*> dsLExpr arg
{-
@@ -718,7 +721,8 @@ dsExpr (EWildPat {}) = panic "dsExpr:EWildPat"
dsExpr (EAsPat {}) = panic "dsExpr:EAsPat"
dsExpr (EViewPat {}) = panic "dsExpr:EViewPat"
dsExpr (ELazyPat {}) = panic "dsExpr:ELazyPat"
-dsExpr (HsType {}) = panic "dsExpr:HsType"
+dsExpr (HsType {}) = panic "dsExpr:HsType" -- removed by typechecker
+dsExpr (HsTypeOut {}) = panic "dsExpr:HsTypeOut" -- handled in HsApp case
dsExpr (HsDo {}) = panic "dsExpr:HsDo"
dsExpr (HsRecFld {}) = panic "dsExpr:HsRecFld"
diff --git a/compiler/deSugar/Match.hs b/compiler/deSugar/Match.hs
index b5a50e75af..7530a0a243 100644
--- a/compiler/deSugar/Match.hs
+++ b/compiler/deSugar/Match.hs
@@ -956,7 +956,7 @@ viewLExprEq (e1,_) (e2,_) = lexp e1 e2
-- equating different ways of writing a coercion)
wrap WpHole WpHole = True
wrap (WpCompose w1 w2) (WpCompose w1' w2') = wrap w1 w1' && wrap w2 w2'
- wrap (WpFun w1 w2 _ _) (WpFun w1' w2' _ _) = wrap w1 w1' && wrap w2 w2'
+ wrap (WpFun w1 w2 _) (WpFun w1' w2' _) = wrap w1 w1' && wrap w2 w2'
wrap (WpCast co) (WpCast co') = co `eqCoercion` co'
wrap (WpEvApp et1) (WpEvApp et2) = et1 `ev_term` et2
wrap (WpTyApp t) (WpTyApp t') = eqType t t'
diff --git a/compiler/hsSyn/HsBinds.hs b/compiler/hsSyn/HsBinds.hs
index 7a1146395b..93dc5a9f10 100644
--- a/compiler/hsSyn/HsBinds.hs
+++ b/compiler/hsSyn/HsBinds.hs
@@ -236,11 +236,13 @@ deriving instance (DataId idL, DataId idR)
-- See Note [AbsBinds]
data ABExport id
- = ABE { abe_poly :: id -- ^ Any INLINE pragmas is attached to this Id
- , abe_mono :: id
- , abe_wrap :: HsWrapper -- ^ See Note [AbsBinds wrappers]
- -- Shape: (forall abs_tvs. abs_ev_vars => abe_mono) ~ abe_poly
- , abe_prags :: TcSpecPrags -- ^ SPECIALISE pragmas
+ = ABE { abe_poly :: id -- ^ Any INLINE pragmas is attached to this Id
+ , abe_mono :: id
+ , abe_inst_wrap :: HsWrapper -- ^ See Note [AbsBinds wrappers]
+ -- ^ Shape: abe_mono ~ abe_insted
+ , abe_wrap :: HsWrapper -- ^ See Note [AbsBinds wrappers]
+ -- Shape: (forall abs_tvs. abs_ev_vars => abe_insted) ~ abe_poly
+ , abe_prags :: TcSpecPrags -- ^ SPECIALISE pragmas
} deriving (Data, Typeable)
-- | - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnPattern',
@@ -375,6 +377,27 @@ The abe_wrap field deals with impedance-matching between
and the thing we really want, which may have fewer type
variables. The action happens in TcBinds.mkExport.
+For abe_inst_wrap, consider this:
+ x = (*)
+The abe_mono type will be forall a. Num a => a -> a -> a
+because no instantiation happens during typechecking. Before inferring
+a final type, we must instantiate this. See Note [Instantiate when inferring
+a type] in TcBinds. The abe_inst_wrap takes the uninstantiated abe_mono type
+to a proper instantiated type. In this case, the "abe_insted" is
+(b -> b -> b). Note that the value of "abe_insted" isn't important; it's
+just an intermediate form as we're going from abe_mono to abe_poly. See also
+the desugaring code in DsBinds.
+
+It's conceivable that we could combine the two wrappers, but note that there
+is a gap: neither wrapper tacks on the tvs and dicts from the outer AbsBinds.
+These bits are added manually in desugaring. (See DsBinds.dsHsBind.) A problem
+that would arise in combining them is that zonking becomes more challenging:
+we want to zonk the tvs and dicts in the AbsBinds, but then we end up re-zonking
+when we zonk the ABExport. And -- worse -- the combined wrapper would have
+the tvs and dicts in binding positions, so they would shadow the original
+tvs and dicts. This is all resolvable with some plumbing, but it seems simpler
+just to keep the two wrappers distinct.
+
Note [Bind free vars]
~~~~~~~~~~~~~~~~~~~~~
The bind_fvs field of FunBind and PatBind records the free variables
@@ -548,10 +571,12 @@ ppr_monobind (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dictvars
pprLHsBinds val_binds
instance (OutputableBndr id) => Outputable (ABExport id) where
- ppr (ABE { abe_wrap = wrap, abe_poly = gbl, abe_mono = lcl, abe_prags = prags })
+ ppr (ABE { abe_wrap = wrap, abe_inst_wrap = inst_wrap
+ , abe_poly = gbl, abe_mono = lcl, abe_prags = prags })
= vcat [ ppr gbl <+> ptext (sLit "<=") <+> ppr lcl
, nest 2 (pprTcSpecPrags prags)
- , nest 2 (ppr wrap)]
+ , nest 2 (ppr wrap)
+ , nest 2 (ppr inst_wrap)]
instance (OutputableBndr idL, OutputableBndr idR) => Outputable (PatSynBind idL idR) where
ppr (PSB{ psb_id = L _ psyn, psb_args = details, psb_def = pat, psb_dir = dir })
diff --git a/compiler/hsSyn/HsExpr.hs b/compiler/hsSyn/HsExpr.hs
index 6e02df7438..158993eb2e 100644
--- a/compiler/hsSyn/HsExpr.hs
+++ b/compiler/hsSyn/HsExpr.hs
@@ -502,7 +502,14 @@ data HsExpr id
-- For details on above see note [Api annotations] in ApiAnnotation
| ELazyPat (LHsExpr id) -- ~ pattern
- | HsType (LHsType id) -- Explicit type argument; e.g f {| Int |} x y
+ -- | Use for type application in expressions.
+ -- 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnAt'
+
+ -- For details on above see note [Api annotations] in ApiAnnotation
+ | HsType (LHsWcType id) -- Explicit type argument; e.g f @Int x y
+ -- NB: Has wildcards, but no implicit quant.
+
+ | HsTypeOut (LHsWcType Name) -- just for pretty-printing
---------------------------------------
-- Finally, HsWrap appears only in typechecker output
@@ -762,7 +769,10 @@ ppr_expr (HsSCC _ (StringLiteral _ lbl) expr)
pprParendExpr expr ]
ppr_expr (HsWrap co_fn e) = pprHsWrapper (pprExpr e) co_fn
-ppr_expr (HsType id) = ppr id
+ppr_expr (HsType (HsWC { hswc_body = ty }))
+ = char '@' <> pprParendHsType (unLoc ty)
+ppr_expr (HsTypeOut (HsWC { hswc_body = ty }))
+ = char '@' <> pprParendHsType (unLoc ty)
ppr_expr (HsSpliceE s) = pprSplice s
ppr_expr (HsBracket b) = pprHsBracket b
@@ -864,6 +874,8 @@ hsExprNeedsParens (HsTcBracketOut {}) = False
hsExprNeedsParens (HsDo sc _ _)
| isListCompExpr sc = False
hsExprNeedsParens (HsRecFld{}) = False
+hsExprNeedsParens (HsType {}) = False
+hsExprNeedsParens (HsTypeOut {}) = False
hsExprNeedsParens _ = True
@@ -970,10 +982,10 @@ data HsCmd id
-- For details on above see note [Api annotations] in ApiAnnotation
- | HsCmdCast TcCoercionN -- A simpler version of HsWrap in HsExpr
+ | HsCmdWrap HsWrapper
(HsCmd id) -- If cmd :: arg1 --> res
- -- co :: arg1 ~ arg2
- -- Then (HsCmdCast co cmd) :: arg2 --> res
+ -- wrap :: arg1 "->" arg2
+ -- Then (HsCmdWrap wrap cmd) :: arg2 --> res
deriving (Typeable)
deriving instance (DataId id) => Data (HsCmd id)
@@ -1054,9 +1066,9 @@ ppr_cmd (HsCmdLet (L _ binds) cmd)
= sep [hang (ptext (sLit "let")) 2 (pprBinds binds),
hang (ptext (sLit "in")) 2 (ppr cmd)]
-ppr_cmd (HsCmdDo (L _ stmts) _) = pprDo ArrowExpr stmts
-ppr_cmd (HsCmdCast co cmd) = sep [ ppr_cmd cmd
- , ptext (sLit "|>") <+> ppr co ]
+ppr_cmd (HsCmdDo (L _ stmts) _) = pprDo ArrowExpr stmts
+
+ppr_cmd (HsCmdWrap w cmd) = pprHsWrapper (ppr_cmd cmd) w
ppr_cmd (HsCmdArrApp arrow arg _ HsFirstOrderApp True)
= hsep [ppr_lexpr arrow, larrowt, ppr_lexpr arg]
@@ -1186,6 +1198,13 @@ isInfixMatch match = case m_fixity match of
isEmptyMatchGroup :: MatchGroup id body -> Bool
isEmptyMatchGroup (MG { mg_alts = ms }) = null $ unLoc ms
+-- | Is there only one RHS in this group?
+isSingletonMatchGroup :: MatchGroup id body -> Bool
+isSingletonMatchGroup (MG { mg_alts = L _ [match] })
+ | L _ (Match { m_grhss = GRHSs { grhssGRHSs = [_] } }) <- match
+ = True
+isSingletonMatchGroup _ = False
+
matchGroupArity :: MatchGroup id body -> Arity
-- Precondition: MatchGroup is non-empty
-- This is called before type checking, when mg_arg_tys is not set
diff --git a/compiler/hsSyn/HsUtils.hs b/compiler/hsSyn/HsUtils.hs
index 9e8ea9af25..9576197b88 100644
--- a/compiler/hsSyn/HsUtils.hs
+++ b/compiler/hsSyn/HsUtils.hs
@@ -25,7 +25,7 @@ module HsUtils(
mkHsWrap, mkLHsWrap, mkHsWrapCo, mkHsWrapCoR, mkLHsWrapCo,
mkHsDictLet, mkHsLams,
mkHsOpApp, mkHsDo, mkHsComp, mkHsWrapPat, mkHsWrapPatCo,
- mkLHsPar, mkHsCmdCast,
+ mkLHsPar, mkHsCmdWrap, mkLHsCmdWrap, isLHsTypeExpr_maybe, isLHsTypeExpr,
nlHsTyApp, nlHsTyApps, nlHsVar, nlHsLit, nlHsApp, nlHsApps, nlHsIntLit, nlHsVarApps,
nlHsDo, nlHsOpApp, nlHsLam, nlHsPar, nlHsIf, nlHsCase, nlList,
@@ -445,6 +445,21 @@ nlHsFunTy a b = noLoc (HsFunTy a b)
nlHsTyConApp :: name -> [LHsType name] -> LHsType name
nlHsTyConApp tycon tys = foldl nlHsAppTy (nlHsTyVar tycon) tys
+-- | Extract a type argument from an HsExpr, with the list of wildcards in
+-- the type
+isLHsTypeExpr_maybe :: LHsExpr name -> Maybe (LHsWcType name)
+isLHsTypeExpr_maybe (L _ (HsPar e)) = isLHsTypeExpr_maybe e
+isLHsTypeExpr_maybe (L _ (HsType ty)) = Just ty
+ -- the HsTypeOut case is ill-typed. We never need it here anyway.
+isLHsTypeExpr_maybe _ = Nothing
+
+-- | Is an expression a visible type application?
+isLHsTypeExpr :: LHsExpr name -> Bool
+isLHsTypeExpr (L _ (HsPar e)) = isLHsTypeExpr e
+isLHsTypeExpr (L _ (HsType _)) = True
+isLHsTypeExpr (L _ (HsTypeOut _)) = True
+isLHsTypeExpr _ = False
+
{-
Tuples. All these functions are *pre-typechecker* because they lack
types on the tuple.
@@ -609,9 +624,12 @@ mkHsWrapCoR co e = mkHsWrap (mkWpCastR co) e
mkLHsWrapCo :: TcCoercionN -> LHsExpr id -> LHsExpr id
mkLHsWrapCo co (L loc e) = L loc (mkHsWrapCo co e)
-mkHsCmdCast :: TcCoercion -> HsCmd id -> HsCmd id
-mkHsCmdCast co cmd | isTcReflCo co = cmd
- | otherwise = HsCmdCast co cmd
+mkHsCmdWrap :: HsWrapper -> HsCmd id -> HsCmd id
+mkHsCmdWrap w cmd | isIdHsWrapper w = cmd
+ | otherwise = HsCmdWrap w cmd
+
+mkLHsCmdWrap :: HsWrapper -> LHsCmd id -> LHsCmd id
+mkLHsCmdWrap w (L loc c) = L loc (mkHsCmdWrap w c)
mkHsWrapPat :: HsWrapper -> Pat id -> Type -> Pat id
mkHsWrapPat co_fn p ty | isIdHsWrapper co_fn = p
diff --git a/compiler/hsSyn/PlaceHolder.hs b/compiler/hsSyn/PlaceHolder.hs
index 8e3b9a3402..004f465d76 100644
--- a/compiler/hsSyn/PlaceHolder.hs
+++ b/compiler/hsSyn/PlaceHolder.hs
@@ -15,9 +15,9 @@ import RdrName
import Var
import Coercion
import {-# SOURCE #-} ConLike (ConLike)
-import TcEvidence (HsWrapper)
import FieldLabel
import SrcLoc (Located)
+import TcEvidence ( HsWrapper )
import Data.Data hiding ( Fixity )
import BasicTypes (Fixity)
@@ -65,6 +65,9 @@ placeHolderNames = PlaceHolder
placeHolderNamesTc :: NameSet
placeHolderNamesTc = emptyNameSet
+placeHolderHsWrapper :: PlaceHolder
+placeHolderHsWrapper = PlaceHolder
+
{-
Note [Pass sensitive types]
diff --git a/compiler/iface/IfaceSyn.hs b/compiler/iface/IfaceSyn.hs
index 503653dd0e..6f26e231de 100644
--- a/compiler/iface/IfaceSyn.hs
+++ b/compiler/iface/IfaceSyn.hs
@@ -963,7 +963,7 @@ ppr_rough Nothing = dot
ppr_rough (Just tc) = ppr tc
tv_to_forall_bndr :: IfaceTvBndr -> IfaceForAllBndr
-tv_to_forall_bndr tv = IfaceTv tv Invisible
+tv_to_forall_bndr tv = IfaceTv tv Specified
{-
Note [Result type of a data family GADT]
diff --git a/compiler/iface/IfaceType.hs b/compiler/iface/IfaceType.hs
index 640d104b6a..154b7c46d8 100644
--- a/compiler/iface/IfaceType.hs
+++ b/compiler/iface/IfaceType.hs
@@ -696,8 +696,9 @@ pprIfaceForAll bndrs@(IfaceTv _ vis : _)
(bndrs', doc) = ppr_itv_bndrs bndrs vis
add_separator stuff = case vis of
- Invisible -> stuff <> dot
Visible -> stuff <+> arrow
+ _inv -> stuff <> dot
+
-- | Render the ... in @(forall ... .)@ or @(forall ... ->)@.
-- Returns both the list of not-yet-rendered binders and the doc.
@@ -705,9 +706,9 @@ pprIfaceForAll bndrs@(IfaceTv _ vis : _)
ppr_itv_bndrs :: [IfaceForAllBndr]
-> VisibilityFlag -- ^ visibility of the first binder in the list
-> ([IfaceForAllBndr], SDoc)
-ppr_itv_bndrs all_bndrs@(IfaceTv tv vis : bndrs) vis1
- | vis == vis1 = let (bndrs', doc) = ppr_itv_bndrs bndrs vis1 in
- (bndrs', pprIfaceTvBndr tv <+> doc)
+ppr_itv_bndrs all_bndrs@(bndr@(IfaceTv _ vis) : bndrs) vis1
+ | vis `sameVis` vis1 = let (bndrs', doc) = ppr_itv_bndrs bndrs vis1 in
+ (bndrs', pprIfaceForAllBndr bndr <+> doc)
| otherwise = (all_bndrs, empty)
ppr_itv_bndrs [] _ = ([], empty)
@@ -719,7 +720,11 @@ pprIfaceForAllCoBndrs :: [(IfLclName, IfaceCoercion)] -> SDoc
pprIfaceForAllCoBndrs bndrs = hsep $ map pprIfaceForAllCoBndr bndrs
pprIfaceForAllBndr :: IfaceForAllBndr -> SDoc
-pprIfaceForAllBndr (IfaceTv tv _) = pprIfaceTvBndr tv
+pprIfaceForAllBndr (IfaceTv tv Invisible) = sdocWithDynFlags $ \dflags ->
+ if gopt Opt_PrintExplicitForalls dflags
+ then braces $ pprIfaceTvBndr tv
+ else pprIfaceTvBndr tv
+pprIfaceForAllBndr (IfaceTv tv _) = pprIfaceTvBndr tv
pprIfaceForAllCoBndr :: (IfLclName, IfaceCoercion) -> SDoc
pprIfaceForAllCoBndr (tv, kind_co)
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 5efe8b3486..55260db67a 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -3210,6 +3210,7 @@ xFlags = [
flagSpec "TraditionalRecordSyntax" LangExt.TraditionalRecordSyntax,
flagSpec "TransformListComp" LangExt.TransformListComp,
flagSpec "TupleSections" LangExt.TupleSections,
+ flagSpec "TypeApplications" LangExt.TypeApplications,
flagSpec "TypeInType" LangExt.TypeInType,
flagSpec "TypeFamilies" LangExt.TypeFamilies,
flagSpec "TypeOperators" LangExt.TypeOperators,
@@ -3324,6 +3325,7 @@ impliedXFlags
, (LangExt.TemplateHaskell, turnOn, LangExt.TemplateHaskellQuotes)
, (LangExt.Strict, turnOn, LangExt.StrictData)
+ , (LangExt.TypeApplications, turnOn, LangExt.AllowAmbiguousTypes)
]
-- Note [Documenting optimisation flags]
diff --git a/compiler/main/PprTyThing.hs b/compiler/main/PprTyThing.hs
index 365a57c7b9..d55b5083ec 100644
--- a/compiler/main/PprTyThing.hs
+++ b/compiler/main/PprTyThing.hs
@@ -147,18 +147,10 @@ ppr_ty_thing hdr_only path ty_thing
-- Nothing is unexpected here; TyThings have External names
pprTypeForUser :: Type -> SDoc
--- We do two things here.
--- a) We tidy the type, regardless
--- b) Swizzle the foralls to the top, so that without
--- -fprint-explicit-foralls we'll suppress all the foralls
--- Prime example: a class op might have type
--- forall a. C a => forall b. Ord b => stuff
--- Then we want to display
--- (C a, Ord b) => stuff
+-- The type is tidied
pprTypeForUser ty
- = pprSigmaType (mkInvSigmaTy tvs ctxt tau)
+ = pprSigmaType tidy_ty
where
- (tvs, ctxt, tau) = tcSplitSigmaTy tidy_ty
(_, tidy_ty) = tidyOpenType emptyTidyEnv ty
-- Often the types/kinds we print in ghci are fully generalised
-- and have no free variables, but it turns out that we sometimes
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index cee8540c09..1bbbfbf20f 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -394,6 +394,14 @@ $tab { warnTab }
{ lex_qquasiquote_tok }
}
+ -- See Note [Lexing type applications]
+<0> {
+ [^ $idchar \) ] ^
+ "@"
+ / { ifExtension typeApplicationEnabled `alexAndPred` notFollowedBySymbol }
+ { token ITtypeApp }
+}
+
<0> {
"(|" / { ifExtension arrowsEnabled `alexAndPred` notFollowedBySymbol }
{ special IToparenbar }
@@ -507,6 +515,32 @@ $tab { warnTab }
\" { lex_string_tok }
}
+-- Note [Lexing type applications]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- The desired syntax for type applications is to prefix the type application
+-- with '@', like this:
+--
+-- foo @Int @Bool baz bum
+--
+-- This, of course, conflicts with as-patterns. The conflict arises because
+-- expressions and patterns use the same parser, and also because we want
+-- to allow type patterns within expression patterns.
+--
+-- Disambiguation is accomplished by requiring *something* to appear betwen
+-- type application and the preceding token. This something must end with
+-- a character that cannot be the end of the variable bound in an as-pattern.
+-- Currently (June 2015), this means that the something cannot end with a
+-- $idchar or a close-paren. (The close-paren is necessary if the as-bound
+-- identifier is symbolic.)
+--
+-- Note that looking for whitespace before the '@' is insufficient, because
+-- of this pathological case:
+--
+-- foo {- hi -}@Int
+--
+-- This design is predicated on the fact that as-patterns are generally
+-- whitespace-free, and also that this whole thing is opt-in, with the
+-- TypeApplications extension.
-- -----------------------------------------------------------------------------
-- Alex "Haskell code fragment bottom"
@@ -686,8 +720,13 @@ data Token
| ITLarrowtail IsUnicodeSyntax -- -<<
| ITRarrowtail IsUnicodeSyntax -- >>-
- | ITunknown String -- Used when the lexer can't make sense of it
- | ITeof -- end of file token
+ -- type application '@' (lexed differently than as-pattern '@',
+ -- due to checking for preceding whitespace)
+ | ITtypeApp
+
+
+ | ITunknown String -- Used when the lexer can't make sense of it
+ | ITeof -- end of file token
-- Documentation annotations
| ITdocCommentNext String -- something beginning '-- |'
@@ -2023,6 +2062,7 @@ data ExtBits
| LambdaCaseBit
| BinaryLiteralsBit
| NegativeLiteralsBit
+ | TypeApplicationsBit
deriving Enum
@@ -2083,6 +2123,8 @@ negativeLiteralsEnabled :: ExtsBitmap -> Bool
negativeLiteralsEnabled = xtest NegativeLiteralsBit
patternSynonymsEnabled :: ExtsBitmap -> Bool
patternSynonymsEnabled = xtest PatternSynonymsBit
+typeApplicationEnabled :: ExtsBitmap -> Bool
+typeApplicationEnabled = xtest TypeApplicationsBit
-- PState for parsing options pragmas
--
@@ -2153,6 +2195,8 @@ mkPState flags buf loc =
.|. BinaryLiteralsBit `setBitIf` xopt LangExt.BinaryLiterals flags
.|. NegativeLiteralsBit `setBitIf` xopt LangExt.NegativeLiterals flags
.|. PatternSynonymsBit `setBitIf` xopt LangExt.PatternSynonyms flags
+ .|. TypeApplicationsBit `setBitIf` xopt LangExt.TypeApplications flags
+
--
setBitIf :: ExtBits -> Bool -> ExtsBitmap
b `setBitIf` cond | cond = xbit b
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index ead81ac337..11dc84f0a6 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -414,6 +414,7 @@ output it generates.
'-<<' { L _ (ITLarrowtail _) } -- for arrow notation
'>>-' { L _ (ITRarrowtail _) } -- for arrow notation
'.' { L _ ITdot }
+ TYPEAPP { L _ ITtypeApp }
'{' { L _ ITocurly } -- special symbols
'}' { L _ ITccurly }
@@ -2237,7 +2238,11 @@ fexp :: { LHsExpr RdrName }
aexp :: { LHsExpr RdrName }
: qvar '@' aexp {% ams (sLL $1 $> $ EAsPat $1 $3) [mj AnnAt $2] }
+ -- If you change the parsing, make sure to understand
+ -- Note [Lexing type applications] in Lexer.x
+
| '~' aexp {% ams (sLL $1 $> $ ELazyPat $2) [mj AnnTilde $1] }
+ | TYPEAPP atype {% ams (sLL $1 $> $ HsType (mkHsWildCardBndrs $2)) [mj AnnAt $1] }
| aexp1 { $1 }
aexp1 :: { LHsExpr RdrName }
@@ -2954,6 +2959,10 @@ var :: { Located RdrName }
| '(' varsym ')' {% ams (sLL $1 $> (unLoc $2))
[mop $1,mj AnnVal $2,mcp $3] }
+ -- Lexing type applications depends subtly on what characters can possibly
+ -- end a qvar. Currently (June 2015), only $idchars and ")" can end a qvar.
+ -- If you're changing this, please see Note [Lexing type applications] in
+ -- Lexer.x.
qvar :: { Located RdrName }
: qvarid { $1 }
| '(' varsym ')' {% ams (sLL $1 $> (unLoc $2))
diff --git a/compiler/prelude/PrimOp.hs b/compiler/prelude/PrimOp.hs
index 67a44cc462..66172acd24 100644
--- a/compiler/prelude/PrimOp.hs
+++ b/compiler/prelude/PrimOp.hs
@@ -536,7 +536,7 @@ primOpType op
Compare _occ ty -> compare_fun_ty ty
GenPrimOp _occ tyvars arg_tys res_ty ->
- mkInvForAllTys tyvars (mkFunTys arg_tys res_ty)
+ mkSpecForAllTys tyvars (mkFunTys arg_tys res_ty)
primOpOcc :: PrimOp -> OccName
primOpOcc op = case primOpInfo op of
diff --git a/compiler/prelude/TysPrim.hs b/compiler/prelude/TysPrim.hs
index a4715df0a6..14505850fd 100644
--- a/compiler/prelude/TysPrim.hs
+++ b/compiler/prelude/TysPrim.hs
@@ -648,7 +648,7 @@ mkProxyPrimTy k ty = TyConApp proxyPrimTyCon [k, ty]
proxyPrimTyCon :: TyCon
proxyPrimTyCon = mkPrimTyCon proxyPrimTyConName kind [Nominal,Nominal] VoidRep
- where kind = ForAllTy (Named kv Invisible) $
+ where kind = ForAllTy (Named kv Specified) $
mkFunTy k unliftedTypeKind
kv = kKiVar
k = mkTyVarTy kv
@@ -664,8 +664,8 @@ proxyPrimTyCon = mkPrimTyCon proxyPrimTyConName kind [Nominal,Nominal] VoidRep
eqPrimTyCon :: TyCon -- The representation type for equality predicates
-- See Note [The equality types story]
eqPrimTyCon = mkPrimTyCon eqPrimTyConName kind roles VoidRep
- where kind = ForAllTy (Named kv1 Invisible) $
- ForAllTy (Named kv2 Invisible) $
+ where kind = ForAllTy (Named kv1 Specified) $
+ ForAllTy (Named kv2 Specified) $
mkFunTys [k1, k2] unliftedTypeKind
[kv1, kv2] = mkTemplateTyVars [liftedTypeKind, liftedTypeKind]
k1 = mkTyVarTy kv1
@@ -678,8 +678,8 @@ eqPrimTyCon = mkPrimTyCon eqPrimTyConName kind roles VoidRep
eqReprPrimTyCon :: TyCon -- See Note [The equality types story]
eqReprPrimTyCon = mkPrimTyCon eqReprPrimTyConName kind
roles VoidRep
- where kind = ForAllTy (Named kv1 Invisible) $
- ForAllTy (Named kv2 Invisible) $
+ where kind = ForAllTy (Named kv1 Specified) $
+ ForAllTy (Named kv2 Specified) $
mkFunTys [k1, k2] unliftedTypeKind
[kv1, kv2] = mkTemplateTyVars [liftedTypeKind, liftedTypeKind]
k1 = mkTyVarTy kv1
@@ -693,8 +693,8 @@ eqPhantPrimTyCon :: TyCon
eqPhantPrimTyCon = mkPrimTyCon eqPhantPrimTyConName kind
[Nominal, Nominal, Phantom, Phantom]
VoidRep
- where kind = ForAllTy (Named kv1 Invisible) $
- ForAllTy (Named kv2 Invisible) $
+ where kind = ForAllTy (Named kv1 Specified) $
+ ForAllTy (Named kv2 Specified) $
mkFunTys [k1, k2] unliftedTypeKind
[kv1, kv2] = mkTemplateTyVars [liftedTypeKind, liftedTypeKind]
k1 = mkTyVarTy kv1
@@ -925,7 +925,7 @@ anyTyCon = mkFamilyTyCon anyTyConName kind [kKiVar] Nothing
Nothing
NotInjective
where
- kind = ForAllTy (Named kKiVar Invisible) (mkTyVarTy kKiVar)
+ kind = ForAllTy (Named kKiVar Specified) (mkTyVarTy kKiVar)
anyTypeOfKind :: Kind -> Type
anyTypeOfKind kind = TyConApp anyTyCon [kind]
diff --git a/compiler/prelude/TysWiredIn.hs b/compiler/prelude/TysWiredIn.hs
index 3c3eab66bf..02e693d5a0 100644
--- a/compiler/prelude/TysWiredIn.hs
+++ b/compiler/prelude/TysWiredIn.hs
@@ -573,7 +573,7 @@ mk_tuple boxity arity = (tycon, tuple_con)
in
( UnboxedTuple
, gHC_PRIM
- , mkInvForAllTys lev_tvs $
+ , mkSpecForAllTys lev_tvs $
mkFunTys (map tyVarKind open_tvs) $
unliftedTypeKind
, arity * 2
@@ -633,7 +633,7 @@ heqSCSelId, coercibleSCSelId :: Id
klass = mkClass tvs [] [sc_pred] [sc_sel_id] [] [] (mkAnd []) tycon
datacon = pcDataCon heqDataConName tvs [sc_pred] tycon
- kind = mkInvForAllTys [kv1, kv2] $ mkFunTys [k1, k2] constraintKind
+ kind = mkSpecForAllTys [kv1, kv2] $ mkFunTys [k1, k2] constraintKind
kv1:kv2:_ = drop 9 alphaTyVars -- gets "j" and "k"
k1 = mkTyVarTy kv1
k2 = mkTyVarTy kv2
@@ -654,7 +654,7 @@ heqSCSelId, coercibleSCSelId :: Id
klass = mkClass tvs [] [sc_pred] [sc_sel_id] [] [] (mkAnd []) tycon
datacon = pcDataCon coercibleDataConName tvs [sc_pred] tycon
- kind = mkInvForAllTys [kKiVar] $ mkFunTys [k, k] constraintKind
+ kind = mkSpecForAllTys [kKiVar] $ mkFunTys [k, k] constraintKind
k = mkTyVarTy kKiVar
[av,bv] = mkTemplateTyVars [k, k]
tvs = [kKiVar, av, bv]
diff --git a/compiler/rename/RnExpr.hs b/compiler/rename/RnExpr.hs
index c4e5bb2abe..03f4b62043 100644
--- a/compiler/rename/RnExpr.hs
+++ b/compiler/rename/RnExpr.hs
@@ -298,9 +298,9 @@ rnExpr (HsMultiIf _ty alts)
-- ; return (HsMultiIf ty alts', fvs) }
; return (HsMultiIf placeHolderType alts', fvs) }
-rnExpr (HsType a)
- = do { (t, fvT) <- rnLHsType HsTypeCtx a
- ; return (HsType t, fvT) }
+rnExpr (HsType ty)
+ = do { (ty', fvT) <- rnHsWcType HsTypeCtx ty
+ ; return (HsType ty', fvT) }
rnExpr (ArithSeq _ _ seq)
= do { opt_OverloadedLists <- xoptM LangExt.OverloadedLists
@@ -524,7 +524,7 @@ rnCmd (HsCmdDo (L l stmts) _)
rnStmts ArrowExpr rnLCmd stmts (\ _ -> return ((), emptyFVs))
; return ( HsCmdDo (L l stmts') placeHolderType, fvs ) }
-rnCmd cmd@(HsCmdCast {}) = pprPanic "rnCmd" (ppr cmd)
+rnCmd cmd@(HsCmdWrap {}) = pprPanic "rnCmd" (ppr cmd)
---------------------------------------------------
type CmdNeeds = FreeVars -- Only inhabitants are
@@ -541,7 +541,7 @@ methodNamesCmd (HsCmdArrApp _arrow _arg _ HsFirstOrderApp _rtl)
methodNamesCmd (HsCmdArrApp _arrow _arg _ HsHigherOrderApp _rtl)
= unitFV appAName
methodNamesCmd (HsCmdArrForm {}) = emptyFVs
-methodNamesCmd (HsCmdCast _ cmd) = methodNamesCmd cmd
+methodNamesCmd (HsCmdWrap _ cmd) = methodNamesCmd cmd
methodNamesCmd (HsCmdPar c) = methodNamesLCmd c
@@ -1819,7 +1819,8 @@ sectionErr expr
patSynErr :: HsExpr RdrName -> RnM (HsExpr Name, FreeVars)
patSynErr e = do { addErr (sep [ptext (sLit "Pattern syntax in expression context:"),
- nest 4 (ppr e)])
+ nest 4 (ppr e)] $$
+ text "Did you mean to enable TypeApplications?")
; return (EWildPat, emptyFVs) }
badIpBinds :: Outputable a => SDoc -> a -> SDoc
diff --git a/compiler/rename/RnSplice.hs b/compiler/rename/RnSplice.hs
index 8f87d730d8..9ddf132311 100644
--- a/compiler/rename/RnSplice.hs
+++ b/compiler/rename/RnSplice.hs
@@ -45,7 +45,7 @@ import Var ( Id )
import THNames ( quoteExpName, quotePatName, quoteDecName, quoteTypeName
, decsQTyConName, expQTyConName, patQTyConName, typeQTyConName, )
-import {-# SOURCE #-} TcExpr ( tcMonoExpr )
+import {-# SOURCE #-} TcExpr ( tcPolyExpr )
import {-# SOURCE #-} TcSplice ( runMetaD, runMetaE, runMetaP, runMetaT, tcTopSpliceExpr )
#endif
@@ -295,7 +295,7 @@ runRnSplice flavour run_meta ppr_res splice
-- Typecheck the expression
; meta_exp_ty <- tcMetaTy meta_ty_name
; zonked_q_expr <- tcTopSpliceExpr Untyped $
- tcMonoExpr the_expr meta_exp_ty
+ tcPolyExpr the_expr meta_exp_ty
-- Run the expression
; result <- run_meta zonked_q_expr
diff --git a/compiler/rename/RnTypes.hs b/compiler/rename/RnTypes.hs
index 52a164f105..5a58148170 100644
--- a/compiler/rename/RnTypes.hs
+++ b/compiler/rename/RnTypes.hs
@@ -751,7 +751,7 @@ checkExtraConstraintWildCard env wc
= checkWildCard env mb_bad
where
mb_bad | not (extraConstraintWildCardsAllowed env)
- = Just (ptext (sLit "Extra-contraint wildcard") <+> quotes (ppr wc)
+ = Just (ptext (sLit "Extra-constraint wildcard") <+> quotes (ppr wc)
<+> ptext (sLit "not allowed"))
| otherwise
= Nothing
@@ -774,6 +774,7 @@ wildCardsAllowed env
RuleCtx {} -> True
FamPatCtx {} -> True -- Not named wildcards though
GHCiCtx {} -> True
+ HsTypeCtx {} -> True
_ -> False
rnAnonWildCard :: HsWildCardInfo RdrName -> RnM (HsWildCardInfo Name)
diff --git a/compiler/typecheck/Inst.hs b/compiler/typecheck/Inst.hs
index 22f16b1f35..8878ba6b46 100644
--- a/compiler/typecheck/Inst.hs
+++ b/compiler/typecheck/Inst.hs
@@ -6,14 +6,15 @@
The @Inst@ type: dictionaries or method instances
-}
-{-# LANGUAGE CPP, MultiWayIf #-}
+{-# LANGUAGE CPP, MultiWayIf, TupleSections #-}
module Inst (
- deeplySkolemise, deeplyInstantiate,
+ deeplySkolemise,
+ topInstantiate, topInstantiateInferred, deeplyInstantiate,
instCall, instDFunType, instStupidTheta,
newWanted, newWanteds,
- newOverloadedLit, mkOverLit,
+ newOverloadedLit, newNonTrivialOverloadedLit, mkOverLit,
newClsInst,
tcGetInsts, tcGetInstEnvs, getOverlapFlag,
@@ -149,6 +150,65 @@ deeplySkolemise ty
| otherwise
= return (idHsWrapper, [], [], ty)
+-- | Instantiate all outer type variables
+-- and any context. Never looks through arrows.
+topInstantiate :: CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcRhoType)
+-- if topInstantiate ty = (wrap, rho)
+-- and e :: ty
+-- then wrap e :: rho
+topInstantiate = top_instantiate True
+
+-- | Instantiate all outer 'Invisible' binders
+-- and any context. Never looks through arrows or specified type variables.
+-- Used for visible type application.
+topInstantiateInferred :: CtOrigin -> TcSigmaType
+ -> TcM (HsWrapper, TcSigmaType)
+-- if topInstantiate ty = (wrap, rho)
+-- and e :: ty
+-- then wrap e :: rho
+topInstantiateInferred = top_instantiate False
+
+top_instantiate :: Bool -- True <=> instantiate *all* variables
+ -> CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcRhoType)
+top_instantiate inst_all orig ty
+ | not (null binders && null theta)
+ = do { let (inst_bndrs, leave_bndrs) = span should_inst binders
+ (inst_theta, leave_theta)
+ | null leave_bndrs = (theta, [])
+ | otherwise = ([], theta)
+ ; (subst, inst_tvs') <- newMetaTyVars (map (binderVar "top_inst") inst_bndrs)
+ ; let inst_theta' = substTheta subst inst_theta
+ sigma' = substTy subst (mkForAllTys leave_bndrs $
+ mkFunTys leave_theta rho)
+
+ ; wrap1 <- instCall orig (mkTyVarTys inst_tvs') inst_theta'
+ ; traceTc "Instantiating"
+ (vcat [ text "all tyvars?" <+> ppr inst_all
+ , text "origin" <+> pprCtOrigin orig
+ , text "type" <+> ppr ty
+ , text "with" <+> ppr inst_tvs'
+ , text "theta:" <+> ppr inst_theta' ])
+
+ ; (wrap2, rho2) <-
+ if null leave_bndrs
+
+ -- account for types like forall a. Num a => forall b. Ord b => ...
+ then top_instantiate inst_all orig sigma'
+
+ -- but don't loop if there were any un-inst'able tyvars
+ else return (idHsWrapper, sigma')
+
+ ; return (wrap2 <.> wrap1, rho2) }
+
+ | otherwise = return (idHsWrapper, ty)
+ where
+ (binders, phi) = tcSplitNamedPiTys ty
+ (theta, rho) = tcSplitPhiTy phi
+
+ should_inst bndr
+ | inst_all = True
+ | otherwise = binderVisibility bndr == Invisible
+
deeplyInstantiate :: CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcRhoType)
-- Int -> forall a. a -> a ==> (\x:Int. [] x alpha) :: Int -> alpha
-- In general if
@@ -176,6 +236,7 @@ deeplyInstantiate orig ty
| otherwise = return (idHsWrapper, ty)
+
{-
************************************************************************
* *
@@ -269,39 +330,54 @@ instStupidTheta orig theta
* *
************************************************************************
+-}
+
+{-
In newOverloadedLit we convert directly to an Int or Integer if we
know that's what we want. This may save some time, by not
temporarily generating overloaded literals, but it won't catch all
cases (the rest are caught in lookupInst).
--}
-newOverloadedLit :: CtOrigin
- -> HsOverLit Name
- -> TcRhoType
- -> TcM (HsOverLit TcId)
-newOverloadedLit orig lit res_ty
- = do dflags <- getDynFlags
- newOverloadedLit' dflags orig lit res_ty
-
-newOverloadedLit' :: DynFlags
- -> CtOrigin
- -> HsOverLit Name
- -> TcRhoType
- -> TcM (HsOverLit TcId)
-newOverloadedLit' dflags orig
- lit@(OverLit { ol_val = val, ol_rebindable = rebindable
- , ol_witness = meth_name }) res_ty
+-}
+newOverloadedLit :: HsOverLit Name
+ -> TcSigmaType -- if nec'y, this type is instantiated...
+ -> CtOrigin -- ... using this CtOrigin
+ -> TcM (HsWrapper, HsOverLit TcId)
+ -- wrapper :: input type "->" type of result
+newOverloadedLit
+ lit@(OverLit { ol_val = val, ol_rebindable = rebindable }) res_ty res_orig
| not rebindable
- , Just expr <- shortCutLit dflags val res_ty
+ -- all built-in overloaded lits are not higher-rank, so skolemise.
+ -- this is necessary for shortCutLit.
+ = do { (wrap, insted_ty) <- deeplyInstantiate res_orig res_ty
+ ; dflags <- getDynFlags
+ ; case shortCutLit dflags val insted_ty of
-- Do not generate a LitInst for rebindable syntax.
-- Reason: If we do, tcSimplify will call lookupInst, which
-- will call tcSyntaxName, which does unification,
-- which tcSimplify doesn't like
- = return (lit { ol_witness = expr, ol_type = res_ty
- , ol_rebindable = rebindable })
+ Just expr -> return ( wrap
+ , lit { ol_witness = expr, ol_type = insted_ty
+ , ol_rebindable = False } )
+ Nothing -> (wrap, ) <$>
+ newNonTrivialOverloadedLit orig lit insted_ty }
| otherwise
+ = do { lit' <- newNonTrivialOverloadedLit orig lit res_ty
+ ; return (idHsWrapper, lit') }
+ where
+ orig = LiteralOrigin lit
+
+-- Does not handle things that 'shortCutLit' can handle. See also
+-- newOverloadedLit in TcUnify
+newNonTrivialOverloadedLit :: CtOrigin
+ -> HsOverLit Name
+ -> TcSigmaType
+ -> TcM (HsOverLit TcId)
+newNonTrivialOverloadedLit orig
+ lit@(OverLit { ol_val = val, ol_witness = meth_name
+ , ol_rebindable = rebindable }) res_ty
= do { hs_lit <- mkOverLit val
; let lit_ty = hsLitType hs_lit
; fi' <- tcSyntaxOp orig meth_name (mkFunTy lit_ty res_ty)
@@ -310,8 +386,8 @@ newOverloadedLit' dflags orig
-- whereas res_ty might be openTypeKind. This was a bug in 6.2.2
-- However this'll be picked up by tcSyntaxOp if necessary
; let witness = HsApp (noLoc fi') (noLoc (HsLit hs_lit))
- ; return (lit { ol_witness = witness, ol_type = res_ty
- , ol_rebindable = rebindable }) }
+ ; return (lit { ol_witness = witness, ol_type = res_ty,
+ ol_rebindable = rebindable }) }
------------
mkOverLit :: OverLitVal -> TcM HsLit
diff --git a/compiler/typecheck/TcArrows.hs b/compiler/typecheck/TcArrows.hs
index 444b148fbc..dac6aedadf 100644
--- a/compiler/typecheck/TcArrows.hs
+++ b/compiler/typecheck/TcArrows.hs
@@ -5,7 +5,7 @@
Typecheck arrow notation
-}
-{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE RankNTypes, TupleSections #-}
module TcArrows ( tcProc ) where
@@ -250,7 +250,7 @@ tc_cmd env
arg_tys = map hsLPatType pats'
cmd' = HsCmdLam (MG { mg_alts = L l [match'], mg_arg_tys = arg_tys
, mg_res_ty = res_ty, mg_origin = origin })
- ; return (mkHsCmdCast co cmd') }
+ ; return (mkHsCmdWrap (mkWpCastN co) cmd') }
where
n_pats = length pats
match_ctxt = (LambdaExpr :: HsMatchContext Name) -- Maybe KappaExpr?
@@ -272,7 +272,7 @@ tc_cmd env
tc_cmd env (HsCmdDo (L l stmts) _) (cmd_stk, res_ty)
= do { co <- unifyType noThing unitTy cmd_stk -- Expecting empty argument stack
; stmts' <- tcStmts ArrowExpr (tcArrDoStmt env) stmts res_ty
- ; return (mkHsCmdCast co (HsCmdDo (L l stmts') res_ty)) }
+ ; return (mkHsCmdWrap (mkWpCastN co) (HsCmdDo (L l stmts') res_ty)) }
-----------------------------------------------------------------
diff --git a/compiler/typecheck/TcBinds.hs b/compiler/typecheck/TcBinds.hs
index 83f2eb98b1..113a5613c3 100644
--- a/compiler/typecheck/TcBinds.hs
+++ b/compiler/typecheck/TcBinds.hs
@@ -15,7 +15,7 @@ module TcBinds ( tcLocalBinds, tcTopBinds, tcRecSelBinds,
TcPragEnv, mkPragEnv,
tcUserTypeSig, instTcTySig, chooseInferredQuantifiers,
instTcTySigFromId, tcExtendTyVarEnvFromSig,
- badBootDeclErr, mkExport ) where
+ badBootDeclErr ) where
import {-# SOURCE #-} TcMatches ( tcGRHSsPat, tcMatchesFun )
import {-# SOURCE #-} TcExpr ( tcMonoExpr )
@@ -32,7 +32,7 @@ import TcEvidence
import TcHsType
import TcPat
import TcMType
-import Inst( deeplyInstantiate )
+import Inst( topInstantiate, deeplyInstantiate )
import FamInstEnv( normaliseType )
import FamInst( tcGetFamInstEnvs )
import TyCon
@@ -556,7 +556,7 @@ tcPolyNoGen rec_tc prag_fn tc_sig_fn bind_list
; mono_ids' <- mapM tc_mono_info mono_infos
; return (binds', mono_ids') }
where
- tc_mono_info (name, _, mono_id)
+ tc_mono_info (MBI { mbi_poly_name = name, mbi_mono_id = mono_id })
= do { mono_ty' <- zonkTcType (idType mono_id)
-- Zonk, mainly to expose unboxed types to checkStrictBinds
; let mono_id' = setIdType mono_id mono_ty'
@@ -601,11 +601,11 @@ tcPolyCheck rec_tc prag_fn
; spec_prags <- tcSpecPrags poly_id prag_sigs
; poly_id <- addInlinePrags poly_id prag_sigs
- ; let (_, _, mono_id) = mono_info
- export = ABE { abe_wrap = idHsWrapper
- , abe_poly = poly_id
- , abe_mono = mono_id
- , abe_prags = SpecPrags spec_prags }
+ ; let export = ABE { abe_wrap = idHsWrapper
+ , abe_inst_wrap = idHsWrapper
+ , abe_poly = poly_id
+ , abe_mono = mbi_mono_id mono_info
+ , abe_prags = SpecPrags spec_prags }
abs_bind = L loc $ AbsBinds
{ abs_tvs = skol_tvs
, abs_ev_vars = ev_vars, abs_ev_binds = [ev_binds]
@@ -616,6 +616,54 @@ tcPolyCheck _rec_tc _prag_fn sig _bind
= pprPanic "tcPolyCheck" (ppr sig)
------------------
+{-
+Note [Instantiate when inferring a type]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider
+ f = (*)
+As there is no incentive to instantiate the RHS, tcMonoBinds will
+produce a type of forall a. Num a => a -> a -> a for `f`. This will then go
+through simplifyInfer and such, remaining unchanged.
+
+There are two problems with this:
+ 1) If the definition were `g _ = (*)`, we get a very unusual type of
+ `forall {a}. a -> forall b. Num b => b -> b -> b` for `g`. This is
+ surely confusing for users.
+
+ 2) The monomorphism restriction can't work. The MR is dealt with in
+ simplifyInfer, and simplifyInfer has no way of instantiating. This
+ could perhaps be worked around, but it may be hard to know even
+ when instantiation should happen.
+
+There is an easy solution to all three problems: instantiate (deeply) when
+inferring a type. So that's what we do. Note that this decision is
+user-facing.
+
+Here are the details:
+ * tcMonoBinds produces the "monomorphic" ids to be put in the AbsBinds.
+ It is inconvenient to instantiate in this function or below. So the
+ monomorphic ids will be uninstantiated (and hence actually polymorphic,
+ but that doesn't ruin anyone's day).
+
+ * In the same captureConstraints as the tcMonoBinds, we instantiate all
+ the types of the monomorphic ids. Instantiating will produce constraints
+ to solve and instantiated types. These constraints and the instantiated
+ types go into simplifyInfer. HsWrappers are produced that go from
+ the "mono" types to the instantiated ones.
+
+ * simplifyInfer does its magic, figuring out how to regeneralize.
+
+ * mkExport then does the impedence matching and needs to connect the
+ monomorphic ids to the polymorphic types as decided by simplifyInfer.
+ Because the instantiation happens before simplifyInfer, we also pass in
+ the HsWrappers obtained via instantiating so that mkExport can connect
+ all the pieces.
+
+ * We produce an AbsBinds with the right (instantiated and then, perhaps,
+ regeneralized) polytypes and the not-yet-instantiated "monomorphic" ids,
+ using the built HsWrappers to connect. Done!
+-}
+
tcPolyInfer
:: RecFlag -- Whether it's recursive after breaking
-- dependencies based on type signatures
@@ -624,19 +672,36 @@ tcPolyInfer
-> [LHsBind Name]
-> TcM (LHsBinds TcId, [TcId])
tcPolyInfer rec_tc prag_fn tc_sig_fn mono bind_list
- = do { (tclvl, wanted, (binds', mono_infos))
+ = do { (tclvl, wanted, (binds', mono_infos, wrappers, insted_tys))
<- pushLevelAndCaptureConstraints $
- tcMonoBinds rec_tc tc_sig_fn LetLclBndr bind_list
+ do { (binds', mono_infos)
+ <- tcMonoBinds rec_tc tc_sig_fn LetLclBndr bind_list
+ -- See Note [Instantiate when inferring a type]
+ ; traceTc "Note [Instantiate when inferring a type]" $
+ vcat (map (pprBndr LetBind . mbi_mono_id) mono_infos)
+ ; (wrappers, insted_tys)
+ <- tcExtendIdBndrs
+ [ TcIdBndr mono_id NotTopLevel
+ | MBI { mbi_mono_id = mono_id } <- mono_infos ] $
+ mapAndUnzipM deeply_instantiate mono_infos
+ -- during instantiation, we might encounter an error
+ -- whose message will want to list these binders as
+ -- relevant.
+
+ ; return (binds', mono_infos, wrappers, insted_tys) }
+
+ ; let name_taus = [ (mbi_poly_name info, tau)
+ | (info, tau) <- zip mono_infos insted_tys]
+ sigs = [ sig | MBI { mbi_sig = Just sig } <- mono_infos ]
- ; let name_taus = [(name, idType mono_id) | (name, _, mono_id) <- mono_infos]
- sigs = [ sig | (_, Just sig, _) <- mono_infos ]
; traceTc "simplifyInfer call" (ppr tclvl $$ ppr name_taus $$ ppr wanted)
; (qtvs, givens, ev_binds)
<- simplifyInfer tclvl mono sigs name_taus wanted
; let inferred_theta = map evVarPred givens
; exports <- checkNoErrs $
- mapM (mkExport prag_fn qtvs inferred_theta) mono_infos
+ zipWith3M (mkExport prag_fn qtvs inferred_theta)
+ mono_infos wrappers insted_tys
; loc <- getSrcSpanM
; let poly_ids = map abe_poly exports
@@ -649,12 +714,23 @@ tcPolyInfer rec_tc prag_fn tc_sig_fn mono bind_list
; return (unitBag abs_bind, poly_ids) }
-- poly_ids are guaranteed zonked by mkExport
+ where
+ deeply_instantiate :: MonoBindInfo -> TcM (HsWrapper, TcRhoType)
+ deeply_instantiate (MBI { mbi_mono_id = mono_id, mbi_orig = orig })
+ = do { mono_ty <- zonkTcType (idType mono_id)
+ -- NB: zonk to uncover any foralls
+ ; addErrCtxtM (instErrCtxt mono_id mono_ty) $
+ deeplyInstantiate orig mono_ty }
+
--------------
mkExport :: TcPragEnv
-> [TyVar] -> TcThetaType -- Both already zonked
-> MonoBindInfo
+ -> HsWrapper -- the instantiation wrapper;
+ -- see Note [Instantiate when inferring a type]
+ -> TcTauType -- the instantiated type
-> TcM (ABExport Id)
--- Only called for generalisation plan IferGen, not by CheckGen or NoGen
+-- Only called for generalisation plan InferGen, not by CheckGen or NoGen
--
-- mkExport generates exports with
-- zonked type variables,
@@ -667,14 +743,19 @@ mkExport :: TcPragEnv
-- Pre-condition: the qtvs and theta are already zonked
-mkExport prag_fn qtvs theta mono_info@(poly_name, mb_sig, mono_id)
- = do { mono_ty <- zonkTcType (idType mono_id)
+mkExport prag_fn qtvs theta
+ mono_info@(MBI { mbi_poly_name = poly_name
+ , mbi_sig = mb_sig
+ , mbi_mono_id = mono_id })
+ inst_wrap inst_ty
+ = do { inst_ty <- zonkTcType inst_ty
+
; poly_id <- case mb_sig of
Just sig | Just poly_id <- completeIdSigPolyId_maybe sig
-> return poly_id
_other -> checkNoErrs $
mkInferredPolyId qtvs theta
- poly_name mb_sig mono_ty
+ poly_name mb_sig inst_ty
-- The checkNoErrs ensures that if the type is ambiguous
-- we don't carry on to the impedence matching, and generate
-- a duplicate ambiguity error. There is a similar
@@ -688,9 +769,12 @@ mkExport prag_fn qtvs theta mono_info@(poly_name, mb_sig, mono_id)
-- See Note [Impedence matching]
-- NB: we have already done checkValidType, including an ambiguity check,
-- on the type; either when we checked the sig or in mkInferredPolyId
- ; let sel_poly_ty = mkInvSigmaTy qtvs theta mono_ty
+ ; let sel_poly_ty = mkInvSigmaTy qtvs theta inst_ty
+ -- this type is just going into tcSubType, so Inv vs. Spec doesn't
+ -- matter
+
poly_ty = idType poly_id
- ; wrap <- if sel_poly_ty `eqType` poly_ty
+ ; wrap <- if sel_poly_ty `eqType` poly_ty -- NB: eqType ignores visibility
then return idHsWrapper -- Fast path; also avoids complaint when we infer
-- an ambiguouse type and have AllowAmbiguousType
-- e..g infer x :: forall a. F a -> Int
@@ -701,7 +785,8 @@ mkExport prag_fn qtvs theta mono_info@(poly_name, mb_sig, mono_id)
; when warn_missing_sigs $ localSigWarn poly_id mb_sig
; return (ABE { abe_wrap = wrap
- -- abe_wrap :: idType poly_id ~ (forall qtvs. theta => mono_ty)
+ -- abe_wrap :: idType poly_id ~ (forall qtvs. theta => inst_ty)
+ , abe_inst_wrap = inst_wrap
, abe_poly = poly_id
, abe_mono = mono_id
, abe_prags = SpecPrags spec_prags}) }
@@ -724,13 +809,12 @@ mkInferredPolyId qtvs inferred_theta poly_name mb_sig mono_ty
-- We can discard the coercion _co, because we'll reconstruct
-- it in the call to tcSubType below
- ; (my_tvs, theta') <- chooseInferredQuantifiers
- inferred_theta (tyCoVarsOfType mono_ty') mb_sig
+ ; (binders, theta') <- chooseInferredQuantifiers inferred_theta
+ (tyCoVarsOfType mono_ty') qtvs mb_sig
- ; let qtvs' = filter (`elemVarSet` my_tvs) qtvs -- Maintain original order
- inferred_poly_ty = mkInvSigmaTy qtvs' theta' mono_ty'
+ ; let inferred_poly_ty = mkForAllTys binders (mkPhiTy theta' mono_ty')
- ; traceTc "mkInferredPolyId" (vcat [ppr poly_name, ppr qtvs, ppr my_tvs, ppr theta'
+ ; traceTc "mkInferredPolyId" (vcat [ppr poly_name, ppr qtvs, ppr theta'
, ppr inferred_poly_ty])
; addErrCtxtM (mk_inf_msg poly_name inferred_poly_ty) $
checkValidType (InfSigCtxt poly_name) inferred_poly_ty
@@ -739,25 +823,32 @@ mkInferredPolyId qtvs inferred_theta poly_name mb_sig mono_ty
; return (mkLocalIdOrCoVar poly_name inferred_poly_ty) }
-chooseInferredQuantifiers :: TcThetaType -> TcTyVarSet -> Maybe TcIdSigInfo
- -> TcM (TcTyVarSet, TcThetaType)
-chooseInferredQuantifiers inferred_theta tau_tvs Nothing
+chooseInferredQuantifiers :: TcThetaType -- inferred
+ -> TcTyVarSet -- tvs free in tau type
+ -> [TcTyVar] -- inferred quantified tvs
+ -> Maybe TcIdSigInfo
+ -> TcM ([TcTyBinder], TcThetaType)
+chooseInferredQuantifiers inferred_theta tau_tvs qtvs Nothing
= do { let free_tvs = closeOverKinds (growThetaTyVars inferred_theta tau_tvs)
-- Include kind variables! Trac #7916
my_theta = pickQuantifiablePreds free_tvs inferred_theta
- ; return (free_tvs, my_theta) }
+ binders = [ mkNamedBinder tv Invisible
+ | tv <- qtvs
+ , tv `elemVarSet` free_tvs ]
+ ; return (binders, my_theta) }
-chooseInferredQuantifiers inferred_theta tau_tvs
+chooseInferredQuantifiers inferred_theta tau_tvs qtvs
(Just (TISI { sig_bndr = bndr_info
, sig_ctxt = ctxt
- , sig_theta = annotated_theta }))
+ , sig_theta = annotated_theta
+ , sig_skols = annotated_tvs }))
| PartialSig { sig_cts = extra } <- bndr_info
, Nothing <- extra
= do { annotated_theta <- zonkTcTypes annotated_theta
; let free_tvs = closeOverKinds (tyCoVarsOfTypes annotated_theta
`unionVarSet` tau_tvs)
; traceTc "ciq" (vcat [ ppr bndr_info, ppr annotated_theta, ppr free_tvs])
- ; return (free_tvs, annotated_theta) }
+ ; return (mk_binders free_tvs, annotated_theta) }
| PartialSig { sig_cts = extra } <- bndr_info
, Just loc <- extra
@@ -786,7 +877,7 @@ chooseInferredQuantifiers inferred_theta tau_tvs
| otherwise -> return ()
False -> reportError msg
- ; return (free_tvs, final_theta) }
+ ; return (mk_binders free_tvs, final_theta) }
| otherwise = pprPanic "chooseInferredQuantifiers" (ppr bndr_info)
@@ -798,12 +889,21 @@ chooseInferredQuantifiers inferred_theta tau_tvs
, if suppress_hint then empty else pts_hint
, typeSigCtxt ctxt bndr_info ]
+ spec_tv_set = mkVarSet $ map snd annotated_tvs
+ mk_binders free_tvs
+ = [ mkNamedBinder tv vis
+ | tv <- qtvs
+ , tv `elemVarSet` free_tvs
+ , let vis | tv `elemVarSet` spec_tv_set = Specified
+ | otherwise = Invisible ]
+ -- Pulling from qtvs maintains original order
mk_impedence_match_msg :: MonoBindInfo
-> TcType -> TcType
-> TidyEnv -> TcM (TidyEnv, SDoc)
-- This is a rare but rather awkward error messages
-mk_impedence_match_msg (name, mb_sig, _) inf_ty sig_ty tidy_env
+mk_impedence_match_msg (MBI { mbi_poly_name = name, mbi_sig = mb_sig })
+ inf_ty sig_ty tidy_env
= do { (tidy_env1, inf_ty) <- zonkTidyTcType tidy_env inf_ty
; (tidy_env2, sig_ty) <- zonkTidyTcType tidy_env1 sig_ty
; let msg = vcat [ ptext (sLit "When checking that the inferred type")
@@ -911,14 +1011,13 @@ We can get these by "impedance matching":
Suppose the shared quantified tyvars are qtvs and constraints theta.
Then we want to check that
- f's final inferred polytype is more polymorphic than
- forall qtvs. theta => f_mono_ty
+ forall qtvs. theta => f_mono_ty is more polymorphic than f's polytype
and the proof is the impedance matcher.
Notice that the impedance matcher may do defaulting. See Trac #7173.
It also cleverly does an ambiguity check; for example, rejecting
- f :: F a -> a
+ f :: F a -> F a
where F is a non-injective type function.
-}
@@ -940,7 +1039,7 @@ recoveryCode binder_names sig_fn
= mkLocalId name forall_a_a
forall_a_a :: TcType
-forall_a_a = mkInvForAllTys [levity1TyVar, openAlphaTyVar] openAlphaTy
+forall_a_a = mkSpecForAllTys [levity1TyVar, openAlphaTyVar] openAlphaTy
{- *********************************************************************
* *
@@ -952,13 +1051,13 @@ Note [Handling SPECIALISE pragmas]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The basic idea is this:
- f:: Num a => a -> b -> a
+ foo :: Num a => a -> b -> a
{-# SPECIALISE foo :: Int -> b -> Int #-}
We check that
- (forall a. Num a => a -> a)
+ (forall a b. Num a => a -> b -> a)
is more polymorphic than
- Int -> Int
+ forall b. Int -> b -> Int
(for which we could use tcSubType, but see below), generating a HsWrapper
to connect the two, something like
wrap = /\b. <hole> Int b dNumInt
@@ -1009,8 +1108,8 @@ Some wrinkles
1. We don't use full-on tcSubType, because that does co and contra
variance and that in turn will generate too complex a LHS for the
- RULE. So we use a single invocation of deeplySkolemise /
- deeplyInstantiate in tcSpecWrapper. (Actually I think that even
+ RULE. So we use a single invocation of skolemise /
+ topInstantiate in tcSpecWrapper. (Actually I think that even
the "deeply" stuff may be too much, because it introduces lambdas,
though I think it can be made to work without too much trouble.)
@@ -1142,8 +1241,8 @@ tcSpecWrapper :: UserTypeCtxt -> TcType -> TcType -> TcM HsWrapper
-- See Note [Handling SPECIALISE pragmas], wrinkle 1
tcSpecWrapper ctxt poly_ty spec_ty
= do { (sk_wrap, inst_wrap)
- <- tcGen ctxt spec_ty $ \ _ spec_tau ->
- do { (inst_wrap, tau) <- deeplyInstantiate orig poly_ty
+ <- tcSkolemise ctxt spec_ty $ \ _ spec_tau ->
+ do { (inst_wrap, tau) <- topInstantiate orig poly_ty
; _ <- unifyType noThing spec_tau tau
-- Deliberately ignore the evidence
-- See Note [Handling SPECIALISE pragmas],
@@ -1377,24 +1476,31 @@ tcMonoBinds is_rec sig_fn no_gen
-- use ReturnTv to allow impredicativity
; let rhs_ty = mkTyVarTy rhs_tv
; mono_id <- newNoSigLetBndr no_gen name rhs_ty
- ; (co_fn, matches') <- tcExtendIdBndrs [TcIdBndr mono_id NotTopLevel] $
- -- We extend the error context even for a non-recursive
- -- function so that in type error messages we show the
- -- type of the thing whose rhs we are type checking
- tcMatchesFun name matches rhs_ty
+ ; (co_fn, matches')
+ <- tcExtendIdBndrs [TcIdBndr mono_id NotTopLevel] $
+ -- We extend the error context even for a non-recursive
+ -- function so that in type error messages we show the
+ -- type of the thing whose rhs we are type checking
+ tcMatchesFun name matches rhs_ty
; return (unitBag $ L b_loc $
FunBind { fun_id = L nm_loc mono_id,
fun_matches = matches', bind_fvs = fvs,
fun_co_fn = co_fn, fun_tick = [] },
- [(name, Nothing, mono_id)]) }
+ [MBI { mbi_poly_name = name
+ , mbi_sig = Nothing
+ , mbi_mono_id = mono_id
+ , mbi_orig = matchesCtOrigin matches }]) }
tcMonoBinds _ sig_fn no_gen binds
= do { tc_binds <- mapM (wrapLocM (tcLhs sig_fn no_gen)) binds
-- Bring the monomorphic Ids, into scope for the RHSs
; let mono_info = getMonoBindInfo tc_binds
- rhs_id_env = [(name, mono_id) | (name, mb_sig, mono_id) <- mono_info
+ rhs_id_env = [(name, mono_id) | MBI { mbi_poly_name = name
+ , mbi_sig = mb_sig
+ , mbi_mono_id = mono_id }
+ <- mono_info
, case mb_sig of
Just sig -> isPartialSig sig
Nothing -> True ]
@@ -1403,9 +1509,9 @@ tcMonoBinds _ sig_fn no_gen binds
; traceTc "tcMonoBinds" $ vcat [ ppr n <+> ppr id <+> ppr (idType id)
| (n,id) <- rhs_id_env]
- ; binds' <- tcExtendLetEnvIds NotTopLevel rhs_id_env $
- mapM (wrapLocM tcRhs) tc_binds
- ; return (listToBag binds', mono_info) }
+ ; (binds', mono_infos') <- tcExtendLetEnvIds NotTopLevel rhs_id_env $
+ mapAndUnzipM (wrapLocFstM tcRhs) tc_binds
+ ; return (listToBag binds', concat mono_infos') }
------------------------
-- tcLhs typechecks the LHS of the bindings, to construct the environment in which
@@ -1427,9 +1533,11 @@ data TcMonoBind -- Half completed; LHS done, RHS not done
= TcFunBind MonoBindInfo SrcSpan (MatchGroup Name (LHsExpr Name))
| TcPatBind [MonoBindInfo] (LPat TcId) (GRHSs Name (LHsExpr Name)) TcSigmaType
-type MonoBindInfo = (Name, Maybe TcIdSigInfo, TcId)
- -- Type signature (if any), and
- -- the monomorphic bound things
+data MonoBindInfo = MBI { mbi_poly_name :: Name
+ , mbi_sig :: Maybe TcIdSigInfo
+ , mbi_mono_id :: TcId
+ , mbi_orig :: CtOrigin }
+ -- origin associated with RHS
tcLhs :: TcSigFun -> LetBndrSpec -> HsBind Name -> TcM TcMonoBind
tcLhs sig_fn no_gen (FunBind { fun_id = L nm_loc name, fun_matches = matches })
@@ -1443,12 +1551,22 @@ tcLhs sig_fn no_gen (FunBind { fun_id = L nm_loc name, fun_matches = matches })
-- Both InferGen and CheckGen gives rise to LetLclBndr
do { mono_name <- newLocalName name
; let mono_id = mkLocalIdOrCoVar mono_name tau
- ; return (TcFunBind (name, Just sig, mono_id) nm_loc matches) }
+ ; return (TcFunBind (MBI { mbi_poly_name = name
+ , mbi_sig = Just sig
+ , mbi_mono_id = mono_id
+ , mbi_orig =
+ Shouldn'tHappenOrigin "FunBind sig" })
+ nm_loc matches) }
| otherwise
= do { mono_ty <- newOpenFlexiTyVarTy
; mono_id <- newNoSigLetBndr no_gen name mono_ty
- ; return (TcFunBind (name, Nothing, mono_id) nm_loc matches) }
+ ; return (TcFunBind (MBI { mbi_poly_name = name
+ , mbi_sig = Nothing
+ , mbi_mono_id = mono_id
+ , mbi_orig =
+ Shouldn'tHappenOrigin "FunBind nosig" })
+ nm_loc matches) }
tcLhs sig_fn no_gen (PatBind { pat_lhs = pat, pat_rhs = grhss })
= do { let tc_pat exp_ty = tcLetPat sig_fn no_gen pat exp_ty $
@@ -1458,11 +1576,15 @@ tcLhs sig_fn no_gen (PatBind { pat_lhs = pat, pat_rhs = grhss })
-- names, which the pattern has brought into scope.
lookup_info :: Name -> TcM MonoBindInfo
lookup_info name
- = do { mono_id <- tcLookupId name
- ; let mb_sig = case sig_fn name of
- Just (TcIdSig sig) -> Just sig
- _ -> Nothing
- ; return (name, mb_sig, mono_id) }
+ = do { mono_id <- tcLookupId name
+ ; let mb_sig = case sig_fn name of
+ Just (TcIdSig sig) -> Just sig
+ _ -> Nothing
+ ; return (MBI { mbi_poly_name = name
+ , mbi_sig = mb_sig
+ , mbi_mono_id = mono_id
+ , mbi_orig =
+ Shouldn'tHappenOrigin "PatBind" }) }
; ((pat', infos), pat_ty) <- addErrCtxt (patMonoBindsCtxt pat grhss) $
tcInfer tc_pat
@@ -1473,18 +1595,20 @@ tcLhs _ _ other_bind = pprPanic "tcLhs" (ppr other_bind)
-- AbsBind, VarBind impossible
-------------------
-tcRhs :: TcMonoBind -> TcM (HsBind TcId)
-tcRhs (TcFunBind info@(_, mb_sig, mono_id) loc matches)
+tcRhs :: TcMonoBind -> TcM (HsBind TcId, [MonoBindInfo]) -- fills in the mbi_orig
+tcRhs (TcFunBind info@(MBI { mbi_sig = mb_sig, mbi_mono_id = mono_id })
+ loc matches)
= tcExtendIdBinderStackForRhs [info] $
tcExtendTyVarEnvForRhs mb_sig $
do { traceTc "tcRhs: fun bind" (ppr mono_id $$ ppr (idType mono_id))
; (co_fn, matches') <- tcMatchesFun (idName mono_id)
- matches (idType mono_id)
- ; return (FunBind { fun_id = L loc mono_id
- , fun_matches = matches'
- , fun_co_fn = co_fn
- , bind_fvs = placeHolderNamesTc
- , fun_tick = [] }) }
+ matches (idType mono_id)
+ ; return ( FunBind { fun_id = L loc mono_id
+ , fun_matches = matches'
+ , fun_co_fn = co_fn
+ , bind_fvs = placeHolderNamesTc
+ , fun_tick = [] }
+ , [info { mbi_orig = matchesCtOrigin matches }] ) }
-- TODO: emit Hole Constraints for wildcards
tcRhs (TcPatBind infos pat' grhss pat_ty)
@@ -1496,9 +1620,13 @@ tcRhs (TcPatBind infos pat' grhss pat_ty)
do { traceTc "tcRhs: pat bind" (ppr pat' $$ ppr pat_ty)
; grhss' <- addErrCtxt (patMonoBindsCtxt pat' grhss) $
tcGRHSsPat grhss pat_ty
- ; return (PatBind { pat_lhs = pat', pat_rhs = grhss', pat_rhs_ty = pat_ty
- , bind_fvs = placeHolderNamesTc
- , pat_ticks = ([],[]) }) }
+ ; let orig = grhssCtOrigin grhss
+ infos' = [ info { mbi_orig = orig } | info <- infos ]
+ ; return ( PatBind { pat_lhs = pat', pat_rhs = grhss'
+ , pat_rhs_ty = pat_ty
+ , bind_fvs = placeHolderNamesTc
+ , pat_ticks = ([],[]) }
+ , infos' ) }
tcExtendTyVarEnvForRhs :: Maybe TcIdSigInfo -> TcM a -> TcM a
tcExtendTyVarEnvForRhs Nothing thing_inside
@@ -1531,7 +1659,9 @@ tcExtendIdBinderStackForRhs :: [MonoBindInfo] -> TcM a -> TcM a
-- If we had the *polymorphic* version of f in the TcIdBinderStack, it
-- would not be reported as relevant, because its type is closed
tcExtendIdBinderStackForRhs infos thing_inside
- = tcExtendIdBndrs [TcIdBndr mono_id NotTopLevel | (_, _, mono_id) <- infos] thing_inside
+ = tcExtendIdBndrs [ TcIdBndr mono_id NotTopLevel
+ | MBI { mbi_mono_id = mono_id } <- infos ]
+ thing_inside
-- NotTopLevel: it's a monomorphic binding
---------------------
@@ -1998,3 +2128,17 @@ typeSigCtxt ctxt (PartialSig { sig_hs_ty = hs_ty })
= pprSigCtxt ctxt empty (ppr hs_ty)
typeSigCtxt ctxt (CompleteSig id)
= pprSigCtxt ctxt empty (ppr (idType id))
+
+instErrCtxt :: TcId -> TcType -> TidyEnv -> TcM (TidyEnv, SDoc)
+instErrCtxt id ty env
+ = do { let (env', ty') = tidyOpenType env ty
+ ; return (env', hang (text "When instantiating" <+> quotes (ppr id) <>
+ text ", initially inferred to have" $$
+ text "this overly-general type:")
+ 2 (ppr ty') $$
+ extra) }
+ where
+ extra = sdocWithDynFlags $ \dflags ->
+ ppWhen (xopt LangExt.MonomorphismRestriction dflags) $
+ text "NB: This instantiation can be caused by the" <+>
+ text "monomorphism restriction."
diff --git a/compiler/typecheck/TcClassDcl.hs b/compiler/typecheck/TcClassDcl.hs
index 64bf2d5fe6..6411fa980d 100644
--- a/compiler/typecheck/TcClassDcl.hs
+++ b/compiler/typecheck/TcClassDcl.hs
@@ -247,13 +247,14 @@ tcDefMeth clas tyvars this_dict binds_in hs_sig_fn prag_fn
tcPolyCheck NonRecursive no_prag_fn local_dm_sig
(L bind_loc lm_bind)
- ; let export = ABE { abe_poly = global_dm_id
+ ; let export = ABE { abe_poly = global_dm_id
-- We have created a complete type signature in
-- instTcTySig, hence it is safe to call
-- completeSigPolyId
- , abe_mono = completeIdSigPolyId local_dm_sig
- , abe_wrap = idHsWrapper
- , abe_prags = IsDefaultMethod }
+ , abe_mono = completeIdSigPolyId local_dm_sig
+ , abe_wrap = idHsWrapper
+ , abe_inst_wrap = idHsWrapper
+ , abe_prags = IsDefaultMethod }
full_bind = AbsBinds { abs_tvs = tyvars
, abs_ev_vars = [this_dict]
, abs_exports = [export]
diff --git a/compiler/typecheck/TcErrors.hs b/compiler/typecheck/TcErrors.hs
index b54d5f5d6c..d480dee9c3 100644
--- a/compiler/typecheck/TcErrors.hs
+++ b/compiler/typecheck/TcErrors.hs
@@ -1239,7 +1239,8 @@ mkEqInfoMsg ct ty1 ty2
= snd (mkAmbigMsg False ct)
| otherwise = empty
- invis_msg | Just Invisible <- tcEqTypeVis ty1 ty2
+ invis_msg | Just vis <- tcEqTypeVis ty1 ty2
+ , vis /= Visible
= sdocWithDynFlags $ \dflags ->
if gopt Opt_PrintExplicitKinds dflags
then text "Use -fprint-explicit-kinds to see the kind arguments"
@@ -2111,7 +2112,7 @@ pprSkol implics tv
= case skol_info of
UnkSkol -> pp_tv <+> ptext (sLit "is an unknown type variable")
SigSkol ctxt ty -> ppr_rigid (pprSigSkolInfo ctxt
- (mkInvForAllTys skol_tvs ty))
+ (mkSpecForAllTys skol_tvs ty))
_ -> ppr_rigid (pprSkolInfo skol_info)
where
pp_tv = quotes (ppr tv)
@@ -2167,7 +2168,8 @@ relevantBindings want_filtering ctxt ct
vcat [ ppr ct
, pprCtOrigin (ctLocOrigin loc)
, ppr ct_tvs
- , ppr [id | TcIdBndr id _ <- tcl_bndrs lcl_env] ]
+ , pprWithCommas id [ ppr id <+> dcolon <+> ppr (idType id)
+ | TcIdBndr id _ <- tcl_bndrs lcl_env ] ]
; (tidy_env', docs, discards)
<- go env1 ct_tvs (maxRelevantBinds dflags)
diff --git a/compiler/typecheck/TcEvidence.hs b/compiler/typecheck/TcEvidence.hs
index 78901156e4..184aa16334 100644
--- a/compiler/typecheck/TcEvidence.hs
+++ b/compiler/typecheck/TcEvidence.hs
@@ -8,7 +8,8 @@ module TcEvidence (
HsWrapper(..),
(<.>), mkWpTyApps, mkWpEvApps, mkWpEvVarApps, mkWpTyLams,
mkWpLams, mkWpLet, mkWpCastN, mkWpCastR,
- mkWpFun, idHsWrapper, isIdHsWrapper, pprHsWrapper,
+ mkWpFun, mkWpFuns, idHsWrapper, isIdHsWrapper, pprHsWrapper,
+ symWrapper_maybe,
-- Evidence bindings
TcEvBinds(..), EvBindsVar(..),
@@ -63,6 +64,10 @@ import FastString
import SrcLoc
import Data.IORef( IORef )
+#if __GLASGOW_HASKELL__ < 709
+import Control.Applicative ( (<*>), (<$>) )
+#endif
+
{-
Note [TcCoercions]
~~~~~~~~~~~~~~~~~~
@@ -161,13 +166,14 @@ data HsWrapper
-- Hence (\a. []) `WpCompose` (\b. []) = (\a b. [])
-- But ([] a) `WpCompose` ([] b) = ([] b a)
- | WpFun HsWrapper HsWrapper TcType TcType
- -- (WpFun wrap1 wrap2 t1 t2)[e] = \(x:t1). wrap2[ e wrap1[x] ] :: t2
+ | WpFun HsWrapper HsWrapper TcType
+ -- (WpFun wrap1 wrap2 t1)[e] = \(x:t1). wrap2[ e wrap1[x] ]
-- So note that if wrap1 :: exp_arg <= act_arg
-- wrap2 :: act_res <= exp_res
-- then WpFun wrap1 wrap2 : (act_arg -> arg_res) <= (exp_arg -> exp_res)
-- This isn't the same as for mkFunCo, but it has to be this way
-- because we can't use 'sym' to flip around these HsWrappers
+ -- The TcType is the "from" type of the first wrapper
| WpCast TcCoercionR -- A cast: [] `cast` co
-- Guaranteed not the identity coercion
@@ -192,12 +198,26 @@ WpHole <.> c = c
c <.> WpHole = c
c1 <.> c2 = c1 `WpCompose` c2
-mkWpFun :: HsWrapper -> HsWrapper -> TcType -> TcType -> HsWrapper
+mkWpFun :: HsWrapper -> HsWrapper
+ -> TcType -- the "from" type of the first wrapper
+ -> TcType -- either type of the second wrapper (used only when the
+ -- second wrapper is the identity)
+ -> HsWrapper
+ -- NB: These optimisations are important, because we need
+ -- symWrapper_maybe to work in TcUnify.matchExpectedFunTys
+ -- See that function for more info.
mkWpFun WpHole WpHole _ _ = WpHole
-mkWpFun WpHole (WpCast co2) t1 _ = WpCast (mkFunCo Representational (mkRepReflCo t1) co2)
-mkWpFun (WpCast co1) WpHole _ t2 = WpCast (mkFunCo Representational (mkSymCo co1) (mkRepReflCo t2))
-mkWpFun (WpCast co1) (WpCast co2) _ _ = WpCast (mkFunCo Representational (mkSymCo co1) co2)
-mkWpFun co1 co2 t1 t2 = WpFun co1 co2 t1 t2
+mkWpFun WpHole (WpCast co2) t1 _ = WpCast (mkTcFunCo Representational (mkTcRepReflCo t1) co2)
+mkWpFun (WpCast co1) WpHole _ t2 = WpCast (mkTcFunCo Representational (mkTcSymCo co1) (mkTcRepReflCo t2))
+mkWpFun (WpCast co1) (WpCast co2) _ _ = WpCast (mkTcFunCo Representational (mkTcSymCo co1) co2)
+mkWpFun co1 co2 t1 _ = WpFun co1 co2 t1
+
+-- | @mkWpFuns arg_tys wrap@, where @wrap :: a "->" b@, gives a wrapper from
+-- @arg_tys -> a@ to @arg_tys -> b@.
+mkWpFuns :: [TcType] -> HsWrapper -> HsWrapper
+mkWpFuns [] res_wrap = res_wrap
+mkWpFuns (arg_ty : arg_tys) res_wrap
+ = WpFun idHsWrapper (mkWpFuns arg_tys res_wrap) arg_ty
mkWpCastR :: TcCoercionR -> HsWrapper
mkWpCastR co
@@ -212,6 +232,21 @@ mkWpCastN co
WpCast (mkTcSubCo co)
-- The mkTcSubCo converts Nominal to Representational
+-- | In a few limited cases, it is possible to reverse the direction
+-- of an HsWrapper. This tries to do so.
+symWrapper_maybe :: HsWrapper -> Maybe HsWrapper
+symWrapper_maybe = go
+ where
+ go WpHole = return WpHole
+ go (WpCompose wp1 wp2) = WpCompose <$> go wp2 <*> go wp1
+ go (WpFun {}) = Nothing
+ go (WpCast co) = return (WpCast (mkTcSymCo co))
+ go (WpEvLam {}) = Nothing
+ go (WpEvApp {}) = Nothing
+ go (WpTyLam {}) = Nothing
+ go (WpTyApp {}) = Nothing
+ go (WpLet {}) = Nothing
+
mkWpTyApps :: [Type] -> HsWrapper
mkWpTyApps tys = mk_co_app_fn WpTyApp tys
@@ -710,7 +745,7 @@ pprHsWrapper doc wrap
-- False <=> appears as body of let or lambda
help it WpHole = it
help it (WpCompose f1 f2) = help (help it f2) f1
- help it (WpFun f1 f2 t1 _) = add_parens $ ptext (sLit "\\(x") <> dcolon <> ppr t1 <> ptext (sLit ").") <+>
+ help it (WpFun f1 f2 t1) = add_parens $ ptext (sLit "\\(x") <> dcolon <> ppr t1 <> ptext (sLit ").") <+>
help (\_ -> it True <+> help (\_ -> ptext (sLit "x")) f1 True) f2 False
help it (WpCast co) = add_parens $ sep [it False, nest 2 (ptext (sLit "|>")
<+> pprParendCo co)]
diff --git a/compiler/typecheck/TcExpr.hs b/compiler/typecheck/TcExpr.hs
index f299e9da9b..93ba3dbb98 100644
--- a/compiler/typecheck/TcExpr.hs
+++ b/compiler/typecheck/TcExpr.hs
@@ -6,11 +6,10 @@
\section[TcExpr]{Typecheck an expression}
-}
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE CPP, TupleSections, ScopedTypeVariables #-}
module TcExpr ( tcPolyExpr, tcPolyExprNC, tcMonoExpr, tcMonoExprNC,
- tcInferRho, tcInferRhoNC,
+ tcInferSigma, tcInferSigmaNC, tcInferRho, tcInferRhoNC,
tcSyntaxOp, tcCheckId,
addExprErrCtxt,
getFixedTyVars ) where
@@ -51,9 +50,9 @@ import Name
import RdrName
import TyCon
import Type
+import TysPrim ( tYPE )
import TcEvidence
import VarSet
-import VarEnv
import TysWiredIn
import TysPrim( intPrimTy )
import PrimOp( tagToEnumKey )
@@ -62,9 +61,9 @@ import MkId ( proxyHashId )
import DynFlags
import SrcLoc
import Util
+import VarEnv ( emptyTidyEnv )
import ListSetOps
import Maybes
-import ErrUtils
import Outputable
import FastString
import Control.Monad
@@ -97,11 +96,15 @@ tcPolyExpr expr res_ty
= addExprErrCtxt expr $
do { traceTc "tcPolyExpr" (ppr res_ty); tcPolyExprNC expr res_ty }
-tcPolyExprNC expr res_ty
- = do { traceTc "tcPolyExprNC" (ppr res_ty)
- ; (gen_fn, expr') <- tcGen GenSigCtxt res_ty $ \ _ rho ->
- tcMonoExprNC expr rho
- ; return (mkLHsWrap gen_fn expr') }
+tcPolyExprNC (L loc expr) res_ty
+ = do { traceTc "tcPolyExprNC_O" (ppr res_ty)
+ ; (wrap, expr')
+ <- tcSkolemise GenSigCtxt res_ty $ \ _ res_ty ->
+ setSrcSpan loc $
+ -- NB: setSrcSpan *after* skolemising, so we get better
+ -- skolem locations
+ tcExpr expr res_ty
+ ; return $ L loc (mkHsWrap wrap expr') }
---------------
tcMonoExpr, tcMonoExprNC
@@ -121,43 +124,25 @@ tcMonoExprNC (L loc expr) res_ty
; return (L loc expr') }
---------------
+tcInferSigma, tcInferSigmaNC :: LHsExpr Name -> TcM ( LHsExpr TcId
+ , TcSigmaType )
+-- Infer a *sigma*-type.
+tcInferSigma expr = addErrCtxt (exprCtxt expr) (tcInferSigmaNC expr)
+
+tcInferSigmaNC (L loc expr)
+ = setSrcSpan loc $
+ do { (expr', sigma) <- tcInfer (tcExpr expr)
+ ; return (L loc expr', sigma) }
+
tcInferRho, tcInferRhoNC :: LHsExpr Name -> TcM (LHsExpr TcId, TcRhoType)
--- Infer a *rho*-type. This is, in effect, a special case
--- for ids and partial applications, so that if
--- f :: Int -> (forall a. a -> a) -> Int
--- then we can infer
--- f 3 :: (forall a. a -> a) -> Int
--- And that in turn is useful
--- (a) for the function part of any application (see tcApp)
--- (b) for the special rule for '$'
+-- Infer a *rho*-type. The return type is always (shallowly) instantiated.
tcInferRho expr = addErrCtxt (exprCtxt expr) (tcInferRhoNC expr)
-tcInferRhoNC (L loc expr)
- = setSrcSpan loc $
- do { (expr', rho) <- tcInfer (tcExpr expr)
- ; return (L loc expr', rho) }
+tcInferRhoNC expr
+ = do { (expr', sigma) <- tcInferSigmaNC expr
+ ; (wrap, rho) <- topInstantiate (exprCtOrigin (unLoc expr)) sigma
+ ; return (mkLHsWrap wrap expr', rho) }
-tcUnboundId :: OccName -> TcRhoType -> TcM (HsExpr TcId)
--- Typechedk an occurrence of an unbound Id
---
--- Some of these started life as a true hole "_". Others might simply
--- be variables that accidentally have no binding site
---
--- We turn all of them into HsVar, since HsUnboundVar can't contain an
--- Id; and indeed the evidence for the CHoleCan does bind it, so it's
--- not unbound any more!
-tcUnboundId occ res_ty
- = do { ty <- newFlexiTyVarTy liftedTypeKind
- ; name <- newSysName occ
- ; let ev = mkLocalId name ty
- ; loc <- getCtLocM HoleOrigin Nothing
- ; let can = CHoleCan { cc_ev = CtWanted { ctev_pred = ty
- , ctev_dest = EvVarDest ev
- , ctev_loc = loc}
- , cc_occ = occ
- , cc_hole = ExprHole }
- ; emitInsoluble can
- ; tcWrapResult (HsVar (noLoc ev)) ty res_ty }
{-
************************************************************************
@@ -165,22 +150,23 @@ tcUnboundId occ res_ty
tcExpr: the main expression typechecker
* *
************************************************************************
+
+NB: The res_ty is always deeply skolemised.
-}
tcExpr :: HsExpr Name -> TcRhoType -> TcM (HsExpr TcId)
-tcExpr e res_ty | debugIsOn && isSigmaTy res_ty -- Sanity check
- = pprPanic "tcExpr: sigma" (ppr res_ty $$ ppr e)
-
tcExpr (HsVar (L _ name)) res_ty = tcCheckId name res_ty
tcExpr (HsUnboundVar v) res_ty = tcUnboundId v res_ty
-tcExpr (HsApp e1 e2) res_ty = tcApp e1 [e2] res_ty
+tcExpr (HsApp e1 e2) res_ty
+ = do { (wrap, fun, args) <- tcApp Nothing e1 [e2] res_ty
+ ; return (mkHsWrap wrap $ unLoc $ foldl mkHsApp fun args) }
-tcExpr (HsLit lit) res_ty = do { let lit_ty = hsLitType lit
- ; tcWrapResult (HsLit lit) lit_ty res_ty }
+tcExpr e@(HsLit lit) res_ty = do { let lit_ty = hsLitType lit
+ ; tcWrapResult e (HsLit lit) lit_ty res_ty }
-tcExpr (HsPar expr) res_ty = do { expr' <- tcMonoExprNC expr res_ty
- ; return (HsPar expr') }
+tcExpr (HsPar expr) res_ty = do { expr' <- tcMonoExprNC expr res_ty
+ ; return (HsPar expr') }
tcExpr (HsSCC src lbl expr) res_ty
= do { expr' <- tcMonoExpr expr res_ty
@@ -195,7 +181,9 @@ tcExpr (HsCoreAnn src lbl expr) res_ty
; return (HsCoreAnn src lbl expr') }
tcExpr (HsOverLit lit) res_ty
- = do { lit' <- newOverloadedLit (LiteralOrigin lit) lit res_ty
+ = do { (_wrap, lit') <- newOverloadedLit lit res_ty
+ (Shouldn'tHappenOrigin "HsOverLit")
+ ; MASSERT( isIdHsWrapper _wrap )
; return (HsOverLit lit') }
tcExpr (NegApp expr neg_expr) res_ty
@@ -204,25 +192,24 @@ tcExpr (NegApp expr neg_expr) res_ty
; expr' <- tcMonoExpr expr res_ty
; return (NegApp expr' neg_expr') }
-tcExpr (HsIPVar x) res_ty
- = do { let origin = IPOccOrigin x
- {- Implicit parameters must have a *tau-type* not a.
+tcExpr e@(HsIPVar x) res_ty
+ = do { {- Implicit parameters must have a *tau-type* not a
type scheme. We enforce this by creating a fresh
type variable as its type. (Because res_ty may not
be a tau-type.) -}
- ; ip_ty <- newOpenFlexiTyVarTy
+ ip_ty <- newOpenFlexiTyVarTy
; let ip_name = mkStrLitTy (hsIPNameFS x)
; ip_var <- emitWantedEvVar origin (mkClassPred ipClass [ip_name, ip_ty])
- ; tcWrapResult (fromDict ipClass ip_name ip_ty (HsVar (noLoc ip_var)))
+ ; tcWrapResult e (fromDict ipClass ip_name ip_ty (HsVar (noLoc ip_var)))
ip_ty res_ty }
where
-- Coerces a dictionary for `IP "x" t` into `t`.
fromDict ipClass x ty = HsWrap $ mkWpCastR $
unwrapIP $ mkClassPred ipClass [x,ty]
+ origin = IPOccOrigin x
-tcExpr (HsOverLabel l) res_ty -- See Note [Type-checking overloaded labels]
- = do { let origin = OverLabelOrigin l
- ; isLabelClass <- tcLookupClass isLabelClassName
+tcExpr e@(HsOverLabel l) res_ty -- See Note [Type-checking overloaded labels]
+ = do { isLabelClass <- tcLookupClass isLabelClassName
; alpha <- newOpenFlexiTyVarTy
; let lbl = mkStrLitTy l
pred = mkClassPred isLabelClass [lbl, alpha]
@@ -231,39 +218,43 @@ tcExpr (HsOverLabel l) res_ty -- See Note [Type-checking overloaded labels]
; let proxy_arg = L loc (mkHsWrap (mkWpTyApps [typeSymbolKind, lbl])
(HsVar (L loc proxyHashId)))
tm = L loc (fromDict pred (HsVar (L loc var))) `HsApp` proxy_arg
- ; tcWrapResult tm alpha res_ty }
+ ; tcWrapResult e tm alpha res_ty }
where
-- Coerces a dictionary for `IsLabel "x" t` into `Proxy# x -> t`.
fromDict pred = HsWrap $ mkWpCastR $ unwrapIP pred
+ origin = OverLabelOrigin l
tcExpr (HsLam match) res_ty
- = do { (co_fn, match') <- tcMatchLambda match res_ty
+ = do { (co_fn, _, match') <- tcMatchLambda herald match_ctxt match res_ty
; return (mkHsWrap co_fn (HsLam match')) }
+ where
+ match_ctxt = MC { mc_what = LambdaExpr, mc_body = tcBody }
+ herald = sep [ ptext (sLit "The lambda expression") <+>
+ quotes (pprSetDepth (PartWay 1) $
+ pprMatches (LambdaExpr :: HsMatchContext Name) match),
+ -- The pprSetDepth makes the abstraction print briefly
+ ptext (sLit "has")]
tcExpr e@(HsLamCase _ matches) res_ty
- = do { (co_fn, [arg_ty], body_ty) <- matchExpectedFunTys msg 1 res_ty
- ; matches' <- tcMatchesCase match_ctxt arg_ty matches body_ty
- ; return $ mkHsWrapCo co_fn $ HsLamCase arg_ty matches' }
+ = do { (co_fn, ~[arg_ty], matches')
+ <- tcMatchLambda msg match_ctxt matches res_ty
+ -- The laziness annotation is because we don't want to fail here
+ -- if there are multiple arguments
+ ; return (mkHsWrap co_fn $ HsLamCase arg_ty matches') }
where msg = sep [ ptext (sLit "The function") <+> quotes (ppr e)
, ptext (sLit "requires")]
match_ctxt = MC { mc_what = CaseAlt, mc_body = tcBody }
-tcExpr (ExprWithTySig expr sig_ty) res_ty
+tcExpr e@(ExprWithTySig expr sig_ty) res_ty
= do { sig_info <- checkNoErrs $ -- Avoid error cascade
tcUserTypeSig sig_ty Nothing
; (expr', poly_ty) <- tcExprSig expr sig_info
- ; (inst_wrap, rho) <- deeplyInstantiate ExprSigOrigin poly_ty
- ; let expr'' = mkHsWrap inst_wrap $
- ExprWithTySigOut expr' sig_ty
- ; tcWrapResult expr'' rho res_ty }
+ ; let expr'' = ExprWithTySigOut expr' sig_ty
+ ; tcWrapResult e expr'' poly_ty res_ty }
tcExpr (HsType ty) _
- = failWithTc (text "Can't handle type argument:" <+> ppr ty)
- -- This is the syntax for type applications that I was planning
- -- but there are difficulties (e.g. what order for type args)
- -- so it's not enabled yet.
- -- Can't eliminate it altogether from the parser, because the
- -- same parser parses *patterns*.
+ = failWithTc (sep [ text "Type argument used outside of a function argument:"
+ , ppr ty ])
{-
@@ -331,7 +322,7 @@ only going to work when it's fully applied, so it turns into
So it seems more uniform to treat 'seq' as it it was a language
construct.
-See Note [seqId magic] in MkId, and
+See also Note [seqId magic] in MkId
-}
tcExpr expr@(OpApp arg1 op fix arg2) res_ty
@@ -349,17 +340,18 @@ tcExpr expr@(OpApp arg1 op fix arg2) res_ty
| (L loc (HsVar (L lv op_name))) <- op
, op_name `hasKey` dollarIdKey -- Note [Typing rule for ($)]
= do { traceTc "Application rule" (ppr op)
- ; (arg1', arg1_ty) <- tcInferRho arg1
+ ; (arg1', arg1_ty) <- tcInferSigma arg1
- ; let doc = ptext (sLit "The first argument of ($) takes")
- ; (co_arg1, [arg2_ty], op_res_ty) <- matchExpectedFunTys doc 1 arg1_ty
+ ; let doc = ptext (sLit "The first argument of ($) takes")
+ orig1 = exprCtOrigin (unLoc arg1)
+ ; (wrap_arg1, [arg2_sigma], op_res_ty) <-
+ matchActualFunTys doc orig1 1 arg1_ty
-- We have (arg1 $ arg2)
-- So: arg1_ty = arg2_ty -> op_res_ty
- -- where arg2_ty maybe polymorphic; that's the point
+ -- where arg2_sigma maybe polymorphic; that's the point
- ; arg2' <- tcArg op (arg2, arg2_ty, 2)
- ; co_b <- unifyType (Just expr) op_res_ty res_ty -- op_res ~ res
+ ; arg2' <- tcArg op (arg2, arg2_sigma, 2)
-- Make sure that the argument type has kind '*'
-- ($) :: forall (v:Levity) (a:*) (b:TYPE v). (a->b) -> a -> b
@@ -372,19 +364,31 @@ tcExpr expr@(OpApp arg1 op fix arg2) res_ty
-- so we don't need to check anything for that
; a2_tv <- newReturnTyVar liftedTypeKind
; let a2_ty = mkTyVarTy a2_tv
- ; co_a <- unifyType (Just arg2) arg2_ty a2_ty -- arg2 ~ a2
+ ; co_a <- unifyType (Just arg2) arg2_sigma a2_ty -- arg2_sigma ~N a2_ty
- ; op_id <- tcLookupId op_name
+ ; wrap_res <- tcSubTypeHR orig1 (Just expr) op_res_ty res_ty
+ -- op_res -> res
+ ; op_id <- tcLookupId op_name
; let op' = L loc (HsWrap (mkWpTyApps [ getLevity "tcExpr ($)" res_ty
, a2_ty
- , res_ty ])
+ , res_ty])
(HsVar (L lv op_id)))
- ; return $
- OpApp (mkLHsWrapCo (mkTcFunCo Nominal co_a co_b) $
- mkLHsWrapCo co_arg1 arg1')
- op' fix
- (mkLHsWrapCo co_a arg2') }
+ -- arg1' :: arg1_ty
+ -- wrap_arg1 :: arg1_ty "->" (arg2_sigma -> op_res_ty)
+ -- wrap_res :: op_res_ty "->" res_ty
+ -- co_a :: arg2_sigma ~N a2_ty
+ -- op' :: (a2_ty -> res_ty) -> a2_ty -> res_ty
+
+ -- wrap1 :: arg1_ty "->" (a2_ty -> res_ty)
+ wrap1 = mkWpFun (mkWpCastN (mkTcSymCo co_a))
+ wrap_res a2_ty res_ty <.> wrap_arg1
+
+ -- arg2' :: arg2_sigma
+ -- wrap_a :: a2_ty "->" arg2_sigma
+ ; return (OpApp (mkLHsWrap wrap1 arg1')
+ op' fix
+ (mkLHsWrapCo co_a arg2')) }
| (L loc (HsRecFld (Ambiguous lbl _))) <- op
, Just sig_ty <- obviousSig (unLoc arg1)
@@ -397,23 +401,23 @@ tcExpr expr@(OpApp arg1 op fix arg2) res_ty
| otherwise
= do { traceTc "Non Application rule" (ppr op)
- ; (op', op_ty) <- tcInferFun op
- ; (co_fn, arg_tys, op_res_ty) <- unifyOpFunTysWrap op 2 op_ty
- ; co_res <- unifyType (Just expr) op_res_ty res_ty
- ; [arg1', arg2'] <- tcArgs op [arg1, arg2] arg_tys
- ; return $ mkHsWrapCo co_res $
- OpApp arg1' (mkLHsWrapCo co_fn op') fix arg2' }
+ ; (wrap, op', [arg1', arg2'])
+ <- tcApp (Just $ mk_op_msg op)
+ op [arg1, arg2] res_ty
+ ; return (mkHsWrap wrap $ OpApp arg1' op' fix arg2') }
-- Right sections, equivalent to \ x -> x `op` expr, or
-- \ x -> op x expr
tcExpr expr@(SectionR op arg2) res_ty
= do { (op', op_ty) <- tcInferFun op
- ; (co_fn, [arg1_ty, arg2_ty], op_res_ty) <- unifyOpFunTysWrap op 2 op_ty
- ; co_res <- unifyType (Just expr) (mkFunTy arg1_ty op_res_ty) res_ty
+ ; (wrap_fun, [arg1_ty, arg2_ty], op_res_ty) <-
+ matchActualFunTys (mk_op_msg op) SectionOrigin 2 op_ty
+ ; wrap_res <- tcSubTypeHR SectionOrigin (Just expr)
+ (mkFunTy arg1_ty op_res_ty) res_ty
; arg2' <- tcArg op (arg2, arg2_ty, 2)
- ; return $ mkHsWrapCo co_res $
- SectionR (mkLHsWrapCo co_fn op') arg2' }
+ ; return ( mkHsWrap wrap_res $
+ SectionR (mkLHsWrap wrap_fun op') arg2' ) }
tcExpr expr@(SectionL arg1 op) res_ty
= do { (op', op_ty) <- tcInferFun op
@@ -421,11 +425,13 @@ tcExpr expr@(SectionL arg1 op) res_ty
; let n_reqd_args | xopt LangExt.PostfixOperators dflags = 1
| otherwise = 2
- ; (co_fn, (arg1_ty:arg_tys), op_res_ty) <- unifyOpFunTysWrap op n_reqd_args op_ty
- ; co_res <- unifyType (Just expr) (mkFunTys arg_tys op_res_ty) res_ty
+ ; (wrap_fn, (arg1_ty:arg_tys), op_res_ty)
+ <- matchActualFunTys (mk_op_msg op) SectionOrigin n_reqd_args op_ty
+ ; wrap_res <- tcSubTypeHR SectionOrigin (Just expr)
+ (mkFunTys arg_tys op_res_ty) res_ty
; arg1' <- tcArg op (arg1, arg1_ty, 1)
- ; return $ mkHsWrapCo co_res $
- SectionL arg1' (mkLHsWrapCo co_fn op') }
+ ; return ( mkHsWrap wrap_res $
+ SectionL arg1' (mkLHsWrap wrap_fn op') ) }
tcExpr expr@(ExplicitTuple tup_args boxity) res_ty
| all tupArgPresent tup_args
@@ -451,30 +457,35 @@ tcExpr expr@(ExplicitTuple tup_args boxity) res_ty
= mkFunTys [ty | (ty, (L _ (Missing _))) <- arg_tys `zip` tup_args]
(mkTupleTy boxity arg_tys)
- ; coi <- unifyType (Just expr) actual_res_ty res_ty
+ ; wrap <- tcSubTypeHR (Shouldn'tHappenOrigin "ExpTuple")
+ (Just expr)
+ actual_res_ty res_ty
-- Handle tuple sections where
; tup_args1 <- tcTupArgs tup_args arg_tys
- ; return $ mkHsWrapCo coi (ExplicitTuple tup_args1 boxity) }
+ ; return $ mkHsWrap wrap (ExplicitTuple tup_args1 boxity) }
tcExpr (ExplicitList _ witness exprs) res_ty
= case witness of
Nothing -> do { (coi, elt_ty) <- matchExpectedListTy res_ty
; exprs' <- mapM (tc_elt elt_ty) exprs
- ; return $ mkHsWrapCo coi (ExplicitList elt_ty Nothing exprs') }
+ ; return $
+ mkHsWrapCo coi $ ExplicitList elt_ty Nothing exprs' }
- Just fln -> do { list_ty <- newFlexiTyVarTy liftedTypeKind
+ Just fln -> do { list_ty <- newFlexiTyVarTy liftedTypeKind
; fln' <- tcSyntaxOp ListOrigin fln (mkFunTys [intTy, list_ty] res_ty)
; (coi, elt_ty) <- matchExpectedListTy list_ty
; exprs' <- mapM (tc_elt elt_ty) exprs
- ; return $ mkHsWrapCo coi (ExplicitList elt_ty (Just fln') exprs') }
+ ; return $
+ mkHsWrapCo coi $ ExplicitList elt_ty (Just fln') exprs' }
where tc_elt elt_ty expr = tcPolyExpr expr elt_ty
tcExpr (ExplicitPArr _ exprs) res_ty -- maybe empty
= do { (coi, elt_ty) <- matchExpectedPArrTy res_ty
; exprs' <- mapM (tc_elt elt_ty) exprs
- ; return $ mkHsWrapCo coi (ExplicitPArr elt_ty exprs') }
+ ; return $
+ mkHsWrapCo coi $ ExplicitPArr elt_ty exprs' }
where
tc_elt elt_ty expr = tcPolyExpr expr elt_ty
@@ -512,33 +523,30 @@ tcExpr (HsCase scrut matches) exp_ty
tcExpr (HsIf Nothing pred b1 b2) res_ty -- Ordinary 'if'
= do { pred' <- tcMonoExpr pred boolTy
+ -- this forces the branches to be fully instantiated
+ -- (See #10619)
+ ; res_ty <- tauTvForReturnTv res_ty
; b1' <- tcMonoExpr b1 res_ty
; b2' <- tcMonoExpr b2 res_ty
; return (HsIf Nothing pred' b1' b2') }
-tcExpr (HsIf (Just fun) pred b1 b2) res_ty -- Note [Rebindable syntax for if]
- = do { pred_ty <- newOpenFlexiTyVarTy
- ; b1_ty <- newOpenFlexiTyVarTy
- ; b2_ty <- newOpenFlexiTyVarTy
- ; let if_ty = mkFunTys [pred_ty, b1_ty, b2_ty] res_ty
- ; fun' <- tcSyntaxOp IfOrigin fun if_ty
- ; pred' <- tcMonoExpr pred pred_ty
- ; b1' <- tcMonoExpr b1 b1_ty
- ; b2' <- tcMonoExpr b2 b2_ty
- -- Fundamentally we are just typing (ifThenElse e1 e2 e3)
- -- so maybe we should use the code for function applications
- -- (which would allow ifThenElse to be higher rank).
- -- But it's a little awkward, so I'm leaving it alone for now
- -- and it maintains uniformity with other rebindable syntax
- ; return (HsIf (Just fun') pred' b1' b2') }
+tcExpr (HsIf (Just fun) pred b1 b2) res_ty
+ -- Note [Rebindable syntax for if]
+ = do { (wrap, fun', [pred', b1', b2'])
+ <- tcApp (Just herald) (noLoc fun) [pred, b1, b2] res_ty
+ ; return ( mkHsWrap wrap $
+ HsIf (Just (unLoc fun')) pred' b1' b2' ) }
+ where
+ herald = text "Rebindable" <+> quotes (text "if") <+> text "takes"
tcExpr (HsMultiIf _ alts) res_ty
= do { alts' <- mapM (wrapLocM $ tcGRHS match_ctxt res_ty) alts
- ; return $ HsMultiIf res_ty alts' }
+ ; return (HsMultiIf res_ty alts') }
where match_ctxt = MC { mc_what = IfAlt, mc_body = tcBody }
tcExpr (HsDo do_or_lc stmts _) res_ty
- = tcDoStmts do_or_lc stmts res_ty
+ = do { expr' <- tcDoStmts do_or_lc stmts res_ty
+ ; return expr' }
tcExpr (HsProc pat cmd) res_ty
= do { (pat', cmd', coi) <- tcProc pat cmd res_ty
@@ -598,19 +606,25 @@ tcExpr expr@(RecordCon { rcon_con_name = L loc con_name
-- Check for missing fields
; checkMissingFields con_like rbinds
- ; (con_expr, con_tau) <- tcInferId con_name
+ ; (con_expr, con_sigma) <- tcInferId con_name
+ ; (con_wrap, con_tau) <-
+ topInstantiate (OccurrenceOf con_name) con_sigma
+ -- a shallow instantiation should really be enough for
+ -- a data constructor.
; let arity = conLikeArity con_like
(arg_tys, actual_res_ty) = tcSplitFunTysN con_tau arity
; case conLikeWrapId_maybe con_like of
Nothing -> nonBidirectionalErr (conLikeName con_like)
Just con_id -> do {
- co_res <- unifyType (Just expr) actual_res_ty res_ty
+ res_wrap <- tcSubTypeHR (Shouldn'tHappenOrigin "RecordCon")
+ (Just expr) actual_res_ty res_ty
; rbinds' <- tcRecordBinds con_like arg_tys rbinds
- ; return $ mkHsWrapCo co_res $
- RecordCon { rcon_con_name = L loc con_id
- , rcon_con_expr = con_expr
- , rcon_con_like = con_like
- , rcon_flds = rbinds' } } }
+ ; return $
+ mkHsWrap res_wrap $
+ RecordCon { rcon_con_name = L loc con_id
+ , rcon_con_expr = mkHsWrap con_wrap con_expr
+ , rcon_con_like = con_like
+ , rcon_flds = rbinds' } } }
{-
Note [Type of a record update]
@@ -749,12 +763,12 @@ following.
tcExpr expr@(RecordUpd { rupd_expr = record_expr, rupd_flds = rbnds }) res_ty
= ASSERT( notNull rbnds )
- do { -- STEP -2: typecheck the record_expr, the record to bd updated
- (record_expr', record_tau) <- tcInferFun record_expr
+ do { -- STEP -2: typecheck the record_expr, the record to be updated
+ (record_expr', record_rho) <- tcInferRho record_expr
-- STEP -1 See Note [Disambiguating record fields]
-- After this we know that rbinds is unambiguous
- ; rbinds <- disambiguateRecordBinds record_expr record_tau rbnds res_ty
+ ; rbinds <- disambiguateRecordBinds record_expr record_rho rbnds res_ty
; let upd_flds = map (unLoc . hsRecFieldLbl . unLoc) rbinds
upd_fld_occs = map (occNameFS . rdrNameOcc . rdrNameAmbiguousFieldOcc) upd_flds
sel_ids = map selectorAmbiguousFieldOcc upd_flds
@@ -860,8 +874,12 @@ tcExpr expr@(RecordUpd { rupd_expr = record_expr, rupd_flds = rbnds }) res_ty
scrut_ty = TcType.substTy scrut_subst con1_res_ty
con1_arg_tys' = map (TcType.substTy result_subst) con1_arg_tys
- ; co_res <- unifyType (Just expr) rec_res_ty res_ty
- ; co_scrut <- unifyType (Just record_expr) record_tau scrut_ty
+ ; wrap_res <- tcSubTypeHR (exprCtOrigin expr)
+ (Just expr) rec_res_ty res_ty
+ ; co_scrut <- unifyType (Just record_expr) record_rho scrut_ty
+ -- NB: normal unification is OK here (as opposed to subsumption),
+ -- because for this to work out, both record_rho and scrut_ty have
+ -- to be normal datatypes -- no contravariant stuff can go on
-- STEP 5
-- Typecheck the bindings
@@ -887,7 +905,8 @@ tcExpr expr@(RecordUpd { rupd_expr = record_expr, rupd_flds = rbnds }) res_ty
; req_wrap <- instCallConstraints RecordUpdOrigin req_theta'
-- Phew!
- ; return $ mkHsWrapCo co_res $
+ ; return $
+ mkHsWrap wrap_res $
RecordUpd { rupd_expr = mkLHsWrap fam_co (mkLHsWrapCo co_scrut record_expr')
, rupd_flds = rbinds'
, rupd_cons = relevant_cons, rupd_in_tys = scrut_inst_tys
@@ -916,8 +935,8 @@ tcExpr (PArrSeq _ seq@(FromTo expr1 expr2)) res_ty
; enumFromToP <- initDsTc $ dsDPHBuiltin enumFromToPVar
; enum_from_to <- newMethodFromName (PArrSeqOrigin seq)
(idName enumFromToP) elt_ty
- ; return $ mkHsWrapCo coi
- (PArrSeq enum_from_to (FromTo expr1' expr2')) }
+ ; return $
+ mkHsWrapCo coi $ PArrSeq enum_from_to (FromTo expr1' expr2') }
tcExpr (PArrSeq _ seq@(FromThenTo expr1 expr2 expr3)) res_ty
= do { (coi, elt_ty) <- matchExpectedPArrTy res_ty
@@ -927,8 +946,9 @@ tcExpr (PArrSeq _ seq@(FromThenTo expr1 expr2 expr3)) res_ty
; enumFromThenToP <- initDsTc $ dsDPHBuiltin enumFromThenToPVar
; eft <- newMethodFromName (PArrSeqOrigin seq)
(idName enumFromThenToP) elt_ty -- !!!FIXME: chak
- ; return $ mkHsWrapCo coi
- (PArrSeq eft (FromThenTo expr1' expr2' expr3')) }
+ ; return $
+ mkHsWrapCo coi $
+ PArrSeq eft (FromThenTo expr1' expr2' expr3') }
tcExpr (PArrSeq _ _) _
= panic "TcExpr.tcExpr: Infinite parallel array!"
@@ -943,9 +963,12 @@ tcExpr (PArrSeq _ _) _
************************************************************************
-}
-tcExpr (HsSpliceE splice) res_ty = tcSpliceExpr splice res_ty
-tcExpr (HsBracket brack) res_ty = tcTypedBracket brack res_ty
-tcExpr (HsRnBracketOut brack ps) res_ty = tcUntypedBracket brack ps res_ty
+tcExpr (HsSpliceE splice) res_ty
+ = tcSpliceExpr splice res_ty
+tcExpr (HsBracket brack) res_ty
+ = tcTypedBracket brack res_ty
+tcExpr (HsRnBracketOut brack ps) res_ty
+ = tcUntypedBracket brack ps res_ty
{-
************************************************************************
@@ -1004,7 +1027,7 @@ tcArithSeq witness seq@(FromThenTo expr1 expr2 expr3) res_ty
-----------------
arithSeqEltType :: Maybe (SyntaxExpr Name) -> TcRhoType
- -> TcM (TcCoercion, TcType, Maybe (SyntaxExpr Id))
+ -> TcM (TcCoercionN, TcType, Maybe (SyntaxExpr Id))
arithSeqEltType Nothing res_ty
= do { (coi, elt_ty) <- matchExpectedListTy res_ty
; return (coi, elt_ty, Nothing) }
@@ -1022,66 +1045,66 @@ arithSeqEltType (Just fl) res_ty
************************************************************************
-}
-tcApp :: LHsExpr Name -> [LHsExpr Name] -- Function and args
- -> TcRhoType -> TcM (HsExpr TcId) -- Translated fun and args
-
-tcApp (L _ (HsPar e)) args res_ty
- = tcApp e args res_ty
-
-tcApp (L _ (HsApp e1 e2)) args res_ty
- = tcApp e1 (e2:args) res_ty -- Accumulate the arguments
-
-tcApp (L loc (HsVar (L _ fun))) args res_ty
- | fun `hasKey` tagToEnumKey
- , [arg] <- args
- = tcTagToEnum loc fun arg res_ty
-
- | fun `hasKey` seqIdKey
- , [arg1,arg2] <- args
- = tcSeq loc fun arg1 arg2 res_ty
-
--- Look for applications of ambiguous record selectors to arguments
--- with type signatures, see Note [Disambiguating record fields]
-tcApp (L loc (HsRecFld (Ambiguous lbl _))) args@(L _ arg:_) res_ty
- | Just sig_ty <- obviousSig arg
- = do { sig_tc_ty <- tcHsSigWcType ExprSigCtxt sig_ty
- ; sel_name <- disambiguateSelector lbl sig_tc_ty
- ; tcApp (L loc (HsRecFld (Unambiguous lbl sel_name))) args res_ty }
-
-tcApp fun args res_ty
- = do { -- Type-check the function
- ; (fun1, fun_tau) <- tcInferFun fun
-
- -- Extract its argument types
- ; (co_fun, expected_arg_tys, actual_res_ty)
- <- matchExpectedFunTys (mk_app_msg fun) (length args) fun_tau
-
- -- Typecheck the result, thereby propagating
- -- info (if any) from result into the argument types
- -- Both actual_res_ty and res_ty are deeply skolemised
- -- Rather like tcWrapResult, but (perhaps for historical reasons)
- -- we do this before typechecking the arguments
- ; wrap_res <- addErrCtxtM (funResCtxt True (unLoc fun) actual_res_ty res_ty) $
- tcSubTypeDS_NC GenSigCtxt (Just $ foldl mkHsApp fun args)
- actual_res_ty res_ty
-
- -- Typecheck the arguments
- ; args1 <- tcArgs fun args expected_arg_tys
-
- -- Assemble the result
- ; let fun2 = mkLHsWrapCo co_fun fun1
- app = mkLHsWrap wrap_res (foldl mkHsApp fun2 args1)
-
- ; return (unLoc app) }
-
+tcApp :: Maybe SDoc -- like "The function `f' is applied to"
+ -- or leave out to get exactly that message
+ -> LHsExpr Name -> [LHsExpr Name] -- Function and args
+ -> TcRhoType -> TcM (HsWrapper, LHsExpr TcId, [LHsExpr TcId])
+ -- (wrap, fun, args). For an ordinary function application,
+ -- these should be assembled as (wrap (fun args)).
+ -- But OpApp is slightly different, so that's why the caller
+ -- must assemble
+
+tcApp m_herald orig_fun orig_args res_ty
+ = go orig_fun orig_args
+ where
+ go (L _ (HsPar e)) args = go e args
+ go (L _ (HsApp e1 e2)) args = go e1 (e2:args)
+
+ go (L loc (HsVar (L _ fun))) args
+ | fun `hasKey` tagToEnumKey
+ , count (not . isLHsTypeExpr) args == 1
+ = do { (wrap, expr, args) <- tcTagToEnum loc fun args res_ty
+ ; return (wrap, expr, args) }
+
+ | fun `hasKey` seqIdKey
+ , count (not . isLHsTypeExpr) args == 2
+ = do { (wrap, expr, args) <- tcSeq loc fun args res_ty
+ ; return (wrap, expr, args) }
+
+ go (L loc (HsRecFld (Ambiguous lbl _))) args@(L _ arg : _)
+ | Just sig_ty <- obviousSig arg
+ = do { sig_tc_ty <- tcHsSigWcType ExprSigCtxt sig_ty
+ ; sel_name <- disambiguateSelector lbl sig_tc_ty
+ ; go (L loc (HsRecFld (Unambiguous lbl sel_name))) args }
+
+ go fun args
+ = do { -- Type-check the function
+ ; (fun1, fun_sigma) <- tcInferFun fun
+ ; let orig = exprCtOrigin (unLoc fun)
+
+ ; (wrap_fun, args1, actual_res_ty)
+ <- tcArgs fun fun_sigma orig args
+ (m_herald `orElse` mk_app_msg fun)
+
+ -- this is just like tcWrapResult, but the types don't line
+ -- up to call that function
+ ; wrap_res <- addFunResCtxt True (unLoc fun) actual_res_ty res_ty $
+ tcSubTypeDS_NC_O orig GenSigCtxt
+ (Just $ foldl mkHsApp fun args)
+ actual_res_ty res_ty
+
+ ; return (wrap_res, mkLHsWrap wrap_fun fun1, args1) }
mk_app_msg :: LHsExpr Name -> SDoc
mk_app_msg fun = sep [ ptext (sLit "The function") <+> quotes (ppr fun)
, ptext (sLit "is applied to")]
+mk_op_msg :: LHsExpr Name -> SDoc
+mk_op_msg op = text "The operator" <+> quotes (ppr op) <+> text "takes"
+
----------------
-tcInferFun :: LHsExpr Name -> TcM (LHsExpr TcId, TcRhoType)
--- Infer and instantiate the type of a function
+tcInferFun :: LHsExpr Name -> TcM (LHsExpr TcId, TcSigmaType)
+-- Infer type of a function
tcInferFun (L loc (HsVar (L _ name)))
= do { (fun, ty) <- setSrcSpan loc (tcInferId name)
-- Don't wrap a context around a plain Id
@@ -1093,23 +1116,70 @@ tcInferFun (L loc (HsRecFld f))
; return (L loc fun, ty) }
tcInferFun fun
- = do { (fun, fun_ty) <- tcInfer (tcMonoExpr fun)
+ = do { (fun, fun_ty) <- tcInferSigma fun
-- Zonk the function type carefully, to expose any polymorphism
-- E.g. (( \(x::forall a. a->a). blah ) e)
-- We can see the rank-2 type of the lambda in time to generalise e
; fun_ty' <- zonkTcType fun_ty
- ; (wrap, rho) <- deeplyInstantiate AppOrigin fun_ty'
- ; return (mkLHsWrap wrap fun, rho) }
+ ; return (fun, fun_ty') }
----------------
-tcArgs :: LHsExpr Name -- The function (for error messages)
- -> [LHsExpr Name] -> [TcSigmaType] -- Actual arguments and expected arg types
- -> TcM [LHsExpr TcId] -- Resulting args
-
-tcArgs fun args expected_arg_tys
- = mapM (tcArg fun) (zip3 args expected_arg_tys [1..])
+-- | Type-check the arguments to a function, possibly including visible type
+-- applications
+tcArgs :: LHsExpr Name -- ^ The function itself (for err msgs only)
+ -> TcSigmaType -- ^ the (uninstantiated) type of the function
+ -> CtOrigin -- ^ the origin for the function's type
+ -> [LHsExpr Name] -- ^ the args
+ -> SDoc -- ^ the herald for matchActualFunTys
+ -> TcM (HsWrapper, [LHsExpr TcId], TcSigmaType)
+ -- ^ (a wrapper for the function, the tc'd args, result type)
+tcArgs fun orig_fun_ty fun_orig orig_args herald
+ = go [] 1 orig_fun_ty orig_args
+ where
+ orig_arity = length orig_args
+
+ go _ _ fun_ty [] = return (idHsWrapper, [], fun_ty)
+
+ go acc_args n fun_ty (arg:args)
+ | Just hs_ty_arg <- isLHsTypeExpr_maybe arg
+ = do { (wrap1, upsilon_ty) <- topInstantiateInferred fun_orig fun_ty
+ -- wrap1 :: fun_ty "->" upsilon_ty
+ ; case tcSplitForAllTy_maybe upsilon_ty of
+ Just (binder, inner_ty)
+ | Just tv <- binderVar_maybe binder ->
+ ASSERT( binderVisibility binder == Specified )
+ do { let kind = tyVarKind tv
+ ; ty_arg <- tcHsTypeApp hs_ty_arg kind
+ ; let insted_ty = substTyWith [tv] [ty_arg] inner_ty
+ ; (inner_wrap, args', res_ty)
+ <- go acc_args (n+1) insted_ty args
+ -- inner_wrap :: insted_ty "->" (map typeOf args') -> res_ty
+ ; let inst_wrap = mkWpTyApps [ty_arg]
+ ; return ( inner_wrap <.> inst_wrap <.> wrap1
+ , L (getLoc arg) (HsTypeOut hs_ty_arg) : args'
+ , res_ty ) }
+ _ -> ty_app_err upsilon_ty hs_ty_arg }
+
+ | otherwise -- not a type application.
+ = do { (wrap, [arg_ty], res_ty)
+ <- matchActualFunTysPart herald fun_orig 1 fun_ty
+ acc_args orig_arity
+ -- wrap :: fun_ty "->" arg_ty -> res_ty
+ ; arg' <- tcArg fun (arg, arg_ty, n)
+ ; (inner_wrap, args', inner_res_ty)
+ <- go (arg_ty : acc_args) (n+1) res_ty args
+ -- inner_wrap :: res_ty "->" (map typeOf args') -> inner_res_ty
+ ; return ( mkWpFun idHsWrapper inner_wrap arg_ty res_ty <.> wrap
+ , arg' : args'
+ , inner_res_ty ) }
+
+ ty_app_err ty arg
+ = do { (_, ty) <- zonkTidyTcType emptyTidyEnv ty
+ ; failWith $
+ text "Cannot not apply expression of type" <+> quotes (ppr ty) $$
+ text "to a visible type argument" <+> quotes (ppr arg) }
----------------
tcArg :: LHsExpr Name -- The function (for error messages)
@@ -1127,23 +1197,16 @@ tcTupArgs args tys
go (L l (Present expr), arg_ty) = do { expr' <- tcPolyExpr expr arg_ty
; return (L l (Present expr')) }
-----------------
-unifyOpFunTysWrap :: LHsExpr Name -> Arity -> TcRhoType
- -> TcM (TcCoercion, [TcSigmaType], TcRhoType)
--- A wrapper for matchExpectedFunTys
-unifyOpFunTysWrap op arity ty = matchExpectedFunTys herald arity ty
- where
- herald = ptext (sLit "The operator") <+> quotes (ppr op) <+> ptext (sLit "takes")
-
---------------------------
tcSyntaxOp :: CtOrigin -> HsExpr Name -> TcType -> TcM (HsExpr TcId)
-- Typecheck a syntax operator, checking that it has the specified type
-- The operator is always a variable at this stage (i.e. renamer output)
-- This version assumes res_ty is a monotype
tcSyntaxOp orig (HsVar (L _ op)) res_ty
- = do { (expr, rho) <- tcInferIdWithOrig orig (nameRdrName op) op
- ; tcWrapResult expr rho res_ty }
-tcSyntaxOp _ other _ = pprPanic "tcSyntaxOp" (ppr other)
+ = do { (expr, rho) <- tcInferId op
+ ; tcWrapResultO orig expr rho res_ty }
+
+tcSyntaxOp _ other _ = pprPanic "tcSyntaxOp" (ppr other)
{-
Note [Push result type in]
@@ -1170,7 +1233,6 @@ With the change, f1 will type-check, because the 'Char' info from
the signature is propagated into MkQ's argument. With the check
in the other order, the extra signature in f2 is reqd.
-
************************************************************************
* *
Expressions with a type signature
@@ -1209,11 +1271,11 @@ tcExprSig expr sig@(TISI { sig_bndr = s_bndr
; tau <- zonkTcType tau
; let inferred_theta = map evVarPred givens
tau_tvs = tyCoVarsOfType tau
- ; (my_tv_set, my_theta) <- chooseInferredQuantifiers inferred_theta tau_tvs (Just sig)
- ; let my_tvs = filter (`elemVarSet` my_tv_set) qtvs -- Maintain original order
- inferred_sigma = mkInvSigmaTy qtvs inferred_theta tau
- my_sigma = mkInvSigmaTy my_tvs my_theta tau
- ; wrap <- if inferred_sigma `eqType` my_sigma
+ ; (binders, my_theta) <- chooseInferredQuantifiers inferred_theta
+ tau_tvs qtvs (Just sig)
+ ; let inferred_sigma = mkInvSigmaTy qtvs inferred_theta tau
+ my_sigma = mkForAllTys binders (mkPhiTy my_theta tau)
+ ; wrap <- if inferred_sigma `eqType` my_sigma -- NB: eqType ignores vis.
then return idHsWrapper -- Fast path; also avoids complaint when we infer
-- an ambiguouse type and have AllowAmbiguousType
-- e..g infer x :: forall a. F a -> Int
@@ -1223,7 +1285,7 @@ tcExprSig expr sig@(TISI { sig_bndr = s_bndr
<.> mkWpTyLams qtvs
<.> mkWpLams givens
<.> mkWpLet ev_binds
- ; return (mkLHsWrap poly_wrap expr', mkInvSigmaTy qtvs theta tau) }
+ ; return (mkLHsWrap poly_wrap expr', my_sigma) }
| otherwise = panic "tcExprSig" -- Can't happen
where
@@ -1240,15 +1302,14 @@ tcCheckId :: Name -> TcRhoType -> TcM (HsExpr TcId)
tcCheckId name res_ty
= do { (expr, actual_res_ty) <- tcInferId name
; traceTc "tcCheckId" (vcat [ppr name, ppr actual_res_ty, ppr res_ty])
- ; addErrCtxtM (funResCtxt False (HsVar (noLoc name))
- actual_res_ty res_ty) $
- tcWrapResult expr actual_res_ty res_ty }
+ ; addFunResCtxt False (HsVar (noLoc name)) actual_res_ty res_ty $
+ tcWrapResultO (OccurrenceOf name) expr actual_res_ty res_ty }
tcCheckRecSelId :: AmbiguousFieldOcc Name -> TcRhoType -> TcM (HsExpr TcId)
-tcCheckRecSelId f@(Unambiguous _ _) res_ty
+tcCheckRecSelId f@(Unambiguous (L _ lbl) _) res_ty
= do { (expr, actual_res_ty) <- tcInferRecSelId f
- ; addErrCtxtM (funResCtxt False (HsRecFld f) actual_res_ty res_ty) $
- tcWrapResult expr actual_res_ty res_ty }
+ ; addFunResCtxt False (HsRecFld f) actual_res_ty res_ty $
+ tcWrapResultO (OccurrenceOfRecSel lbl) expr actual_res_ty res_ty }
tcCheckRecSelId (Ambiguous lbl _) res_ty
= case tcSplitFunTy_maybe res_ty of
Nothing -> ambiguousSelector lbl
@@ -1256,21 +1317,17 @@ tcCheckRecSelId (Ambiguous lbl _) res_ty
; tcCheckRecSelId (Unambiguous lbl sel_name) res_ty }
------------------------
-tcInferId :: Name -> TcM (HsExpr TcId, TcRhoType)
--- Infer type, and deeply instantiate
-tcInferId n = tcInferIdWithOrig (OccurrenceOf n) (nameRdrName n) n
-
tcInferRecSelId :: AmbiguousFieldOcc Name -> TcM (HsExpr TcId, TcRhoType)
tcInferRecSelId (Unambiguous (L _ lbl) sel)
- = tcInferIdWithOrig (OccurrenceOfRecSel lbl) lbl sel
+ = do { (expr', ty) <- tc_infer_id lbl sel
+ ; return (expr', ty) }
tcInferRecSelId (Ambiguous lbl _)
= ambiguousSelector lbl
------------------------
-tcInferIdWithOrig :: CtOrigin -> RdrName -> Name ->
- TcM (HsExpr TcId, TcRhoType)
--- Look up an occurrence of an Id, and instantiate it (deeply)
-tcInferIdWithOrig orig lbl id_name
+tcInferId :: Name -> TcM (HsExpr TcId, TcSigmaType)
+-- Look up an occurrence of an Id
+tcInferId id_name
| id_name `hasKey` tagToEnumKey
= failWithTc (ptext (sLit "tagToEnum# must appear applied to one argument"))
-- tcApp catches the case (tagToEnum# arg)
@@ -1278,67 +1335,97 @@ tcInferIdWithOrig orig lbl id_name
| id_name `hasKey` assertIdKey
= do { dflags <- getDynFlags
; if gopt Opt_IgnoreAsserts dflags
- then tc_infer_id orig lbl id_name
- else tc_infer_assert orig }
+ then tc_infer_id (nameRdrName id_name) id_name
+ else tc_infer_assert id_name }
| otherwise
- = tc_infer_id orig lbl id_name
+ = do { (expr, ty) <- tc_infer_id (nameRdrName id_name) id_name
+ ; traceTc "tcInferId" (ppr id_name <+> dcolon <+> ppr ty)
+ ; return (expr, ty) }
-tc_infer_assert :: CtOrigin -> TcM (HsExpr TcId, TcRhoType)
+tc_infer_assert :: Name -> TcM (HsExpr TcId, TcSigmaType)
-- Deal with an occurrence of 'assert'
-- See Note [Adding the implicit parameter to 'assert']
-tc_infer_assert orig
+tc_infer_assert assert_name
= do { assert_error_id <- tcLookupId assertErrorName
- ; (wrap, id_rho) <- deeplyInstantiate orig (idType assert_error_id)
+ ; (wrap, id_rho) <- topInstantiate (OccurrenceOf assert_name)
+ (idType assert_error_id)
; return (mkHsWrap wrap (HsVar (noLoc assert_error_id)), id_rho)
}
-tc_infer_id :: CtOrigin -> RdrName -> Name -> TcM (HsExpr TcId, TcRhoType)
--- Return type is deeply instantiated
-tc_infer_id orig lbl id_name
+tc_infer_id :: RdrName -> Name -> TcM (HsExpr TcId, TcSigmaType)
+tc_infer_id lbl id_name
= do { thing <- tcLookup id_name
; case thing of
ATcId { tct_id = id }
-> do { check_naughty id -- Note [Local record selectors]
; checkThLocalId id
- ; inst_normal_id id }
+ ; return_id id }
AGlobal (AnId id)
-> do { check_naughty id
- ; inst_normal_id id }
+ ; return_id id }
-- A global cannot possibly be ill-staged
-- nor does it need the 'lifting' treatment
-- hence no checkTh stuff here
AGlobal (AConLike cl) -> case cl of
- RealDataCon con -> inst_data_con con
- PatSynCon ps -> tcPatSynBuilderOcc orig ps
+ RealDataCon con -> return_data_con con
+ PatSynCon ps -> tcPatSynBuilderOcc ps
_ -> failWithTc $
ppr thing <+> ptext (sLit "used where a value identifier was expected") }
where
- inst_normal_id id
- = do { (wrap, rho) <- deeplyInstantiate orig (idType id)
- ; return (mkHsWrap wrap (HsVar (noLoc id)), rho) }
-
- inst_data_con con
- -- For data constructors,
- -- * Must perform the stupid-theta check
- -- * No need to deeply instantiate because type has all foralls at top
- = do { let wrap_id = dataConWrapId con
- (tvs, theta, rho) = tcSplitSigmaTy (idType wrap_id)
- ; (subst, tvs') <- newMetaTyVars tvs
- ; let tys' = mkTyVarTys tvs'
- theta' = substTheta subst theta
- rho' = substTy subst rho
- ; wrap <- instCall orig tys' theta'
- ; addDataConStupidTheta con tys'
- ; return (mkHsWrap wrap (HsVar (noLoc wrap_id)), rho') }
+ return_id id = return (HsVar (noLoc id), idType id)
+
+ return_data_con con
+ -- For data constructors, must perform the stupid-theta check
+ | null stupid_theta
+ = return_id con_wrapper_id
+
+ | otherwise
+ -- See Note [Instantiating stupid theta]
+ = do { let (tvs, theta, rho) = tcSplitSigmaTy (idType con_wrapper_id)
+ ; (subst, tvs') <- newMetaTyVars tvs
+ ; let tys' = mkTyVarTys tvs'
+ theta' = substTheta subst theta
+ rho' = substTy subst rho
+ ; wrap <- instCall (OccurrenceOf id_name) tys' theta'
+ ; addDataConStupidTheta con tys'
+ ; return (mkHsWrap wrap (HsVar (noLoc con_wrapper_id)), rho') }
+
+ where
+ con_wrapper_id = dataConWrapId con
+ stupid_theta = dataConStupidTheta con
check_naughty id
| isNaughtyRecordSelector id = failWithTc (naughtyRecordSel lbl)
| otherwise = return ()
+
+tcUnboundId :: OccName -> TcRhoType -> TcM (HsExpr TcId)
+-- Typechedk an occurrence of an unbound Id
+--
+-- Some of these started life as a true hole "_". Others might simply
+-- be variables that accidentally have no binding site
+--
+-- We turn all of them into HsVar, since HsUnboundVar can't contain an
+-- Id; and indeed the evidence for the CHoleCan does bind it, so it's
+-- not unbound any more!
+tcUnboundId occ res_ty
+ = do { ty <- newFlexiTyVarTy liftedTypeKind
+ ; name <- newSysName occ
+ ; let ev = mkLocalId name ty
+ ; loc <- getCtLocM HoleOrigin Nothing
+ ; let can = CHoleCan { cc_ev = CtWanted { ctev_pred = ty
+ , ctev_dest = EvVarDest ev
+ , ctev_loc = loc}
+ , cc_occ = occ
+ , cc_hole = ExprHole }
+ ; emitInsoluble can
+ ; tcWrapResultO (UnboundOccurrenceOf occ) (HsVar (noLoc ev)) ty res_ty }
+
+
{-
Note [Adding the implicit parameter to 'assert']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1374,48 +1461,105 @@ Usually that coercion is hidden inside the wrappers for
constructors of F [Int] but here we have to do it explicitly.
It's all grotesquely complicated.
+
+Note [Instantiating stupid theta]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Normally, when we infer the type of an Id, we don't instantiate,
+because we wish to allow for visible type application later on.
+But if a datacon has a stupid theta, we're a bit stuck. We need
+to emit the stupid theta constraints with instantiated types. It's
+difficult to defer this to the lazy instantiation, because a stupid
+theta has no spot to put it in a type. So we just instantiate eagerly
+in this case. Thus, users cannot use visible type application with
+a data constructor sporting a stupid theta. I won't feel so bad for
+the users that complain.
+
-}
-tcSeq :: SrcSpan -> Name -> LHsExpr Name -> LHsExpr Name
- -> TcRhoType -> TcM (HsExpr TcId)
+tcSeq :: SrcSpan -> Name -> [LHsExpr Name]
+ -> TcRhoType -> TcM (HsWrapper, LHsExpr TcId, [LHsExpr TcId])
-- (seq e1 e2) :: res_ty
-- We need a special typing rule because res_ty can be unboxed
-- See Note [Typing rule for seq]
-tcSeq loc fun_name arg1 arg2 res_ty
+tcSeq loc fun_name args res_ty
= do { fun <- tcLookupId fun_name
- ; (arg1', arg1_ty) <- tcInfer (tcMonoExpr arg1)
+ ; (arg1_ty, args1) <- case args of
+ (ty_arg_expr1 : args1)
+ | Just hs_ty_arg1 <- isLHsTypeExpr_maybe ty_arg_expr1
+ -> do { ty_arg1 <- tcHsTypeApp hs_ty_arg1 liftedTypeKind
+ ; return (ty_arg1, args1) }
+
+ _ -> do { arg_ty1 <- newFlexiTyVarTy liftedTypeKind
+ ; return (arg_ty1, args) }
+
+ ; (arg1, arg2) <- case args1 of
+ [ty_arg_expr2, term_arg1, term_arg2]
+ | Just hs_ty_arg2 <- isLHsTypeExpr_maybe ty_arg_expr2
+ -> do { lev_ty <- newFlexiTyVarTy levityTy
+ ; ty_arg2 <- tcHsTypeApp hs_ty_arg2 (tYPE lev_ty)
+ -- see Note [Typing rule for seq]
+ ; _ <- unifyType noThing ty_arg2 res_ty
+ ; return (term_arg1, term_arg2) }
+ [term_arg1, term_arg2] -> return (term_arg1, term_arg2)
+ _ -> too_many_args
+
+ ; arg1' <- tcMonoExpr arg1 arg1_ty
+ ; res_ty <- zonkTcType res_ty -- just in case we learned something
+ -- interesting about it
; arg2' <- tcMonoExpr arg2 res_ty
; let fun' = L loc (HsWrap ty_args (HsVar (L loc fun)))
ty_args = WpTyApp res_ty <.> WpTyApp arg1_ty
- ; return (HsApp (L loc (HsApp fun' arg1')) arg2') }
+ ; return (idHsWrapper, fun', [arg1', arg2']) }
+ where
+ too_many_args :: TcM a
+ too_many_args
+ = failWith $
+ hang (text "Too many type arguments to seq:")
+ 2 (sep (map pprParendExpr args))
-tcTagToEnum :: SrcSpan -> Name -> LHsExpr Name -> TcRhoType -> TcM (HsExpr TcId)
+
+tcTagToEnum :: SrcSpan -> Name -> [LHsExpr Name] -> TcRhoType
+ -> TcM (HsWrapper, LHsExpr TcId, [LHsExpr TcId])
-- tagToEnum# :: forall a. Int# -> a
-- See Note [tagToEnum#] Urgh!
-tcTagToEnum loc fun_name arg res_ty
- = do { fun <- tcLookupId fun_name
- ; ty' <- zonkTcType res_ty
-
- -- Check that the type is algebraic
- ; let mb_tc_app = tcSplitTyConApp_maybe ty'
- Just (tc, tc_args) = mb_tc_app
- ; checkTc (isJust mb_tc_app)
- (mk_error ty' doc1)
-
- -- Look through any type family
- ; fam_envs <- tcGetFamInstEnvs
- ; let (rep_tc, rep_args, coi) = tcLookupDataFamInst fam_envs tc tc_args
- -- coi :: tc tc_args ~R rep_tc rep_args
-
- ; checkTc (isEnumerationTyCon rep_tc)
- (mk_error ty' doc2)
-
- ; arg' <- tcMonoExpr arg intPrimTy
- ; let fun' = L loc (HsWrap (WpTyApp rep_ty) (HsVar (L loc fun)))
- rep_ty = mkTyConApp rep_tc rep_args
-
- ; return (mkHsWrapCoR (mkTcSymCo coi) $ HsApp fun' arg') }
- -- coi is a Representational coercion
+tcTagToEnum loc fun_name args res_ty
+ = do { fun <- tcLookupId fun_name
+
+ ; arg <- case args of
+ [ty_arg_expr, term_arg]
+ | Just hs_ty_arg <- isLHsTypeExpr_maybe ty_arg_expr
+ -> do { ty_arg <- tcHsTypeApp hs_ty_arg liftedTypeKind
+ ; _ <- unifyType noThing ty_arg res_ty
+ -- other than influencing res_ty, we just
+ -- don't care about a type arg passed in.
+ -- So drop the evidence.
+ ; return term_arg }
+ [term_arg] -> return term_arg
+ _ -> too_many_args
+
+ ; ty' <- zonkTcType res_ty
+
+ -- Check that the type is algebraic
+ ; let mb_tc_app = tcSplitTyConApp_maybe ty'
+ Just (tc, tc_args) = mb_tc_app
+ ; checkTc (isJust mb_tc_app)
+ (mk_error ty' doc1)
+
+ -- Look through any type family
+ ; fam_envs <- tcGetFamInstEnvs
+ ; let (rep_tc, rep_args, coi)
+ = tcLookupDataFamInst fam_envs tc tc_args
+ -- coi :: tc tc_args ~R rep_tc rep_args
+
+ ; checkTc (isEnumerationTyCon rep_tc)
+ (mk_error ty' doc2)
+
+ ; arg' <- tcMonoExpr arg intPrimTy
+ ; let fun' = L loc (HsWrap (WpTyApp rep_ty) (HsVar (L loc fun)))
+ rep_ty = mkTyConApp rep_tc rep_args
+
+ ; return (mkWpCastR (mkTcSymCo coi), fun', [arg']) }
+ -- coi is a Representational coercion
where
doc1 = vcat [ ptext (sLit "Specify the type by giving a type signature")
, ptext (sLit "e.g. (tagToEnum# x) :: Bool") ]
@@ -1427,6 +1571,12 @@ tcTagToEnum loc fun_name arg res_ty
<+> ptext (sLit "at type") <+> ppr ty)
2 what
+ too_many_args :: TcM a
+ too_many_args
+ = failWith $
+ hang (text "Too many type arguments to tagToEnum#:")
+ 2 (sep (map pprParendExpr args))
+
{-
************************************************************************
* *
@@ -1643,7 +1793,7 @@ See also Note [HsRecField and HsRecUpdField] in HsPat.
-- Given a RdrName that refers to multiple record fields, and the type
-- of its argument, try to determine the name of the selector that is
-- meant.
-disambiguateSelector :: Located RdrName -> Type -> RnM Name
+disambiguateSelector :: Located RdrName -> Type -> TcM Name
disambiguateSelector lr@(L _ rdr) parent_type
= do { fam_inst_envs <- tcGetFamInstEnvs
; case tyConOf fam_inst_envs parent_type of
@@ -1658,7 +1808,7 @@ disambiguateSelector lr@(L _ rdr) parent_type
-- This field name really is ambiguous, so add a suitable "ambiguous
-- occurrence" error, then give up.
-ambiguousSelector :: Located RdrName -> RnM a
+ambiguousSelector :: Located RdrName -> TcM a
ambiguousSelector (L _ rdr)
= do { env <- getGlobalRdrEnv
; let gres = lookupGRE_RdrName rdr env
@@ -1667,10 +1817,10 @@ ambiguousSelector (L _ rdr)
-- Disambiguate the fields in a record update.
-- See Note [Disambiguating record fields]
-disambiguateRecordBinds :: LHsExpr Name -> TcType
+disambiguateRecordBinds :: LHsExpr Name -> TcRhoType
-> [LHsRecUpdField Name] -> Type
-> TcM [LHsRecField' (AmbiguousFieldOcc Id) (LHsExpr Name)]
-disambiguateRecordBinds record_expr record_tau rbnds res_ty
+disambiguateRecordBinds record_expr record_rho rbnds res_ty
-- Are all the fields unambiguous?
= case mapM isUnambiguous rbnds of
-- If so, just skip to looking up the Ids
@@ -1718,7 +1868,7 @@ disambiguateRecordBinds record_expr record_tau rbnds res_ty
-- Does the expression being updated have a type signature?
-- If so, try to extract a parent TyCon from it
| Just {} <- obviousSig (unLoc record_expr)
- , Just tc <- tyConOf fam_inst_envs record_tau
+ , Just tc <- tyConOf fam_inst_envs record_rho
-> return (RecSelData tc)
-- Nothing else we can try...
@@ -1946,36 +2096,47 @@ fieldCtxt :: FieldLabelString -> SDoc
fieldCtxt field_name
= ptext (sLit "In the") <+> quotes (ppr field_name) <+> ptext (sLit "field of a record")
-funResCtxt :: Bool -- There is at least one argument
- -> HsExpr Name -> TcType -> TcType
- -> TidyEnv -> TcM (TidyEnv, MsgDoc)
+addFunResCtxt :: Bool -- There is at least one argument
+ -> HsExpr Name -> TcType -> TcType
+ -> TcM a -> TcM a
-- When we have a mis-match in the return type of a function
-- try to give a helpful message about too many/few arguments
--
-- Used for naked variables too; but with has_args = False
-funResCtxt has_args fun fun_res_ty env_ty tidy_env
- = do { fun_res' <- zonkTcType fun_res_ty
- ; env' <- zonkTcType env_ty
- ; let (args_fun, res_fun) = tcSplitFunTys fun_res'
- (args_env, res_env) = tcSplitFunTys env'
- n_fun = length args_fun
- n_env = length args_env
- info | n_fun == n_env = Outputable.empty
- | n_fun > n_env
- , not_fun res_env = ptext (sLit "Probable cause:") <+> quotes (ppr fun)
- <+> ptext (sLit "is applied to too few arguments")
- | has_args
- , not_fun res_fun = ptext (sLit "Possible cause:") <+> quotes (ppr fun)
- <+> ptext (sLit "is applied to too many arguments")
- | otherwise = Outputable.empty -- Never suggest that a naked variable is
- -- applied to too many args!
- ; return (tidy_env, info) }
+addFunResCtxt has_args fun fun_res_ty env_ty
+ = addLandmarkErrCtxtM (\env -> (env, ) <$> mk_msg)
+ -- NB: use a landmark error context, so that an empty context
+ -- doesn't suppress some more useful context
where
- not_fun ty -- ty is definitely not an arrow type,
- -- and cannot conceivably become one
- = case tcSplitTyConApp_maybe ty of
- Just (tc, _) -> isAlgTyCon tc
- Nothing -> False
+ mk_msg
+ = do { fun_res' <- zonkTcType fun_res_ty
+ ; env' <- zonkTcType env_ty
+ ; let (_, _, fun_tau) = tcSplitSigmaTy fun_res'
+ (_, _, env_tau) = tcSplitSigmaTy env'
+ (args_fun, res_fun) = tcSplitFunTys fun_tau
+ (args_env, res_env) = tcSplitFunTys env_tau
+ n_fun = length args_fun
+ n_env = length args_env
+ info | n_fun == n_env = Outputable.empty
+ | n_fun > n_env
+ , not_fun res_env
+ = ptext (sLit "Probable cause:") <+> quotes (ppr fun)
+ <+> ptext (sLit "is applied to too few arguments")
+
+ | has_args
+ , not_fun res_fun
+ = ptext (sLit "Possible cause:") <+> quotes (ppr fun)
+ <+> ptext (sLit "is applied to too many arguments")
+
+ | otherwise
+ = Outputable.empty -- Never suggest that a naked variable is -- applied to too many args!
+ ; return info }
+ where
+ not_fun ty -- ty is definitely not an arrow type,
+ -- and cannot conceivably become one
+ = case tcSplitTyConApp_maybe ty of
+ Just (tc, _) -> isAlgTyCon tc
+ Nothing -> False
badFieldTypes :: [(FieldLabelString,TcType)] -> SDoc
badFieldTypes prs
diff --git a/compiler/typecheck/TcExpr.hs-boot b/compiler/typecheck/TcExpr.hs-boot
index acd5d8a747..8d60ba4662 100644
--- a/compiler/typecheck/TcExpr.hs-boot
+++ b/compiler/typecheck/TcExpr.hs-boot
@@ -14,7 +14,11 @@ tcMonoExpr, tcMonoExprNC ::
-> TcRhoType
-> TcM (LHsExpr TcId)
-tcInferRho, tcInferRhoNC ::
+tcInferSigma, tcInferSigmaNC ::
+ LHsExpr Name
+ -> TcM (LHsExpr TcId, TcSigmaType)
+
+tcInferRho ::
LHsExpr Name
-> TcM (LHsExpr TcId, TcRhoType)
diff --git a/compiler/typecheck/TcGenDeriv.hs b/compiler/typecheck/TcGenDeriv.hs
index 009d203128..ad36167a69 100644
--- a/compiler/typecheck/TcGenDeriv.hs
+++ b/compiler/typecheck/TcGenDeriv.hs
@@ -1639,10 +1639,10 @@ functorLikeTraverse var (FT { ft_triv = caseTrivial, ft_var = caseVar
| otherwise = (caseWrongArg, True) -- Non-decomposable (eg type function)
where
(xrs,xcs) = unzip (map (go co) args)
- go co (ForAllTy (Named v Invisible) x) | v /= var && xc = (caseForAll v xr,True)
+ go _ (ForAllTy (Named _ Visible) _) = panic "unexpected visible binder"
+ go co (ForAllTy (Named v _) x) | v /= var && xc = (caseForAll v xr,True)
where (xr,xc) = go co x
- go _ (ForAllTy (Named _ Visible) _) = panic "unexpected visible binder"
go _ _ = (caseTrivial,False)
-- Return all syntactic subterms of ty that contain var somewhere
@@ -2052,7 +2052,7 @@ genAuxBindSpec loc (DerivCon2Tag tycon)
rdr_name = con2tag_RDR tycon
sig_ty = mkLHsSigWcType $ L loc $ HsCoreTy $
- mkInvSigmaTy (tyConTyVars tycon) (tyConStupidTheta tycon) $
+ mkSpecSigmaTy (tyConTyVars tycon) (tyConStupidTheta tycon) $
mkParentType tycon `mkFunTy` intPrimTy
lots_of_constructors = tyConFamilySize tycon > 8
@@ -2076,7 +2076,7 @@ genAuxBindSpec loc (DerivTag2Con tycon)
L loc (TypeSig [L loc rdr_name] sig_ty))
where
sig_ty = mkLHsSigWcType $ L loc $
- HsCoreTy $ mkInvForAllTys (tyConTyVars tycon) $
+ HsCoreTy $ mkSpecForAllTys (tyConTyVars tycon) $
intTy `mkFunTy` mkParentType tycon
rdr_name = tag2con_RDR tycon
diff --git a/compiler/typecheck/TcHsSyn.hs b/compiler/typecheck/TcHsSyn.hs
index ee7038d546..210b1798e6 100644
--- a/compiler/typecheck/TcHsSyn.hs
+++ b/compiler/typecheck/TcHsSyn.hs
@@ -320,6 +320,7 @@ zonkTyBndrX :: ZonkEnv -> TyVar -> TcM (ZonkEnv, TyVar)
zonkTyBndrX env tv
= ASSERT( isImmutableTyVar tv )
do { ki <- zonkTcTypeToType env (tyVarKind tv)
+ -- Internal names tidy up better, for iface files.
; let tv' = mkTyVar (tyVarName tv) ki
; return (extendTyZonkEnv1 env tv', tv') }
@@ -433,12 +434,15 @@ zonk_bind env (AbsBinds { abs_tvs = tyvars, abs_ev_vars = evs
, abs_ev_binds = new_ev_binds
, abs_exports = new_exports, abs_binds = new_val_bind }) }
where
- zonkExport env (ABE{ abe_wrap = wrap, abe_poly = poly_id
+ zonkExport env (ABE{ abe_wrap = wrap, abe_inst_wrap = inst_wrap
+ , abe_poly = poly_id
, abe_mono = mono_id, abe_prags = prags })
= do new_poly_id <- zonkIdBndr env poly_id
(_, new_wrap) <- zonkCoFn env wrap
+ (_, new_inst_wrap) <- zonkCoFn env inst_wrap
new_prags <- zonkSpecPrags env prags
- return (ABE{ abe_wrap = new_wrap, abe_poly = new_poly_id
+ return (ABE{ abe_wrap = new_wrap, abe_inst_wrap = new_inst_wrap
+ , abe_poly = new_poly_id
, abe_mono = zonkIdOcc env mono_id
, abe_prags = new_prags })
@@ -731,6 +735,9 @@ zonkExpr env (HsWrap co_fn expr)
zonkExpr _ (HsUnboundVar v)
= return (HsUnboundVar v)
+ -- nothing to do here. The payload is an LHsType, not a Type.
+zonkExpr _ e@(HsTypeOut {}) = return e
+
zonkExpr _ expr = pprPanic "zonkExpr" (ppr expr)
-------------------------------------------------------------------------
@@ -740,10 +747,10 @@ zonkCmd :: ZonkEnv -> HsCmd TcId -> TcM (HsCmd Id)
zonkLCmd env cmd = wrapLocM (zonkCmd env) cmd
-zonkCmd env (HsCmdCast co cmd)
- = do { co' <- zonkCoToCo env co
- ; cmd' <- zonkCmd env cmd
- ; return (HsCmdCast co' cmd') }
+zonkCmd env (HsCmdWrap w cmd)
+ = do { (env1, w') <- zonkCoFn env w
+ ; cmd' <- zonkCmd env1 cmd
+ ; return (HsCmdWrap w' cmd') }
zonkCmd env (HsCmdArrApp e1 e2 ty ho rl)
= do new_e1 <- zonkLExpr env e1
new_e2 <- zonkLExpr env e2
@@ -811,11 +818,10 @@ zonkCoFn env WpHole = return (env, WpHole)
zonkCoFn env (WpCompose c1 c2) = do { (env1, c1') <- zonkCoFn env c1
; (env2, c2') <- zonkCoFn env1 c2
; return (env2, WpCompose c1' c2') }
-zonkCoFn env (WpFun c1 c2 t1 t2) = do { (env1, c1') <- zonkCoFn env c1
- ; (env2, c2') <- zonkCoFn env1 c2
- ; t1' <- zonkTcTypeToType env2 t1
- ; t2' <- zonkTcTypeToType env2 t2
- ; return (env2, WpFun c1' c2' t1' t2') }
+zonkCoFn env (WpFun c1 c2 t1) = do { (env1, c1') <- zonkCoFn env c1
+ ; (env2, c2') <- zonkCoFn env1 c2
+ ; t1' <- zonkTcTypeToType env2 t1
+ ; return (env2, WpFun c1' c2' t1') }
zonkCoFn env (WpCast co) = do { co' <- zonkCoToCo env co
; return (env, WpCast co') }
zonkCoFn env (WpEvLam ev) = do { (env', ev') <- zonkEvBndrX env ev
diff --git a/compiler/typecheck/TcHsType.hs b/compiler/typecheck/TcHsType.hs
index 769c45f43d..6214a8a94d 100644
--- a/compiler/typecheck/TcHsType.hs
+++ b/compiler/typecheck/TcHsType.hs
@@ -15,6 +15,7 @@ module TcHsType (
tcHsClsInstType,
tcHsDeriv, tcHsVectInst,
+ tcHsTypeApp,
UserTypeCtxt(..),
tcImplicitTKBndrs, tcImplicitTKBndrsType, tcHsTyVarBndrs,
@@ -202,7 +203,7 @@ tc_hs_sig_type (HsIB { hsib_body = hs_ty
= do { (tkvs, ty) <- solveEqualities $
tcImplicitTKBndrsType sig_vars $
tc_lhs_type typeLevelMode hs_ty kind
- ; return (mkInvForAllTys tkvs ty) }
+ ; return (mkSpecForAllTys tkvs ty) }
-----------------
tcHsDeriv :: LHsSigType Name -> TcM ([TyVar], Class, [Type], Kind)
@@ -244,7 +245,7 @@ tcHsClsInstType user_ctxt hs_inst_ty@(HsIB { hsib_vars = sig_vars
; head_ty' <- tc_lhs_type typeLevelMode
head_ty constraintKind
; return (mkPhiTy theta head_ty') }
- ; let inst_ty = mkInvForAllTys tkvs phi_ty
+ ; let inst_ty = mkSpecForAllTys tkvs phi_ty
; inst_ty <- kindGeneralizeType inst_ty
; inst_ty <- zonkTcType inst_ty
; checkValidInstance user_ctxt hs_inst_ty inst_ty }
@@ -267,6 +268,21 @@ tcHsVectInst ty
| otherwise
= failWithTc $ ptext (sLit "Malformed instance type")
+----------------------------------------------
+-- | Type-check a visible type application
+tcHsTypeApp :: LHsWcType Name -> Kind -> TcM Type
+tcHsTypeApp wc_ty kind
+ | HsWC { hswc_wcs = sig_wcs, hswc_ctx = extra, hswc_body = hs_ty } <- wc_ty
+ = ASSERT( isNothing extra ) -- handled in RnTypes.rnExtraConstraintWildCard
+ tcWildCardBinders sig_wcs $ \ _ ->
+ do { ty <- tcCheckLHsType hs_ty kind
+ ; ty <- zonkTcType ty
+ ; checkValidType TypeAppCtxt ty
+ ; return ty }
+ -- NB: we don't call emitWildcardHoleConstraints here, because
+ -- we want any holes in visible type applications to be used
+ -- without fuss. No errors, warnings, extensions, etc.
+
{-
These functions are used during knot-tying in
type and class declarations, when we have to
@@ -504,7 +520,7 @@ tc_hs_type mode hs_ty@(HsForAllTy { hst_bndrs = hs_tvs, hst_body = ty }) exp_kin
-- Why exp_kind? See Note [Body kind of forall]
do { ty' <- tc_lhs_type mode ty exp_kind
; let bound_vars = allBoundVariables ty'
- ; return (mkNakedInvSigmaTy tvs' [] ty', bound_vars) }
+ ; return (mkNakedSpecSigmaTy tvs' [] ty', bound_vars) }
tc_hs_type mode (HsQualTy { hst_ctxt = ctxt, hst_body = ty }) exp_kind
= do { ctxt' <- tc_hs_context mode ctxt
@@ -1275,12 +1291,15 @@ kcHsTyVarBndrs cusk (HsQTvs { hsq_implicit = kv_ns
do { (full_kind, _, stuff) <- bind_telescope hs_tvs (thing_inside kvs)
; let qkvs = filter (not . isMetaTyVar) $
tyCoVarsOfTypeWellScoped full_kind
+ -- these have to be the vars made with new_skolem_tv
+ -- above. Thus, they are known to the user and should
+ -- be Specified, not Invisible, when kind-generalizing
-- the free non-meta variables in the returned kind will
-- contain both *mentioned* kind vars and *unmentioned* kind
-- vars (See case (1) under Note [Typechecking telescopes])
gen_kind = if cusk
- then mkInvForAllTys qkvs $ full_kind
+ then mkSpecForAllTys qkvs $ full_kind
else full_kind
; return (gen_kind, stuff) } }
where
diff --git a/compiler/typecheck/TcInstDcls.hs b/compiler/typecheck/TcInstDcls.hs
index 3b931711c3..007abf0804 100644
--- a/compiler/typecheck/TcInstDcls.hs
+++ b/compiler/typecheck/TcInstDcls.hs
@@ -872,7 +872,8 @@ tcInstDecl2 (InstInfo { iSpec = ispec, iBinds = ibinds })
| otherwise
= SpecPrags spec_inst_prags
- export = ABE { abe_wrap = idHsWrapper, abe_poly = dfun_id
+ export = ABE { abe_wrap = idHsWrapper, abe_inst_wrap = idHsWrapper
+ , abe_poly = dfun_id
, abe_mono = self_dict, abe_prags = dfun_spec_prags }
-- NB: see Note [SPECIALISE instance pragmas]
main_bind = AbsBinds { abs_tvs = inst_tyvars
@@ -986,7 +987,9 @@ tcSuperClasses dfun_id cls tyvars dfun_evs inst_tys dfun_ev_binds _fam_envs sc_t
; addTcEvBind ev_binds_var $ mkWantedEvBind sc_ev_id sc_ev_tm
; let sc_top_ty = mkInvForAllTys tyvars (mkPiTypes dfun_evs sc_pred)
sc_top_id = mkLocalId sc_top_name sc_top_ty
- export = ABE { abe_wrap = idHsWrapper, abe_poly = sc_top_id
+ export = ABE { abe_wrap = idHsWrapper
+ , abe_inst_wrap = idHsWrapper
+ , abe_poly = sc_top_id
, abe_mono = sc_ev_id
, abe_prags = SpecPrags [] }
local_ev_binds = TcEvBinds ev_binds_var
@@ -1318,7 +1321,8 @@ tcMethods dfun_id clas tyvars dfun_ev_vars inst_tys
-- method to this version. Note [INLINE and default methods]
- export = ABE { abe_wrap = hs_wrap, abe_poly = meth_id1
+ export = ABE { abe_wrap = hs_wrap, abe_inst_wrap = idHsWrapper
+ , abe_poly = meth_id1
, abe_mono = local_meth_id
, abe_prags = mk_meth_spec_prags meth_id1 spec_inst_prags [] }
bind = AbsBinds { abs_tvs = tyvars, abs_ev_vars = dfun_ev_vars
@@ -1374,10 +1378,11 @@ tcMethodBody clas tyvars dfun_ev_vars inst_tys
(L bind_loc lm_bind)
; let specs = mk_meth_spec_prags global_meth_id spec_inst_prags spec_prags
- export = ABE { abe_poly = global_meth_id
- , abe_mono = local_meth_id
- , abe_wrap = hs_wrap
- , abe_prags = specs }
+ export = ABE { abe_poly = global_meth_id
+ , abe_mono = local_meth_id
+ , abe_wrap = hs_wrap
+ , abe_inst_wrap = idHsWrapper
+ , abe_prags = specs }
local_ev_binds = TcEvBinds ev_binds_var
full_bind = AbsBinds { abs_tvs = tyvars
@@ -1417,7 +1422,7 @@ mkMethIds sig_fn clas tyvars dfun_ev_vars inst_tys sel_id
do { inst_sigs <- xoptM LangExt.InstanceSigs
; checkTc inst_sigs (misplacedInstSig sel_name lhs_ty)
; sig_ty <- tcHsSigType (FunSigCtxt sel_name False) lhs_ty
- ; let poly_sig_ty = mkInvSigmaTy tyvars theta sig_ty
+ ; let poly_sig_ty = mkSpecSigmaTy tyvars theta sig_ty
ctxt = FunSigCtxt sel_name True
; tc_sig <- instTcTySig ctxt lhs_ty sig_ty local_meth_name
; hs_wrap <- addErrCtxtM (methSigCtxt sel_name poly_sig_ty poly_meth_ty) $
@@ -1438,7 +1443,7 @@ mkMethIds sig_fn clas tyvars dfun_ev_vars inst_tys sel_id
sel_name = idName sel_id
sel_occ = nameOccName sel_name
local_meth_ty = instantiateMethod clas sel_id inst_tys
- poly_meth_ty = mkInvSigmaTy tyvars theta local_meth_ty
+ poly_meth_ty = mkSpecSigmaTy tyvars theta local_meth_ty
theta = map idType dfun_ev_vars
methSigCtxt :: Name -> TcType -> TcType -> TidyEnv -> TcM (TidyEnv, MsgDoc)
diff --git a/compiler/typecheck/TcMType.hs b/compiler/typecheck/TcMType.hs
index 9285f9ae22..cacaab23d8 100644
--- a/compiler/typecheck/TcMType.hs
+++ b/compiler/typecheck/TcMType.hs
@@ -21,11 +21,11 @@ module TcMType (
newFlexiTyVarTys, -- Int -> Kind -> TcM [TcType]
newOpenFlexiTyVarTy,
newReturnTyVar, newReturnTyVarTy,
- newMaybeReturnTyVarTy,
newOpenReturnTyVar,
newMetaKindVar, newMetaKindVars,
cloneMetaTyVar,
newFmvTyVar, newFskTyVar,
+ tauTvForReturnTv,
readMetaTyVar, writeMetaTyVar, writeMetaTyVarRef,
newMetaDetails, isFilledMetaTyVar, isUnfilledMetaTyVar,
@@ -632,12 +632,6 @@ newReturnTyVar kind = newAnonMetaTyVar ReturnTv kind
newReturnTyVarTy :: Kind -> TcM TcType
newReturnTyVarTy kind = mkTyVarTy <$> newReturnTyVar kind
--- | Either makes a normal Flexi or a ReturnTv Flexi
-newMaybeReturnTyVarTy :: Bool -- True <=> make a ReturnTv
- -> Kind -> TcM TcType
-newMaybeReturnTyVarTy True = newReturnTyVarTy
-newMaybeReturnTyVarTy False = newFlexiTyVarTy
-
-- | Create a tyvar that can be a lifted or unlifted type.
newOpenFlexiTyVarTy :: TcM TcType
newOpenFlexiTyVarTy
@@ -652,6 +646,23 @@ newOpenReturnTyVar
; tv <- newReturnTyVar k
; return (tv, k) }
+-- | If the type is a ReturnTv, fill it with a new meta-TauTv. Otherwise,
+-- no change. This function can look through ReturnTvs and returns a partially
+-- zonked type as an optimisation.
+tauTvForReturnTv :: TcType -> TcM TcType
+tauTvForReturnTv ty
+ | Just tv <- tcGetTyVar_maybe ty
+ , isReturnTyVar tv
+ = do { contents <- readMetaTyVar tv
+ ; case contents of
+ Flexi -> do { tau_ty <- newFlexiTyVarTy (tyVarKind tv)
+ ; writeMetaTyVar tv tau_ty
+ ; return tau_ty }
+ Indirect ty -> tauTvForReturnTv ty }
+ | otherwise
+ = ASSERT( all (not . isReturnTyVar) (tyCoVarsOfTypeList ty) )
+ return ty
+
newMetaSigTyVars :: [TyVar] -> TcM (TCvSubst, [TcTyVar])
newMetaSigTyVars = mapAccumLM newMetaSigTyVarX emptyTCvSubst
@@ -671,9 +682,8 @@ newMetaTyVarX :: TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
newMetaTyVarX subst tyvar
= do { uniq <- newUnique
-- See Note [Levity polymorphic variables accept foralls]
- ; let info = if isLevityPolymorphic (tyVarKind tyvar)
- then ReturnTv
- else TauTv
+ ; let info | isLevityPolymorphic (tyVarKind tyvar) = ReturnTv
+ | otherwise = TauTv
; details <- newMetaDetails info
; let name = mkSystemName uniq (getOccName tyvar)
-- See Note [Name of an instantiated type variable]
diff --git a/compiler/typecheck/TcMatches.hs b/compiler/typecheck/TcMatches.hs
index 323adceaaa..2e4078b4ee 100644
--- a/compiler/typecheck/TcMatches.hs
+++ b/compiler/typecheck/TcMatches.hs
@@ -9,6 +9,7 @@ TcMatches: Typecheck some @Matches@
{-# LANGUAGE CPP #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE MultiWayIf #-}
+{-# LANGUAGE TupleSections #-}
module TcMatches ( tcMatchesFun, tcGRHS, tcGRHSsPat, tcMatchesCase, tcMatchLambda,
TcMatchCtxt(..), TcStmtChecker, TcExprStmtChecker, TcCmdStmtChecker,
@@ -16,11 +17,10 @@ module TcMatches ( tcMatchesFun, tcGRHS, tcGRHSsPat, tcMatchesCase, tcMatchLambd
tcDoStmt, tcGuardStmt
) where
-import {-# SOURCE #-} TcExpr( tcSyntaxOp, tcInferRhoNC, tcInferRho, tcCheckId,
- tcMonoExpr, tcMonoExprNC, tcPolyExpr )
+import {-# SOURCE #-} TcExpr( tcSyntaxOp, tcInferSigmaNC, tcInferSigma
+ , tcCheckId, tcMonoExpr, tcMonoExprNC, tcPolyExpr )
import HsSyn
-import BasicTypes
import TcRnMonad
import TcEnv
import TcPat
@@ -47,6 +47,10 @@ import MkCore
import Control.Monad
+#if __GLASGOW_HASKELL__ < 709
+import Data.Traversable ( traverse )
+#endif
+
#include "HsVersions.h"
{-
@@ -64,7 +68,7 @@ same number of arguments before using @tcMatches@ to do the work.
Note [Polymorphic expected type for tcMatchesFun]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tcMatchesFun may be given a *sigma* (polymorphic) type
-so it must be prepared to use tcGen to skolemise it.
+so it must be prepared to use tcSkolemise to skolemise it.
See Note [sig_tau may be polymorphic] in TcPat.
-}
@@ -83,11 +87,14 @@ tcMatchesFun fun_name matches exp_ty
traceTc "tcMatchesFun" (ppr fun_name $$ ppr exp_ty)
; checkArgs fun_name matches
+ ; exp_ty <- tauifyMultipleMatches matches exp_ty
; (wrap_gen, (wrap_fun, group))
- <- tcGen (FunSigCtxt fun_name True) exp_ty $ \ _ exp_rho ->
+ <- tcSkolemise (FunSigCtxt fun_name True) exp_ty $ \ _ exp_rho ->
-- Note [Polymorphic expected type for tcMatchesFun]
- matchFunTys herald arity exp_rho $ \ pat_tys rhs_ty ->
- tcMatches match_ctxt pat_tys rhs_ty matches
+ do { (wrap_fun, pat_tys, rhs_ty)
+ <- matchExpectedFunTys herald arity exp_rho
+ ; matches' <- tcMatches match_ctxt pat_tys rhs_ty matches
+ ; return (wrap_fun, matches') }
; return (wrap_gen <.> wrap_fun, group) }
where
arity = matchGroupArity matches
@@ -102,33 +109,38 @@ parser guarantees that each equation has exactly one argument.
tcMatchesCase :: (Outputable (body Name)) =>
TcMatchCtxt body -- Case context
- -> TcRhoType -- Type of scrutinee
+ -> TcSigmaType -- Type of scrutinee
-> MatchGroup Name (Located (body Name)) -- The case alternatives
-> TcRhoType -- Type of whole case expressions
- -> TcM (MatchGroup TcId (Located (body TcId))) -- Translated alternatives
+ -> TcM (MatchGroup TcId (Located (body TcId)))
+ -- Translated alternatives
+ -- wrapper goes from MatchGroup's ty to expected ty
tcMatchesCase ctxt scrut_ty matches res_ty
| isEmptyMatchGroup matches -- Allow empty case expressions
- = return (MG { mg_alts = noLoc [], mg_arg_tys = [scrut_ty]
- , mg_res_ty = res_ty, mg_origin = mg_origin matches })
+ = return (MG { mg_alts = noLoc []
+ , mg_arg_tys = [scrut_ty]
+ , mg_res_ty = res_ty
+ , mg_origin = mg_origin matches })
| otherwise
- = tcMatches ctxt [scrut_ty] res_ty matches
-
-tcMatchLambda :: MatchGroup Name (LHsExpr Name) -> TcRhoType
- -> TcM (HsWrapper, MatchGroup TcId (LHsExpr TcId))
-tcMatchLambda match res_ty
- = matchFunTys herald n_pats res_ty $ \ pat_tys rhs_ty ->
- tcMatches match_ctxt pat_tys rhs_ty match
+ = do { res_ty <- tauifyMultipleMatches matches res_ty
+ ; tcMatches ctxt [scrut_ty] res_ty matches }
+
+tcMatchLambda :: SDoc -- see Note [Herald for matchExpectedFunTys] in TcUnify
+ -> TcMatchCtxt HsExpr
+ -> MatchGroup Name (LHsExpr Name)
+ -> TcRhoType -- deeply skolemised
+ -> TcM (HsWrapper, [TcSigmaType], MatchGroup TcId (LHsExpr TcId))
+ -- also returns the argument types
+tcMatchLambda herald match_ctxt match res_ty
+ = do { res_ty <- tauifyMultipleMatches match res_ty
+ ; (wrap, pat_tys, rhs_ty) <- matchExpectedFunTys herald n_pats res_ty
+ ; match' <- tcMatches match_ctxt pat_tys rhs_ty match
+ ; return (wrap, pat_tys, match') }
where
- n_pats = matchGroupArity match
- herald = sep [ ptext (sLit "The lambda expression")
- <+> quotes (pprSetDepth (PartWay 1) $
- pprMatches (LambdaExpr :: HsMatchContext Name) match),
- -- The pprSetDepth makes the abstraction print briefly
- ptext (sLit "has")]
- match_ctxt = MC { mc_what = LambdaExpr,
- mc_body = tcBody }
+ n_pats | isEmptyMatchGroup match = 1 -- must be lambda-case
+ | otherwise = matchGroupArity match
-- @tcGRHSsPat@ typechecks @[GRHSs]@ that occur in a @PatMonoBind@.
@@ -140,29 +152,59 @@ tcGRHSsPat grhss res_ty = tcGRHSs match_ctxt grhss res_ty
match_ctxt = MC { mc_what = PatBindRhs,
mc_body = tcBody }
-matchFunTys
- :: SDoc -- See Note [Herald for matchExpecteFunTys] in TcUnify
- -> Arity
- -> TcRhoType
- -> ([TcSigmaType] -> TcRhoType -> TcM a)
- -> TcM (HsWrapper, a)
-
--- Written in CPS style for historical reasons;
--- could probably be un-CPSd, like matchExpectedTyConApp
-
-matchFunTys herald arity res_ty thing_inside
- = do { (co, pat_tys, res_ty) <- matchExpectedFunTys herald arity res_ty
- ; res <- thing_inside pat_tys res_ty
- ; return (mkWpCastN (mkTcSymCo co), res) }
-
{-
************************************************************************
* *
\subsection{tcMatch}
* *
************************************************************************
+
+Note [Case branches must be taus]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider
+
+ case ... of
+ ... -> \(x :: forall a. a -> a) -> x
+ ... -> \y -> y
+
+Should that type-check? The problem is that, if we check the second branch
+first, then we'll get a type (b -> b) for the branches, which won't unify
+with the polytype in the first branch. If we check the first branch first,
+then everything is OK. This order-dependency is terrible. So we want only
+proper tau-types in branches. This is what tauTvForReturnsTv ensures:
+it gets rid of those pesky ReturnTvs that might unify with polytypes.
+
+An even trickier case looks like
+
+ f x True = x undefined
+ f x False = x ()
+
+Here, we see that the arguments must also be non-ReturnTvs. Thus, we must
+tauify before calling matchFunTys.
+
+But we make a special case for a one-branch case. This is so that
+
+ f = \(x :: forall a. a -> a) -> x
+
+still gets assigned a polytype.
-}
+-- | When the MatchGroup has multiple RHSs, convert any ReturnTvs in the
+-- expected type into TauTvs.
+-- See Note [Case branches must be taus]
+tauifyMultipleMatches :: MatchGroup id body
+ -> TcType
+ -> TcM TcType
+tauifyMultipleMatches group exp_ty
+ | isSingletonMatchGroup group
+ = return exp_ty
+
+ | otherwise
+ = tauTvForReturnTv exp_ty
+
+-- | Type-check a MatchGroup. If there are multiple RHSs, the expected type
+-- must already be tauified. See Note [Case branches must be taus] and
+-- tauifyMultipleMatches
tcMatches :: (Outputable (body Name)) => TcMatchCtxt body
-> [TcSigmaType] -- Expected pattern types
-> TcRhoType -- Expected result-type of the Match.
@@ -176,11 +218,14 @@ data TcMatchCtxt body -- c.f. TcStmtCtxt, also in this module
-> TcRhoType
-> TcM (Located (body TcId)) }
-tcMatches ctxt pat_tys rhs_ty (MG { mg_alts = L l matches, mg_origin = origin })
+tcMatches ctxt pat_tys rhs_ty (MG { mg_alts = L l matches
+ , mg_origin = origin })
= ASSERT( not (null matches) ) -- Ensure that rhs_ty is filled in
- do { matches' <- mapM (tcMatch ctxt pat_tys rhs_ty) matches
- ; return (MG { mg_alts = L l matches', mg_arg_tys = pat_tys
- , mg_res_ty = rhs_ty, mg_origin = origin }) }
+ do { matches' <- mapM (tcMatch ctxt pat_tys rhs_ty) matches
+ ; return (MG { mg_alts = L l matches'
+ , mg_arg_tys = pat_tys
+ , mg_res_ty = rhs_ty
+ , mg_origin = origin }) }
-------------
tcMatch :: (Outputable (body Name)) => TcMatchCtxt body
@@ -223,8 +268,9 @@ tcGRHSs :: TcMatchCtxt body -> GRHSs Name (Located (body Name)) -> TcRhoType
-- but we don't need to do that any more
tcGRHSs ctxt (GRHSs grhss (L l binds)) res_ty
- = do { (binds', grhss') <- tcLocalBinds binds $
- mapM (wrapLocM (tcGRHS ctxt res_ty)) grhss
+ = do { (binds', grhss')
+ <- tcLocalBinds binds $
+ mapM (wrapLocM (tcGRHS ctxt res_ty)) grhss
; return (GRHSs grhss' (L l binds')) }
@@ -233,8 +279,9 @@ tcGRHS :: TcMatchCtxt body -> TcRhoType -> GRHS Name (Located (body Name))
-> TcM (GRHS TcId (Located (body TcId)))
tcGRHS ctxt res_ty (GRHS guards rhs)
- = do { (guards', rhs') <- tcStmtsAndThen stmt_ctxt tcGuardStmt guards res_ty $
- mc_body ctxt rhs
+ = do { (guards', rhs')
+ <- tcStmtsAndThen stmt_ctxt tcGuardStmt guards res_ty $
+ mc_body ctxt rhs
; return (GRHS guards' rhs') }
where
stmt_ctxt = PatGuard (mc_what ctxt)
@@ -280,8 +327,7 @@ tcDoStmts ctxt _ _ = pprPanic "tcDoStmts" (pprStmtContext ctxt)
tcBody :: LHsExpr Name -> TcRhoType -> TcM (LHsExpr TcId)
tcBody body res_ty
= do { traceTc "tcBody" (ppr res_ty)
- ; body' <- tcMonoExpr body res_ty
- ; return body'
+ ; tcMonoExpr body res_ty
}
{-
@@ -348,9 +394,9 @@ tcStmtsAndThen ctxt stmt_chk (L loc stmt : stmts) res_ty thing_inside
| otherwise
= do { (stmt', (stmts', thing)) <-
setSrcSpan loc $
- addErrCtxt (pprStmtInCtxt ctxt stmt) $
+ addErrCtxt (pprStmtInCtxt ctxt stmt) $
stmt_chk ctxt stmt res_ty $ \ res_ty' ->
- popErrCtxt $
+ popErrCtxt $
tcStmtsAndThen ctxt stmt_chk stmts res_ty' $
thing_inside
; return (L loc stmt' : stmts', thing) }
@@ -366,8 +412,10 @@ tcGuardStmt _ (BodyStmt guard _ _ _) res_ty thing_inside
; return (BodyStmt guard' noSyntaxExpr noSyntaxExpr boolTy, thing) }
tcGuardStmt ctxt (BindStmt pat rhs _ _) res_ty thing_inside
- = do { (rhs', rhs_ty) <- tcInferRhoNC rhs -- Stmt has a context already
- ; (pat', thing) <- tcPat (StmtCtxt ctxt) pat rhs_ty $
+ = do { (rhs', rhs_ty) <- tcInferSigmaNC rhs
+ -- Stmt has a context already
+ ; (pat', thing) <- tcPat_O (StmtCtxt ctxt) (exprCtOrigin (unLoc rhs))
+ pat rhs_ty $
thing_inside res_ty
; return (BindStmt pat' rhs' noSyntaxExpr noSyntaxExpr, thing) }
@@ -437,9 +485,7 @@ tcLcStmt m_tc ctxt (TransStmt { trS_form = form, trS_stmts = stmts
-- passed in to tcStmtsAndThen is never looked at
; (stmts', (bndr_ids, by'))
<- tcStmtsAndThen (TransStmtCtxt ctxt) (tcLcStmt m_tc) stmts unused_ty $ \_ -> do
- { by' <- case by of
- Nothing -> return Nothing
- Just e -> do { e_ty <- tcInferRho e; return (Just e_ty) }
+ { by' <- traverse tcInferSigma by
; bndr_ids <- tcLookupLocalIds bndr_names
; return (bndr_ids, by') }
diff --git a/compiler/typecheck/TcPat.hs b/compiler/typecheck/TcPat.hs
index b951ad2197..a5da75c84d 100644
--- a/compiler/typecheck/TcPat.hs
+++ b/compiler/typecheck/TcPat.hs
@@ -11,12 +11,12 @@ TcPat: Typechecking patterns
module TcPat ( tcLetPat, TcSigFun
, TcPragEnv, lookupPragEnv, emptyPragEnv
, LetBndrSpec(..), addInlinePrags
- , tcPat, tcPats, newNoSigLetBndr
+ , tcPat, tcPat_O, tcPats, newNoSigLetBndr
, addDataConStupidTheta, badFieldCon, polyPatSig ) where
#include "HsVersions.h"
-import {-# SOURCE #-} TcExpr( tcSyntaxOp, tcInferRho)
+import {-# SOURCE #-} TcExpr( tcSyntaxOp, tcInferSigma )
import HsSyn
import TcHsSyn
@@ -67,7 +67,8 @@ tcLetPat sig_fn no_gen pat pat_ty thing_inside
= tc_lpat pat pat_ty penv thing_inside
where
penv = PE { pe_lazy = True
- , pe_ctxt = LetPat sig_fn no_gen }
+ , pe_ctxt = LetPat sig_fn no_gen
+ , pe_orig = PatOrigin }
-----------------
tcPats :: HsMatchContext Name
@@ -90,23 +91,31 @@ tcPats :: HsMatchContext Name
tcPats ctxt pats pat_tys thing_inside
= tc_lpats penv pats pat_tys thing_inside
where
- penv = PE { pe_lazy = False, pe_ctxt = LamPat ctxt }
+ penv = PE { pe_lazy = False, pe_ctxt = LamPat ctxt, pe_orig = PatOrigin }
tcPat :: HsMatchContext Name
-> LPat Name -> TcSigmaType
- -> TcM a -- Checker for body, given
- -- its result type
+ -> TcM a -- Checker for body
-> TcM (LPat TcId, a)
-tcPat ctxt pat pat_ty thing_inside
+tcPat ctxt = tcPat_O ctxt PatOrigin
+
+-- | A variant of 'tcPat' that takes a custom origin
+tcPat_O :: HsMatchContext Name
+ -> CtOrigin -- ^ origin to use if the type needs inst'ing
+ -> LPat Name -> TcSigmaType
+ -> TcM a -- Checker for body
+ -> TcM (LPat TcId, a)
+tcPat_O ctxt orig pat pat_ty thing_inside
= tc_lpat pat pat_ty penv thing_inside
where
- penv = PE { pe_lazy = False, pe_ctxt = LamPat ctxt }
+ penv = PE { pe_lazy = False, pe_ctxt = LamPat ctxt, pe_orig = orig }
-----------------
data PatEnv
= PE { pe_lazy :: Bool -- True <=> lazy context, so no existentials allowed
, pe_ctxt :: PatCtxt -- Context in which the whole pattern appears
+ , pe_orig :: CtOrigin -- origin to use if the pat_ty needs inst'ing
}
data PatCtxt
@@ -171,6 +180,8 @@ tcPatBndr (PE { pe_ctxt = LetPat lookup_sig no_gen}) bndr_name pat_ty
tcPatBndr (PE { pe_ctxt = _lam_or_proc }) bndr_name pat_ty
= return (mkTcNomReflCo pat_ty, mkLocalId bndr_name pat_ty)
+ -- whether or not there is a sig is irrelevant, as this
+ -- is local
------------
newNoSigLetBndr :: LetBndrSpec -> Name -> TcType -> TcM TcId
@@ -369,26 +380,20 @@ tc_pat penv (AsPat (L nm_loc name) pat) pat_ty thing_inside
tc_pat penv (ViewPat expr pat _) overall_pat_ty thing_inside
= do {
- -- Morally, expr must have type `forall a1...aN. OPT' -> B`
+ -- Expr must have type `forall a1...aN. OPT' -> B`
-- where overall_pat_ty is an instance of OPT'.
- -- Here, we infer a rho type for it,
- -- which replaces the leading foralls and constraints
- -- with fresh unification variables.
- ; (expr',expr'_inferred) <- tcInferRho expr
+ ; (expr',expr'_inferred) <- tcInferSigma expr
-- next, we check that expr is coercible to `overall_pat_ty -> pat_ty`
- -- NOTE: this forces pat_ty to be a monotype (because we use a unification
- -- variable to find it). this means that in an example like
- -- (view -> f) where view :: _ -> forall b. b
- -- we will only be able to use view at one instantation in the
- -- rest of the view
- ; (expr_co, pat_ty) <- tcInfer $ \ pat_ty ->
- unifyType (Just expr) expr'_inferred (mkFunTy overall_pat_ty pat_ty)
+ ; (expr_wrap, pat_ty) <- tcInfer $ \ pat_ty ->
+ tcSubTypeDS_O (exprCtOrigin (unLoc expr)) GenSigCtxt (Just expr)
+ expr'_inferred
+ (mkFunTy overall_pat_ty pat_ty)
-- pattern must have pat_ty
; (pat', res) <- tc_lpat pat pat_ty penv thing_inside
- ; return (ViewPat (mkLHsWrapCo expr_co expr') pat' overall_pat_ty, res) }
+ ; return (ViewPat (mkLHsWrap expr_wrap expr') pat' overall_pat_ty, res) }
-- Type signatures in patterns
-- See Note [Pattern coercions] below
@@ -403,7 +408,7 @@ tc_pat penv (SigPatIn pat sig_ty) pat_ty thing_inside
------------------------
-- Lists, tuples, arrays
tc_pat penv (ListPat pats _ Nothing) pat_ty thing_inside
- = do { (coi, elt_ty) <- matchExpectedPatTy matchExpectedListTyR pat_ty
+ = do { (coi, elt_ty) <- matchExpectedPatTy matchExpectedListTy penv pat_ty
; (pats', res) <- tcMultiple (\p -> tc_lpat p elt_ty)
pats penv thing_inside
; return (mkHsWrapPat coi (ListPat pats' elt_ty Nothing) pat_ty, res)
@@ -412,14 +417,14 @@ tc_pat penv (ListPat pats _ Nothing) pat_ty thing_inside
tc_pat penv (ListPat pats _ (Just (_,e))) pat_ty thing_inside
= do { list_pat_ty <- newFlexiTyVarTy liftedTypeKind
; e' <- tcSyntaxOp ListOrigin e (mkFunTy pat_ty list_pat_ty)
- ; (coi, elt_ty) <- matchExpectedPatTy matchExpectedListTyR list_pat_ty
+ ; (coi, elt_ty) <- matchExpectedPatTy matchExpectedListTy penv list_pat_ty
; (pats', res) <- tcMultiple (\p -> tc_lpat p elt_ty)
pats penv thing_inside
; return (mkHsWrapPat coi (ListPat pats' elt_ty (Just (pat_ty,e'))) list_pat_ty, res)
}
tc_pat penv (PArrPat pats _) pat_ty thing_inside
- = do { (coi, elt_ty) <- matchExpectedPatTy matchExpectedPArrTyR pat_ty
+ = do { (coi, elt_ty) <- matchExpectedPatTy matchExpectedPArrTy penv pat_ty
; (pats', res) <- tcMultiple (\p -> tc_lpat p elt_ty)
pats penv thing_inside
; return (mkHsWrapPat coi (PArrPat pats' elt_ty) pat_ty, res)
@@ -428,7 +433,8 @@ tc_pat penv (PArrPat pats _) pat_ty thing_inside
tc_pat penv (TuplePat pats boxity _) pat_ty thing_inside
= do { let arity = length pats
tc = tupleTyCon boxity arity
- ; (coi, arg_tys) <- matchExpectedPatTy (matchExpectedTyConAppR tc) pat_ty
+ ; (coi, arg_tys) <- matchExpectedPatTy (matchExpectedTyConApp tc)
+ penv pat_ty
-- Unboxed tuples have levity vars, which we discard:
-- See Note [Unboxed tuple levity vars] in TyCon
; let con_arg_tys = case boxity of Unboxed -> drop arity arg_tys
@@ -470,9 +476,10 @@ tc_pat _ (LitPat simple_lit) pat_ty thing_inside
------------------------
-- Overloaded patterns: n, and n+k
-tc_pat _ (NPat (L l over_lit) mb_neg eq) pat_ty thing_inside
+tc_pat (PE { pe_orig = pat_orig })
+ (NPat (L l over_lit) mb_neg eq) pat_ty thing_inside
= do { let orig = LiteralOrigin over_lit
- ; lit' <- newOverloadedLit orig over_lit pat_ty
+ ; (wrap, lit') <- newOverloadedLit over_lit pat_ty pat_orig
; eq' <- tcSyntaxOp orig eq (mkFunTys [pat_ty, pat_ty] boolTy)
; mb_neg' <- case mb_neg of
Nothing -> return Nothing -- Positive literal
@@ -481,18 +488,22 @@ tc_pat _ (NPat (L l over_lit) mb_neg eq) pat_ty thing_inside
do { neg' <- tcSyntaxOp orig neg (mkFunTy pat_ty pat_ty)
; return (Just neg') }
; res <- thing_inside
- ; return (NPat (L l lit') mb_neg' eq', res) }
+ ; return (mkHsWrapPat wrap (NPat (L l lit') mb_neg' eq') pat_ty, res) }
tc_pat penv (NPlusKPat (L nm_loc name) (L loc lit) ge minus) pat_ty thing_inside
= do { (co, bndr_id) <- setSrcSpan nm_loc (tcPatBndr penv name pat_ty)
; let pat_ty' = idType bndr_id
orig = LiteralOrigin lit
- ; lit' <- newOverloadedLit orig lit pat_ty'
+ ; (wrap_lit, lit') <- newOverloadedLit lit pat_ty' (pe_orig penv)
-- The '>=' and '-' parts are re-mappable syntax
; ge' <- tcSyntaxOp orig ge (mkFunTys [pat_ty', pat_ty'] boolTy)
; minus' <- tcSyntaxOp orig minus (mkFunTys [pat_ty', pat_ty'] pat_ty')
- ; let pat' = NPlusKPat (L nm_loc bndr_id) (L loc lit') ge' minus'
+ ; let pat' = mkHsWrapPat wrap_lit
+ (NPlusKPat (L nm_loc bndr_id)
+ (L loc lit')
+ ge' minus')
+ pat_ty
-- The Report says that n+k patterns must be in Integral
-- We may not want this when using re-mappable syntax, though (ToDo?)
@@ -630,7 +641,7 @@ tcDataConPat penv (L con_span con_name) data_con pat_ty arg_pats thing_inside
-- Instantiate the constructor type variables [a->ty]
-- This may involve doing a family-instance coercion,
-- and building a wrapper
- ; (wrap, ctxt_res_tys) <- matchExpectedPatTy (matchExpectedConTy tycon) pat_ty
+ ; (wrap, ctxt_res_tys) <- matchExpectedConTy penv tycon pat_ty
-- Add the stupid theta
; setSrcSpan con_span $ addDataConStupidTheta data_con ctxt_res_tys
@@ -750,57 +761,36 @@ tcPatSynPat penv (L con_span _) pat_syn pat_ty arg_pats thing_inside
; return (mkHsWrapPat wrap res_pat pat_ty, res) }
----------------------------
-downgrade :: (TcRhoType -> TcM (TcCoercionN, a))
- -> TcRhoType -> TcM (TcCoercionR, a)
-downgrade f a = do { (co,res) <- f a; return (mkTcSubCo co, res) }
-
-matchExpectedListTyR :: TcRhoType -> TcM (TcCoercionR, TcRhoType)
-matchExpectedListTyR = downgrade matchExpectedListTy
-matchExpectedPArrTyR :: TcRhoType -> TcM (TcCoercionR, TcRhoType)
-matchExpectedPArrTyR = downgrade matchExpectedPArrTy
-matchExpectedTyConAppR :: TyCon -> TcRhoType -> TcM (TcCoercionR, [TcSigmaType])
-matchExpectedTyConAppR tc = downgrade (matchExpectedTyConApp tc)
-
-----------------------------
-matchExpectedPatTy :: (TcRhoType -> TcM (TcCoercionR, a))
- -> TcRhoType -- Type of the pattern
- -> TcM (HsWrapper, a)
+-- | Convenient wrapper for calling a matchExpectedXXX function
+matchExpectedPatTy :: (TcRhoType -> TcM (TcCoercionN, a))
+ -> PatEnv -> TcSigmaType -> TcM (HsWrapper, a)
-- See Note [Matching polytyped patterns]
-- Returns a wrapper : pat_ty ~R inner_ty
-matchExpectedPatTy inner_match pat_ty
- | null tvs && null theta
- = do { (co, res) <- inner_match pat_ty -- 'co' is Representational
- ; traceTc "matchExpectedPatTy" (ppr pat_ty $$ ppr co $$ ppr (isTcReflCo co))
- ; return (mkWpCastR (mkTcSymCo co), res) }
- -- The Sym is because the inner_match returns a coercion
- -- that is the other way round to matchExpectedPatTy
-
- | otherwise
- = do { (subst, tvs') <- newMetaTyVars tvs
- ; wrap1 <- instCall PatOrigin (mkTyVarTys tvs') (substTheta subst theta)
- ; (wrap2, arg_tys) <- matchExpectedPatTy inner_match (TcType.substTy subst tau)
- ; return (wrap2 <.> wrap1, arg_tys) }
- where
- (tvs, theta, tau) = tcSplitSigmaTy pat_ty
+matchExpectedPatTy inner_match (PE { pe_orig = orig }) pat_ty
+ = do { (wrap, pat_rho) <- topInstantiate orig pat_ty
+ ; (co, res) <- inner_match pat_rho
+ ; traceTc "matchExpectedPatTy" (ppr pat_ty $$ ppr wrap)
+ ; return (mkWpCastN (mkTcSymCo co) <.> wrap, res) }
----------------------------
-matchExpectedConTy :: TyCon -- The TyCon that this data
+matchExpectedConTy :: PatEnv
+ -> TyCon -- The TyCon that this data
-- constructor actually returns
-- In the case of a data family this is
-- the /representation/ TyCon
- -> TcRhoType -- The type of the pattern; in the case
- -- of a data family this would mention
- -- the /family/ TyCon
- -> TcM (TcCoercionR, [TcSigmaType])
+ -> TcSigmaType -- The type of the pattern; in the case
+ -- of a data family this would mention
+ -- the /family/ TyCon
+ -> TcM (HsWrapper, [TcSigmaType])
-- See Note [Matching constructor patterns]
--- Returns a coercion : T ty1 ... tyn ~R pat_ty
--- This is the same way round as matchExpectedListTy etc
--- but the other way round to matchExpectedPatTy
-matchExpectedConTy data_tc pat_ty
+-- Returns a wrapper : pat_ty "->" T ty1 ... tyn
+matchExpectedConTy (PE { pe_orig = orig }) data_tc pat_ty
| Just (fam_tc, fam_args, co_tc) <- tyConFamInstSig_maybe data_tc
-- Comments refer to Note [Matching constructor patterns]
-- co_tc :: forall a. T [a] ~ T7 a
- = do { (subst, tvs') <- newMetaTyVars (tyConTyVars data_tc)
+ = do { (wrap, pat_ty) <- topInstantiate orig pat_ty
+
+ ; (subst, tvs') <- newMetaTyVars (tyConTyVars data_tc)
-- tys = [ty1,ty2]
; traceTc "matchExpectedConTy" (vcat [ppr data_tc,
@@ -808,16 +798,21 @@ matchExpectedConTy data_tc pat_ty
ppr fam_tc, ppr fam_args])
; co1 <- unifyType noThing (mkTyConApp fam_tc (substTys subst fam_args)) pat_ty
-- co1 : T (ty1,ty2) ~N pat_ty
+ -- could use tcSubType here... but it's the wrong way round
+ -- for actual vs. expected in error messages.
; let tys' = mkTyVarTys tvs'
co2 = mkTcUnbranchedAxInstCo co_tc tys' []
-- co2 : T (ty1,ty2) ~R T7 ty1 ty2
- ; return (mkTcSymCo co2 `mkTcTransCo` mkTcSubCo co1, tys') }
+ ; return ( wrap <.> (mkWpCastR $
+ mkTcSubCo (mkTcSymCo co1) `mkTcTransCo` co2)
+ , tys') }
| otherwise
- = matchExpectedTyConAppR data_tc pat_ty
- -- coi : T tys ~R pat_ty
+ = do { (wrap, pat_rho) <- topInstantiate orig pat_ty
+ ; (coi, tys) <- matchExpectedTyConApp data_tc pat_rho
+ ; return (mkWpCastN (mkTcSymCo coi) <.> wrap, tys) }
{-
Note [Matching constructor patterns]
diff --git a/compiler/typecheck/TcPatSyn.hs b/compiler/typecheck/TcPatSyn.hs
index 5f9225030b..9444ef241a 100644
--- a/compiler/typecheck/TcPatSyn.hs
+++ b/compiler/typecheck/TcPatSyn.hs
@@ -39,7 +39,6 @@ import TcEvidence
import BuildTyCl
import VarSet
import MkId
-import Inst
import TcTyDecls
import ConLike
import FieldLabel
@@ -209,7 +208,7 @@ tcInferPatSynDecl PSB{ psb_id = lname@(L _ name), psb_args = details,
req_theta = map evVarPred req_dicts
; traceTc "tcInferPatSynDecl }" $ ppr name
- ; tc_patsyn_finish lname dir is_infix lpat'
+ ; tc_patsyn_finish lname dir False {- no sig -} is_infix lpat'
(univ_tvs, req_theta, ev_binds, req_dicts)
(ex_tvs, mkTyVarTys ex_tvs, prov_theta, map EvId prov_dicts)
(map nlHsVar args, map idType args)
@@ -268,7 +267,7 @@ tcCheckPatSynDecl PSB{ psb_id = lname@(L _ name), psb_args = details
-- when that should be impossible
; traceTc "tcCheckPatSynDecl }" $ ppr name
- ; tc_patsyn_finish lname dir is_infix lpat'
+ ; tc_patsyn_finish lname dir True {- has a sig -} is_infix lpat'
(univ_tvs, req_theta, ev_binds, req_dicts)
(ex_tvs, mkTyVarTys ex_tvs', prov_theta, prov_dicts)
(args', arg_tys)
@@ -365,6 +364,7 @@ wrongNumberOfParmsErr name decl_arity ty_arity
-- Shared by both tcInferPatSyn and tcCheckPatSyn
tc_patsyn_finish :: Located Name -- ^ PatSyn Name
-> HsPatSynDir Name -- ^ PatSyn type (Uni/Bidir/ExplicitBidir)
+ -> Bool -- ^ True <=> signature provided
-> Bool -- ^ Whether infix
-> LPat Id -- ^ Pattern of the PatSyn
-> ([TcTyVar], [PredType], TcEvBinds, [EvVar])
@@ -374,7 +374,7 @@ tc_patsyn_finish :: Located Name -- ^ PatSyn Name
-> [Name] -- ^ Selector names
-- ^ Whether fields, empty if not record PatSyn
-> TcM (LHsBinds Id, TcGblEnv)
-tc_patsyn_finish lname dir is_infix lpat'
+tc_patsyn_finish lname dir has_sig is_infix lpat'
(univ_tvs, req_theta, req_ev_binds, req_dicts)
(ex_tvs, ex_tys, prov_theta, prov_dicts)
(args, arg_tys)
@@ -402,7 +402,7 @@ tc_patsyn_finish lname dir is_infix lpat'
ppr pat_ty
-- Make the 'matcher'
- ; (matcher_id, matcher_bind) <- tcPatSynMatcher lname lpat'
+ ; (matcher_id, matcher_bind) <- tcPatSynMatcher has_sig lname lpat'
(univ_tvs, req_theta, req_ev_binds, req_dicts)
(ex_tvs, ex_tys, prov_theta, prov_dicts)
(args, arg_tys)
@@ -410,7 +410,7 @@ tc_patsyn_finish lname dir is_infix lpat'
-- Make the 'builder'
- ; builder_id <- mkPatSynBuilderId dir lname qtvs theta
+ ; builder_id <- mkPatSynBuilderId has_sig dir lname qtvs theta
arg_tys pat_ty
-- TODO: Make this have the proper information
@@ -447,7 +447,8 @@ tc_patsyn_finish lname dir is_infix lpat'
************************************************************************
-}
-tcPatSynMatcher :: Located Name
+tcPatSynMatcher :: Bool -- True <=> signature provided
+ -> Located Name
-> LPat Id
-> ([TcTyVar], ThetaType, TcEvBinds, [EvVar])
-> ([TcTyVar], [TcType], ThetaType, [EvTerm])
@@ -455,7 +456,7 @@ tcPatSynMatcher :: Located Name
-> TcType
-> TcM ((Id, Bool), LHsBinds Id)
-- See Note [Matchers and builders for pattern synonyms] in PatSyn
-tcPatSynMatcher (L loc name) lpat
+tcPatSynMatcher has_sig (L loc name) lpat
(univ_tvs, req_theta, req_ev_binds, req_dicts)
(ex_tvs, ex_tys, prov_theta, prov_dicts)
(args, arg_tys) pat_ty
@@ -471,10 +472,11 @@ tcPatSynMatcher (L loc name) lpat
(cont_args, cont_arg_tys)
| is_unlifted = ([nlHsVar voidPrimId], [voidPrimTy])
| otherwise = (args, arg_tys)
- cont_ty = mkInvSigmaTy ex_tvs prov_theta $
+ mk_sigma = if has_sig then mkSpecSigmaTy else mkInvSigmaTy
+ cont_ty = mk_sigma ex_tvs prov_theta $
mkFunTys cont_arg_tys res_ty
- fail_ty = mkFunTy voidPrimTy res_ty
+ fail_ty = mkFunTy voidPrimTy res_ty
; matcher_name <- newImplicitBinder name mkMatcherOcc
; scrutinee <- newSysLocalId (fsLit "scrut") pat_ty
@@ -555,22 +557,25 @@ isUnidirectional ExplicitBidirectional{} = False
************************************************************************
-}
-mkPatSynBuilderId :: HsPatSynDir a -> Located Name
+mkPatSynBuilderId :: Bool -- True <=> signature provided
+ -> HsPatSynDir a -> Located Name
-> [TyVar] -> ThetaType -> [Type] -> Type
-> TcM (Maybe (Id, Bool))
-mkPatSynBuilderId dir (L _ name) qtvs theta arg_tys pat_ty
+mkPatSynBuilderId has_sig dir (L _ name) qtvs theta arg_tys pat_ty
| isUnidirectional dir
= return Nothing
| otherwise
= do { builder_name <- newImplicitBinder name mkBuilderOcc
- ; let builder_sigma = mkInvSigmaTy qtvs theta (mkFunTys builder_arg_tys pat_ty)
+ ; let mk_sigma = if has_sig then mkSpecSigmaTy else mkInvSigmaTy
+ builder_sigma = add_void $
+ mk_sigma qtvs theta (mkFunTys arg_tys pat_ty)
builder_id =
-- See Note [Exported LocalIds] in Id
mkExportedLocalId VanillaId builder_name builder_sigma
; return (Just (builder_id, need_dummy_arg)) }
where
- builder_arg_tys | need_dummy_arg = [voidPrimTy]
- | otherwise = arg_tys
+ add_void | need_dummy_arg = mkFunTy voidPrimTy
+ | otherwise = id
need_dummy_arg = isUnLiftedType pat_ty && null arg_tys && null theta
tcPatSynBuilderBind :: PatSynBind Name Name
@@ -626,7 +631,8 @@ tcPatSynBuilderBind PSB{ psb_id = L loc name, psb_def = lpat
InfixPatSyn arg1 arg2 -> [arg1, arg2]
RecordPatSyn args -> map recordPatSynPatVar args
- add_dummy_arg :: MatchGroup Name (LHsExpr Name) -> MatchGroup Name (LHsExpr Name)
+ add_dummy_arg :: MatchGroup Name (LHsExpr Name)
+ -> MatchGroup Name (LHsExpr Name)
add_dummy_arg mg@(MG { mg_alts
= L l [L loc (Match NonFunBindMatch [] ty grhss)] })
= mg { mg_alts
@@ -634,19 +640,20 @@ tcPatSynBuilderBind PSB{ psb_id = L loc name, psb_def = lpat
add_dummy_arg other_mg = pprPanic "add_dummy_arg" $
pprMatches (PatSyn :: HsMatchContext Name) other_mg
-tcPatSynBuilderOcc :: CtOrigin -> PatSyn -> TcM (HsExpr TcId, TcRhoType)
--- The result type should be fully instantiated
-tcPatSynBuilderOcc orig ps
+tcPatSynBuilderOcc :: PatSyn -> TcM (HsExpr TcId, TcSigmaType)
+-- monadic only for failure
+tcPatSynBuilderOcc ps
| Just (builder_id, add_void_arg) <- builder
- = do { (wrap, rho) <- deeplyInstantiate orig (idType builder_id)
- ; let inst_fun = mkHsWrap wrap (HsVar (noLoc builder_id))
- ; if add_void_arg
- then return ( HsApp (noLoc inst_fun) (nlHsVar voidPrimId)
- , tcFunResultTy rho )
- else return ( inst_fun, rho ) }
+ , let builder_expr = HsVar (noLoc builder_id)
+ builder_ty = idType builder_id
+ = return $
+ if add_void_arg
+ then ( HsApp (noLoc $ builder_expr) (nlHsVar voidPrimId)
+ , tcFunResultTy builder_ty )
+ else (builder_expr, builder_ty)
| otherwise -- Unidirectional
- = nonBidirectionalErr name
+ = nonBidirectionalErr name
where
name = patSynName ps
builder = patSynBuilder ps
@@ -836,4 +843,3 @@ tcCollectEx pat = go pat
goRecFd :: LHsRecField Id (LPat Id) -> (TyVarSet, [EvVar])
goRecFd (L _ HsRecField{ hsRecFieldArg = p }) = go p
-
diff --git a/compiler/typecheck/TcRnDriver.hs b/compiler/typecheck/TcRnDriver.hs
index 8764c33dcf..823bd38bb2 100644
--- a/compiler/typecheck/TcRnDriver.hs
+++ b/compiler/typecheck/TcRnDriver.hs
@@ -1974,7 +1974,7 @@ tcRnExpr hsc_env rdr_expr
uniq <- newUnique ;
let { fresh_it = itName uniq (getLoc rdr_expr) } ;
(tclvl, lie, (_tc_expr, res_ty)) <- pushLevelAndCaptureConstraints $
- tcInferRho rn_expr ;
+ tcInferSigma rn_expr ;
((qtvs, dicts, _), lie_top) <- captureConstraints $
{-# SCC "simplifyInfer" #-}
simplifyInfer tclvl
diff --git a/compiler/typecheck/TcRnMonad.hs b/compiler/typecheck/TcRnMonad.hs
index f5d5ed553b..7ce60bc852 100644
--- a/compiler/typecheck/TcRnMonad.hs
+++ b/compiler/typecheck/TcRnMonad.hs
@@ -972,14 +972,26 @@ getErrCtxt = do { env <- getLclEnv; return (tcl_ctxt env) }
setErrCtxt :: [ErrCtxt] -> TcM a -> TcM a
setErrCtxt ctxt = updLclEnv (\ env -> env { tcl_ctxt = ctxt })
+-- | Add a fixed message to the error context. This message should not
+-- do any tidying.
addErrCtxt :: MsgDoc -> TcM a -> TcM a
addErrCtxt msg = addErrCtxtM (\env -> return (env, msg))
+-- | Add a message to the error context. This message may do tidying.
addErrCtxtM :: (TidyEnv -> TcM (TidyEnv, MsgDoc)) -> TcM a -> TcM a
addErrCtxtM ctxt = updCtxt (\ ctxts -> (False, ctxt) : ctxts)
+-- | Add a fixed landmark message to the error context. A landmark
+-- message is always sure to be reported, even if there is a lot of
+-- context. It also doesn't count toward the maximum number of contexts
+-- reported.
addLandmarkErrCtxt :: MsgDoc -> TcM a -> TcM a
-addLandmarkErrCtxt msg = updCtxt (\ctxts -> (True, \env -> return (env,msg)) : ctxts)
+addLandmarkErrCtxt msg = addLandmarkErrCtxtM (\env -> return (env, msg))
+
+-- | Variant of 'addLandmarkErrCtxt' that allows for monadic operations
+-- and tidying.
+addLandmarkErrCtxtM :: (TidyEnv -> TcM (TidyEnv, MsgDoc)) -> TcM a -> TcM a
+addLandmarkErrCtxtM ctxt = updCtxt (\ctxts -> (True, ctxt) : ctxts)
-- Helper function for the above
updCtxt :: ([ErrCtxt] -> [ErrCtxt]) -> TcM a -> TcM a
diff --git a/compiler/typecheck/TcRnTypes.hs b/compiler/typecheck/TcRnTypes.hs
index 5275f904a3..d0cf737058 100644
--- a/compiler/typecheck/TcRnTypes.hs
+++ b/compiler/typecheck/TcRnTypes.hs
@@ -91,7 +91,8 @@ module TcRnTypes(
ctLocTypeOrKind_maybe,
ctLocDepth, bumpCtLocDepth,
setCtLocOrigin, setCtLocEnv, setCtLocSpan,
- CtOrigin(..), ErrorThing(..), mkErrorThing, errorThingNumArgs_maybe,
+ CtOrigin(..), exprCtOrigin, matchesCtOrigin, grhssCtOrigin,
+ ErrorThing(..), mkErrorThing, errorThingNumArgs_maybe,
TypeOrKind(..), isTypeLevel, isKindLevel,
pprCtOrigin, pprCtLoc,
pushErrCtxt, pushErrCtxtSameOrigin,
@@ -164,6 +165,7 @@ import Outputable
import ListSetOps
import FastString
import GHC.Fingerprint
+import qualified GHC.LanguageExtensions as LangExt
import Control.Monad (ap, liftM, msum)
#if __GLASGOW_HASKELL__ > 710
@@ -1211,7 +1213,7 @@ instance Outputable TcIdSigInfo where
ppr (TISI { sig_bndr = bndr, sig_skols = tyvars
, sig_theta = theta, sig_tau = tau })
= ppr (tcIdSigBndrName bndr) <+> dcolon <+>
- vcat [ pprSigmaType (mkInvSigmaTy (map snd tyvars) theta tau)
+ vcat [ pprSigmaType (mkSpecSigmaTy (map snd tyvars) theta tau)
, ppr (map fst tyvars) ]
instance Outputable TcIdSigBndr where
@@ -2648,12 +2650,16 @@ data CtOrigin
-- is pinned on the entire error message
| HoleOrigin
- | UnboundOccurrenceOf RdrName
+ | UnboundOccurrenceOf OccName
| ListOrigin -- An overloaded list
| StaticOrigin -- A static form
| FailablePattern (LPat TcId) -- A failable pattern in do-notation for the
-- MonadFail Proposal (MFP). Obsolete when
-- actual desugaring to MonadFail.fail is live.
+ | Shouldn'tHappenOrigin String
+ -- the user should never see this one,
+ -- unlesss ImpredicativeTypes is on, where all
+ -- bets are off
-- | A thing that can be stored for error message generation only.
-- It is stored with a function to zonk and tidy the thing.
@@ -2695,6 +2701,78 @@ instance Outputable ErrorThing where
ctoHerald :: SDoc
ctoHerald = ptext (sLit "arising from")
+-- | Extract a suitable CtOrigin from a HsExpr
+exprCtOrigin :: HsExpr Name -> CtOrigin
+exprCtOrigin (HsVar (L _ name)) = OccurrenceOf name
+exprCtOrigin (HsUnboundVar occ) = UnboundOccurrenceOf occ
+exprCtOrigin (HsRecFld f) = OccurrenceOfRecSel (rdrNameAmbiguousFieldOcc f)
+exprCtOrigin (HsOverLabel l) = OverLabelOrigin l
+exprCtOrigin (HsIPVar ip) = IPOccOrigin ip
+exprCtOrigin (HsOverLit lit) = LiteralOrigin lit
+exprCtOrigin (HsLit {}) = Shouldn'tHappenOrigin "concrete literal"
+exprCtOrigin (HsLam matches) = matchesCtOrigin matches
+exprCtOrigin (HsLamCase _ ms) = matchesCtOrigin ms
+exprCtOrigin (HsApp (L _ e1) _) = exprCtOrigin e1
+exprCtOrigin (OpApp _ (L _ op) _ _) = exprCtOrigin op
+exprCtOrigin (NegApp (L _ e) _) = exprCtOrigin e
+exprCtOrigin (HsPar (L _ e)) = exprCtOrigin e
+exprCtOrigin (SectionL _ _) = SectionOrigin
+exprCtOrigin (SectionR _ _) = SectionOrigin
+exprCtOrigin (ExplicitTuple {}) = Shouldn'tHappenOrigin "explicit tuple"
+exprCtOrigin (HsCase _ matches) = matchesCtOrigin matches
+exprCtOrigin (HsIf (Just syn) _ _ _) = exprCtOrigin syn
+exprCtOrigin (HsIf {}) = Shouldn'tHappenOrigin "if expression"
+exprCtOrigin (HsMultiIf _ rhs) = lGRHSCtOrigin rhs
+exprCtOrigin (HsLet _ (L _ e)) = exprCtOrigin e
+exprCtOrigin (HsDo _ _ _) = DoOrigin
+exprCtOrigin (ExplicitList {}) = Shouldn'tHappenOrigin "list"
+exprCtOrigin (ExplicitPArr {}) = Shouldn'tHappenOrigin "parallel array"
+exprCtOrigin (RecordCon {}) = Shouldn'tHappenOrigin "record construction"
+exprCtOrigin (RecordUpd {}) = Shouldn'tHappenOrigin "record update"
+exprCtOrigin (ExprWithTySig {}) = ExprSigOrigin
+exprCtOrigin (ExprWithTySigOut {}) = panic "exprCtOrigin ExprWithTySigOut"
+exprCtOrigin (ArithSeq {}) = Shouldn'tHappenOrigin "arithmetic sequence"
+exprCtOrigin (PArrSeq {}) = Shouldn'tHappenOrigin "parallel array sequence"
+exprCtOrigin (HsSCC _ _ (L _ e))= exprCtOrigin e
+exprCtOrigin (HsCoreAnn _ _ (L _ e)) = exprCtOrigin e
+exprCtOrigin (HsBracket {}) = Shouldn'tHappenOrigin "TH bracket"
+exprCtOrigin (HsRnBracketOut {})= Shouldn'tHappenOrigin "HsRnBracketOut"
+exprCtOrigin (HsTcBracketOut {})= panic "exprCtOrigin HsTcBracketOut"
+exprCtOrigin (HsSpliceE {}) = Shouldn'tHappenOrigin "TH splice"
+exprCtOrigin (HsProc {}) = Shouldn'tHappenOrigin "proc"
+exprCtOrigin (HsStatic {}) = Shouldn'tHappenOrigin "static expression"
+exprCtOrigin (HsArrApp {}) = panic "exprCtOrigin HsArrApp"
+exprCtOrigin (HsArrForm {}) = panic "exprCtOrigin HsArrForm"
+exprCtOrigin (HsTick _ (L _ e)) = exprCtOrigin e
+exprCtOrigin (HsBinTick _ _ (L _ e)) = exprCtOrigin e
+exprCtOrigin (HsTickPragma _ _ (L _ e)) = exprCtOrigin e
+exprCtOrigin EWildPat = panic "exprCtOrigin EWildPat"
+exprCtOrigin (EAsPat {}) = panic "exprCtOrigin EAsPat"
+exprCtOrigin (EViewPat {}) = panic "exprCtOrigin EViewPat"
+exprCtOrigin (ELazyPat {}) = panic "exprCtOrigin ELazyPat"
+exprCtOrigin (HsType {}) = Shouldn'tHappenOrigin "type application"
+exprCtOrigin (HsTypeOut {}) = panic "exprCtOrigin HsTypeOut"
+exprCtOrigin (HsWrap {}) = panic "exprCtOrigin HsWrap"
+
+-- | Extract a suitable CtOrigin from a MatchGroup
+matchesCtOrigin :: MatchGroup Name (LHsExpr Name) -> CtOrigin
+matchesCtOrigin (MG { mg_alts = alts })
+ | L _ [L _ match] <- alts
+ , Match { m_grhss = grhss } <- match
+ = grhssCtOrigin grhss
+
+ | otherwise
+ = Shouldn'tHappenOrigin "multi-way match"
+
+-- | Extract a suitable CtOrigin from guarded RHSs
+grhssCtOrigin :: GRHSs Name (LHsExpr Name) -> CtOrigin
+grhssCtOrigin (GRHSs { grhssGRHSs = lgrhss }) = lGRHSCtOrigin lgrhss
+
+-- | Extract a suitable CtOrigin from a list of guarded RHSs
+lGRHSCtOrigin :: [LGRHS Name (LHsExpr Name)] -> CtOrigin
+lGRHSCtOrigin [L _ (GRHS _ (L _ e))] = exprCtOrigin e
+lGRHSCtOrigin _ = Shouldn'tHappenOrigin "multi-way GRHS"
+
pprCtLoc :: CtLoc -> SDoc
-- "arising from ... at ..."
-- Not an instance of Outputable because of the "arising from" prefix
@@ -2758,6 +2836,15 @@ pprCtOrigin (FailablePattern pat)
$$
text "(this will become an error a future GHC release)"
+pprCtOrigin (Shouldn'tHappenOrigin note)
+ = sdocWithDynFlags $ \dflags ->
+ if xopt LangExt.ImpredicativeTypes dflags
+ then text "a situation created by impredicative types"
+ else
+ vcat [ text "<< This should not appear in error messages. If you see this"
+ , text "in an error message, please report a bug mentioning" <+> quotes (text note) <+> text "at"
+ , text "https://ghc.haskell.org/trac/ghc/wiki/ReportABug >>" ]
+
pprCtOrigin simple_origin
= ctoHerald <+> pprCtO simple_origin
@@ -2774,7 +2861,7 @@ pprCtO ExprSigOrigin = ptext (sLit "an expression type signature")
pprCtO PatSigOrigin = ptext (sLit "a pattern type signature")
pprCtO PatOrigin = ptext (sLit "a pattern")
pprCtO ViewPatOrigin = ptext (sLit "a view pattern")
-pprCtO IfOrigin = ptext (sLit "an if statement")
+pprCtO IfOrigin = ptext (sLit "an if expression")
pprCtO (LiteralOrigin lit) = hsep [ptext (sLit "the literal"), quotes (ppr lit)]
pprCtO (ArithSeqOrigin seq) = hsep [ptext (sLit "the arithmetic sequence"), quotes (ppr seq)]
pprCtO (PArrSeqOrigin seq) = hsep [ptext (sLit "the parallel array sequence"), quotes (ppr seq)]
diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs
index e3b4fa8c7e..bf967aeb2f 100644
--- a/compiler/typecheck/TcSplice.hs
+++ b/compiler/typecheck/TcSplice.hs
@@ -75,6 +75,7 @@ import TyCoRep
import FamInst
import FamInstEnv
import InstEnv
+import Inst
import NameEnv
import PrelNames
import TysWiredIn
@@ -84,7 +85,6 @@ import Var
import Module
import LoadIface
import Class
-import Inst
import TyCon
import CoAxiom
import PatSyn ( patSynName )
@@ -174,11 +174,12 @@ tcTypedBracket brack@(TExpBr expr) res_ty
-- NC for no context; tcBracket does that
; meta_ty <- tcTExpTy expr_ty
- ; co <- unifyType (Just expr) meta_ty res_ty
; ps' <- readMutVar ps_ref
; texpco <- tcLookupId unsafeTExpCoerceName
- ; return (mkHsWrapCo co (unLoc (mkHsApp (nlHsTyApp texpco [expr_ty])
- (noLoc (HsTcBracketOut brack ps'))))) }
+ ; tcWrapResultO (Shouldn'tHappenOrigin "TExpBr")
+ (unLoc (mkHsApp (nlHsTyApp texpco [expr_ty])
+ (noLoc (HsTcBracketOut brack ps'))))
+ meta_ty res_ty }
tcTypedBracket other_brack _
= pprPanic "tcTypedBracket" (ppr other_brack)
@@ -187,9 +188,9 @@ tcUntypedBracket brack ps res_ty
= do { traceTc "tc_bracket untyped" (ppr brack $$ ppr ps)
; ps' <- mapM tcPendingSplice ps
; meta_ty <- tcBrackTy brack
- ; co <- unifyType (Just brack) meta_ty res_ty
; traceTc "tc_bracket done untyped" (ppr meta_ty)
- ; return (mkHsWrapCo co (HsTcBracketOut brack ps')) }
+ ; tcWrapResultO (Shouldn'tHappenOrigin "untyped bracket")
+ (HsTcBracketOut brack ps') meta_ty res_ty }
---------------
tcBrackTy :: HsBracket Name -> TcM TcType
@@ -512,7 +513,7 @@ tcTopSpliceExpr :: SpliceType -> TcM (LHsExpr Id) -> TcM (LHsExpr Id)
-- Note that set the level to Splice, regardless of the original level,
-- before typechecking the expression. For example:
-- f x = $( ...$(g 3) ... )
--- The recursive call to tcMonoExpr will simply expand the
+-- The recursive call to tcPolyExpr will simply expand the
-- inner escape before dealing with the outer one
tcTopSpliceExpr isTypedSplice tc_action
diff --git a/compiler/typecheck/TcTyDecls.hs b/compiler/typecheck/TcTyDecls.hs
index 51d6fc78f4..c17d78b9cc 100644
--- a/compiler/typecheck/TcTyDecls.hs
+++ b/compiler/typecheck/TcTyDecls.hs
@@ -626,10 +626,10 @@ initialRoleEnv1 is_boot annots_env tc
_ -> replicate num_exps Nothing
default_roles = build_default_roles visflags role_annots
- build_default_roles (Invisible : viss) ras
- = Nominal : build_default_roles viss ras
build_default_roles (Visible : viss) (m_annot : ras)
= (m_annot `orElse` default_role) : build_default_roles viss ras
+ build_default_roles (_inv : viss) ras
+ = Nominal : build_default_roles viss ras
build_default_roles [] [] = []
build_default_roles _ _ = pprPanic "initialRoleEnv1 (2)"
(vcat [ppr tc, ppr role_annots])
@@ -885,7 +885,7 @@ mkDefaultMethodIds tycons
where
mk_dm_ty :: Class -> Id -> DefMethSpec Type -> Type
mk_dm_ty _ sel_id VanillaDM = idType sel_id
- mk_dm_ty cls _ (GenericDM dm_ty) = mkInvSigmaTy cls_tvs [pred] dm_ty
+ mk_dm_ty cls _ (GenericDM dm_ty) = mkSpecSigmaTy cls_tvs [pred] dm_ty
where
cls_tvs = classTyVars cls
pred = mkClassPred cls (mkTyVarTys cls_tvs)
@@ -960,18 +960,19 @@ mkOneRecordSelector all_cons idDetails fl
-- Selector type; Note [Polymorphic selectors]
field_ty = conLikeFieldType con1 lbl
- data_tvs = tyCoVarsOfType data_ty
- is_naughty = not (tyCoVarsOfType field_ty `subVarSet` data_tvs)
+ data_tvs = tyCoVarsOfTypeWellScoped data_ty
+ data_tv_set= mkVarSet data_tvs
+ is_naughty = not (tyCoVarsOfType field_ty `subVarSet` data_tv_set)
(field_tvs, field_theta, field_tau) = tcSplitSigmaTy field_ty
- all_tvs = varSetElemsWellScoped $ data_tvs `extendVarSetList` field_tvs
sel_ty | is_naughty = unitTy -- See Note [Naughty record selectors]
- | otherwise = ASSERT( all isTyVar all_tvs )
- mkInvForAllTys all_tvs $
+ | otherwise = mkSpecForAllTys data_tvs $
mkPhiTy (conLikeStupidTheta con1) $ -- Urgh!
- mkPhiTy field_theta $ -- Urgh!
+ mkFunTy data_ty $
+ mkSpecForAllTys field_tvs $
+ mkPhiTy field_theta $
-- req_theta is empty for normal DataCon
mkPhiTy req_theta $
- mkFunTy data_ty field_tau
+ field_tau
-- Make the binding: sel (C2 { fld = x }) = x
-- sel (C7 { fld = x }) = x
@@ -1017,7 +1018,8 @@ mkOneRecordSelector all_cons idDetails fl
(univ_tvs, _, eq_spec, _, req_theta, _, data_ty) = conLikeFullSig con1
- inst_tys = substTyVars (mkTopTCvSubst (map eqSpecPair eq_spec)) univ_tvs
+ eq_subst = mkTopTCvSubst (map eqSpecPair eq_spec)
+ inst_tys = substTyVars eq_subst univ_tvs
unit_rhs = mkLHsTupleExpr []
msg_lit = HsStringPrim "" (fastStringToByteString lbl)
@@ -1025,14 +1027,14 @@ mkOneRecordSelector all_cons idDetails fl
{-
Note [Polymorphic selectors]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-When a record has a polymorphic field, we pull the foralls out to the front.
- data T = MkT { f :: forall a. [a] -> a }
-Then f :: forall a. T -> [a] -> a
-NOT f :: T -> forall a. [a] -> a
-
-This is horrid. It's only needed in deeply obscure cases, which I hate.
-The only case I know is test tc163, which is worth looking at. It's far
-from clear that this test should succeed at all!
+We take care to build the type of a polymorphic selector in the right
+order, so that visible type application works.
+
+ data Ord a => T a = MkT { field :: forall b. (Num a, Show b) => (a, b) }
+
+We want
+
+ field :: forall a. Ord a => T a -> forall b. (Num a, Show b) => (a, b)
Note [Naughty record selectors]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/compiler/typecheck/TcType.hs b/compiler/typecheck/TcType.hs
index 879f977045..97865f44a7 100644
--- a/compiler/typecheck/TcType.hs
+++ b/compiler/typecheck/TcType.hs
@@ -32,9 +32,8 @@ module TcType (
-- MetaDetails
UserTypeCtxt(..), pprUserTypeCtxt, pprSigCtxt, isSigMaybe,
TcTyVarDetails(..), pprTcTyVarDetails, vanillaSkolemTv, superSkolemTv,
- MetaDetails(Flexi, Indirect), MetaInfo(..),
- isImmutableTyVar, isSkolemTyVar,
- isMetaTyVar, isMetaTyVarTy, isTyVarTy,
+ MetaDetails(Flexi, Indirect), MetaInfo(..), TauTvFlavour(..),
+ isImmutableTyVar, isSkolemTyVar, isMetaTyVar, isMetaTyVarTy, isTyVarTy,
isSigTyVar, isOverlappableTyVar, isTyConableTyVar,
isFskTyVar, isFmvTyVar, isFlattenTyVar, isReturnTyVar,
isAmbiguousTyVar, metaTvRef, metaTyVarInfo,
@@ -46,14 +45,15 @@ module TcType (
--------------------------------
-- Builders
- mkPhiTy, mkInvSigmaTy, mkSigmaTy,
+ mkPhiTy, mkInvSigmaTy, mkSpecSigmaTy, mkSigmaTy,
mkNakedTyConApp, mkNakedAppTys, mkNakedAppTy, mkNakedFunTy,
- mkNakedInvSigmaTy, mkNakedCastTy, mkNakedPhiTy,
+ mkNakedSpecSigmaTy, mkNakedCastTy, mkNakedPhiTy,
--------------------------------
-- Splitters
-- These are important because they do not look through newtypes
getTyVar,
+ tcSplitForAllTy_maybe,
tcSplitForAllTys, tcSplitPiTys, tcSplitNamedPiTys,
tcSplitPhiTy, tcSplitPredFunTy_maybe,
tcSplitFunTy_maybe, tcSplitFunTys, tcFunArgTy, tcFunResultTy, tcSplitFunTysN,
@@ -126,11 +126,12 @@ module TcType (
-- Rexported from Type
Type, PredType, ThetaType, TyBinder, VisibilityFlag(..),
- mkForAllTy, mkForAllTys, mkInvForAllTys, mkNamedForAllTy,
+ mkForAllTy, mkForAllTys, mkInvForAllTys, mkSpecForAllTys, mkNamedForAllTy,
mkFunTy, mkFunTys,
mkTyConApp, mkAppTy, mkAppTys, applyTys,
mkTyConTy, mkTyVarTy,
mkTyVarTys,
+ mkNamedBinder,
isClassPred, isEqPred, isNomEqPred, isIPPred,
mkClassPred,
@@ -389,6 +390,10 @@ instance Outputable MetaDetails where
ppr Flexi = ptext (sLit "Flexi")
ppr (Indirect ty) = ptext (sLit "Indirect") <+> ppr ty
+data TauTvFlavour
+ = VanillaTau
+ | WildcardTau -- ^ A tyvar that originates from a type wildcard.
+
data MetaInfo
= TauTv -- This MetaTv is an ordinary unification variable
-- A TauTv is always filled in with a tau-type, which
@@ -428,7 +433,7 @@ data UserTypeCtxt
| InfSigCtxt Name -- Inferred type for function
| ExprSigCtxt -- Expression type signature
-
+ | TypeAppCtxt -- Visible type application
| ConArgCtxt Name -- Data constructor argument
| TySynCtxt Name -- RHS of a type synonym decl
| PatSynCtxt Name -- Type sig for a pattern synonym
@@ -615,6 +620,7 @@ pprUserTypeCtxt (FunSigCtxt n _) = ptext (sLit "the type signature for") <+> qu
pprUserTypeCtxt (InfSigCtxt n) = ptext (sLit "the inferred type for") <+> quotes (ppr n)
pprUserTypeCtxt (RuleSigCtxt n) = ptext (sLit "a RULE for") <+> quotes (ppr n)
pprUserTypeCtxt ExprSigCtxt = ptext (sLit "an expression type signature")
+pprUserTypeCtxt TypeAppCtxt = ptext (sLit "a type argument")
pprUserTypeCtxt (ConArgCtxt c) = ptext (sLit "the type of the constructor") <+> quotes (ppr c)
pprUserTypeCtxt (TySynCtxt c) = ptext (sLit "the RHS of the type synonym") <+> quotes (ppr c)
pprUserTypeCtxt (PatSynCtxt c) = ptext (sLit "the type signature for pattern synonym") <+> quotes (ppr c)
@@ -967,6 +973,12 @@ mkInvSigmaTy :: [TyVar] -> [PredType] -> Type -> Type
mkInvSigmaTy tyvars
= mkSigmaTy (zipWith mkNamedBinder tyvars (repeat Invisible))
+-- | Make a sigma ty where all type variables are "specified". That is,
+-- they can be used with visible type application
+mkSpecSigmaTy :: [TyVar] -> [PredType] -> Type -> Type
+mkSpecSigmaTy tyvars
+ = mkSigmaTy (zipWith mkNamedBinder tyvars (repeat Specified))
+
mkPhiTy :: [PredType] -> Type -> Type
mkPhiTy = mkFunTys
@@ -974,10 +986,10 @@ mkNakedSigmaTy :: [TyBinder] -> [PredType] -> Type -> Type
-- See Note [Type-checking inside the knot] in TcHsType
mkNakedSigmaTy bndrs theta tau = mkForAllTys bndrs (mkNakedPhiTy theta tau)
-mkNakedInvSigmaTy :: [TyVar] -> [PredType] -> Type -> Type
+mkNakedSpecSigmaTy :: [TyVar] -> [PredType] -> Type -> Type
-- See Note [Type-checking inside the knot] in TcHsType
-mkNakedInvSigmaTy tyvars
- = mkNakedSigmaTy (zipWith mkNamedBinder tyvars (repeat Invisible))
+mkNakedSpecSigmaTy tyvars
+ = mkNakedSigmaTy (zipWith mkNamedBinder tyvars (repeat Specified))
mkNakedPhiTy :: [PredType] -> Type -> Type
-- See Note [Type-checking inside the knot] in TcHsType
@@ -1063,6 +1075,11 @@ variables. It's up to you to make sure this doesn't matter.
tcSplitPiTys :: Type -> ([TyBinder], Type)
tcSplitPiTys = splitPiTys
+tcSplitForAllTy_maybe :: Type -> Maybe (TyBinder, Type)
+tcSplitForAllTy_maybe ty | Just ty' <- coreView ty = tcSplitForAllTy_maybe ty'
+tcSplitForAllTy_maybe (ForAllTy tv ty) = Just (tv, ty)
+tcSplitForAllTy_maybe _ = Nothing
+
-- | Like 'tcSplitPiTys', but splits off only named binders, returning
-- just the tycovars.
tcSplitForAllTys :: Type -> ([TyVar], Type)
@@ -1310,8 +1327,8 @@ tcEqTypeVis ty1 ty2
(<!>) :: Maybe VisibilityFlag -> Maybe VisibilityFlag -> Maybe VisibilityFlag
Nothing <!> x = x
Just Visible <!> _ = Just Visible
-Just Invisible <!> Just Visible = Just Visible
-Just Invisible <!> _ = Just Invisible
+Just _inv <!> Just Visible = Just Visible
+Just inv <!> _ = Just inv
infixr 3 <!>
-- | Real worker for 'tcEqType'. No kind check!
@@ -1578,7 +1595,7 @@ occurCheckExpand dflags tv ty
canUnifyWithPolyType :: DynFlags -> TcTyVarDetails -> Bool
canUnifyWithPolyType dflags details
= case details of
- MetaTv { mtv_info = ReturnTv } -> True -- See Note [ReturnTv]
+ MetaTv { mtv_info = ReturnTv } -> True -- See Note [ReturnTv]
MetaTv { mtv_info = SigTv } -> False
MetaTv { mtv_info = TauTv } -> xopt LangExt.ImpredicativeTypes dflags
_other -> True
@@ -1992,6 +2009,40 @@ to_tc_type = mapType to_tc_mapper
\subsection{Misc}
* *
************************************************************************
+
+Note [Visible type application]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+GHC implements a generalisation of the algorithm described in the
+"Visible Type Application" paper (available from
+http://www.cis.upenn.edu/~sweirich/publications.html). A key part
+of that algorithm is to distinguish user-specified variables from inferred
+variables. For example, the following should typecheck:
+
+ f :: forall a b. a -> b -> b
+ f = const id
+
+ g = const id
+
+ x = f @Int @Bool 5 False
+ y = g 5 @Bool False
+
+The idea is that we wish to allow visible type application when we are
+instantiating a specified, fixed variable. In practice, specified, fixed
+variables are either written in a type signature (or
+annotation), OR are imported from another module. (We could do better here,
+for example by doing SCC analysis on parts of a module and considering any
+type from outside one's SCC to be fully specified, but this is very confusing to
+users. The simple rule above is much more straightforward and predictable.)
+
+So, both of f's quantified variables are specified and may be instantiated.
+But g has no type signature, so only id's variable is specified (because id
+is imported). We write the type of g as forall {a}. a -> forall b. b -> b.
+Note that the a is in braces, meaning it cannot be instantiated with
+visible type application.
+
+Tracking specified vs. inferred variables is done conveniently by a field
+in TyBinder.
+
-}
deNoteType :: Type -> Type
diff --git a/compiler/typecheck/TcUnify.hs b/compiler/typecheck/TcUnify.hs
index 51a1eee695..b7bc77db73 100644
--- a/compiler/typecheck/TcUnify.hs
+++ b/compiler/typecheck/TcUnify.hs
@@ -6,12 +6,13 @@
Type subsumption and unification
-}
-{-# LANGUAGE CPP, MultiWayIf #-}
+{-# LANGUAGE CPP, MultiWayIf, TupleSections #-}
module TcUnify (
-- Full-blown subsumption
- tcWrapResult, tcGen,
- tcSubType, tcSubType_NC, tcSubTypeDS, tcSubTypeDS_NC,
+ tcWrapResult, tcWrapResultO, tcSkolemise,
+ tcSubTypeHR, tcSubType, tcSubType_NC, tcSubTypeDS, tcSubTypeDS_O,
+ tcSubTypeDS_NC, tcSubTypeDS_NC_O,
checkConstraints, buildImplication, buildImplicationFor,
-- Various unifications
@@ -26,7 +27,7 @@ module TcUnify (
matchExpectedTyConApp,
matchExpectedAppTy,
matchExpectedFunTys,
-
+ matchActualFunTys, matchActualFunTysPart,
matchExpectedFunKind,
wrapFunResCoercion
@@ -92,7 +93,7 @@ This is used to construct a message of form
Note [matchExpectedFunTys]
~~~~~~~~~~~~~~~~~~~~~~~~~~
-matchExpectedFunTys checks that an (Expected rho) has the form
+matchExpectedFunTys checks that a sigma has the form
of an n-ary function. It passes the decomposed type to the
thing_inside, and returns a wrapper to coerce between the two types
@@ -102,18 +103,77 @@ namely:
A function definition
An operator section
-This is not (currently) where deep skolemisation occurs;
-matchExpectedFunTys does not skolmise nested foralls in the
-expected type, because it expects that to have been done already
-}
-matchExpectedFunTys :: SDoc -- See Note [Herald for matchExpectedFunTys]
+-- Use this one when you have an "expected" type.
+matchExpectedFunTys :: SDoc -- See Note [Herald for matchExpectedFunTys]
-> Arity
- -> TcRhoType
- -> TcM (TcCoercionN, [TcSigmaType], TcRhoType)
-
--- If matchExpectFunTys n ty = (co, [t1,..,tn], ty_r)
--- then co : ty ~N (t1 -> ... -> tn -> ty_r)
+ -> TcSigmaType -- deeply skolemised
+ -> TcM (HsWrapper, [TcSigmaType], TcSigmaType)
+-- If matchExpectedFunTys n ty = (wrap, [t1,..,tn], ty_r)
+-- then wrap : (t1 -> ... -> tn -> ty_r) "->" ty
+
+-- This function is always called with a deeply skolemised expected result
+-- type. This means that matchActualFunTys will never actually instantiate,
+-- and the returned HsWrapper will be reversible (that is, just a coercion).
+-- So we just piggyback on matchActualFunTys. This is just a bit dodgy, but
+-- it's much better than duplicating all the logic in matchActualFunTys.
+-- To keep expected/actual working out properly, we tell matchActualFunTys
+-- to swap the arguments to unifyType.
+matchExpectedFunTys herald arity ty
+ = ASSERT( is_deeply_skolemised ty )
+ do { (wrap, arg_tys, res_ty)
+ <- match_fun_tys True herald
+ (Shouldn'tHappenOrigin "matchExpectedFunTys")
+ arity ty [] arity
+ ; return $
+ case symWrapper_maybe wrap of
+ Just wrap' -> (wrap', arg_tys, res_ty)
+ Nothing -> pprPanic "matchExpectedFunTys" (ppr wrap $$ ppr ty) }
+ where
+ is_deeply_skolemised (TyVarTy {}) = True
+ is_deeply_skolemised (AppTy {}) = True
+ is_deeply_skolemised (TyConApp {}) = True
+ is_deeply_skolemised (LitTy {}) = True
+ is_deeply_skolemised (CastTy ty _) = is_deeply_skolemised ty
+ is_deeply_skolemised (CoercionTy {}) = True
+
+ is_deeply_skolemised (ForAllTy (Anon _) res) = is_deeply_skolemised res
+ is_deeply_skolemised (ForAllTy (Named {}) _) = False
+
+matchActualFunTys :: SDoc -- See Note [Herald for matchExpectedFunTys]
+ -> CtOrigin
+ -> Arity
+ -> TcSigmaType
+ -> TcM (HsWrapper, [TcSigmaType], TcSigmaType)
+matchActualFunTys herald ct_orig arity ty
+ = matchActualFunTysPart herald ct_orig arity ty [] arity
+
+-- | Variant of 'matchActualFunTys' that works when supplied only part
+-- (that is, to the right of some arrows) of the full function type
+matchActualFunTysPart :: SDoc -- See Note [Herald for matchExpectedFunTys]
+ -> CtOrigin
+ -> Arity
+ -> TcSigmaType
+ -> [TcSigmaType] -- reversed args. See (*) below.
+ -> Arity -- overall arity of the function, for errs
+ -> TcM (HsWrapper, [TcSigmaType], TcSigmaType)
+matchActualFunTysPart = match_fun_tys False
+
+match_fun_tys :: Bool -- True <=> swap the args when unifying,
+ -- for better expected/actual in error messages;
+ -- see comments with matchExpectedFunTys
+ -> SDoc
+ -> CtOrigin
+ -> Arity
+ -> TcSigmaType
+ -> [TcSigmaType]
+ -> Arity
+ -> TcM (HsWrapper, [TcSigmaType], TcSigmaType)
+match_fun_tys swap_tys herald ct_orig arity orig_ty orig_old_args full_arity
+ = go arity orig_old_args orig_ty
+-- If matchActualFunTys n ty = (wrap, [t1,..,tn], ty_r)
+-- then wrap : ty "->" (t1 -> ... -> tn -> ty_r)
--
-- Does not allocate unnecessary meta variables: if the input already is
-- a function, we just take it apart. Not only is this efficient,
@@ -122,29 +182,54 @@ matchExpectedFunTys :: SDoc -- See Note [Herald for matchExpectedFunTys]
-- If allocated (fresh-meta-var1 -> fresh-meta-var2) and unified, we'd
-- hide the forall inside a meta-variable
-matchExpectedFunTys herald arity orig_ty
- = go arity orig_ty
- where
- -- If go n ty = (co, [t1,..,tn], ty_r)
- -- then co : ty ~ t1 -> .. -> tn -> ty_r
+-- (*) Sometimes it's necessary to call matchActualFunTys with only part
+-- (that is, to the right of some arrows) of the type of the function in
+-- question. (See TcExpr.tcArgs.) This argument is the reversed list of
+-- arguments already seen (that is, not part of the TcSigmaType passed
+-- in elsewhere).
- go n_req ty
- | n_req == 0 = return (mkTcNomReflCo ty, [], ty)
+ where
+ -- This function has a bizarre mechanic: it accumulates arguments on
+ -- the way down and also builds an argument list on the way up. Why:
+ -- 1. The returns args list and the accumulated args list might be different.
+ -- The accumulated args include all the arg types for the function,
+ -- including those from before this function was called. The returned
+ -- list should include only those arguments produced by this call of
+ -- matchActualFunTys
+ --
+ -- 2. The HsWrapper can be built only on the way up. It seems (more)
+ -- bizarre to build the HsWrapper but not the arg_tys.
+ --
+ -- Refactoring is welcome.
+ go :: Arity
+ -> [TcSigmaType] -- accumulator of arguments (reversed)
+ -> TcSigmaType -- the remainder of the type as we're processing
+ -> TcM (HsWrapper, [TcSigmaType], TcSigmaType)
+ go 0 _ ty = return (idHsWrapper, [], ty)
+
+ go n acc_args ty
+ | not (null tvs && null theta)
+ = do { (wrap1, rho) <- topInstantiate ct_orig ty
+ ; (wrap2, arg_tys, res_ty) <- go n acc_args rho
+ ; return (wrap2 <.> wrap1, arg_tys, res_ty) }
+ where
+ (tvs, theta, _) = tcSplitSigmaTy ty
- go n_req ty
- | Just ty' <- coreView ty = go n_req ty'
+ go n acc_args ty
+ | Just ty' <- coreView ty = go n acc_args ty'
- go n_req (ForAllTy (Anon arg_ty) res_ty)
- | not (isPredTy arg_ty)
- = do { (co, tys, ty_r) <- go (n_req-1) res_ty
- ; return (mkTcFunCo Nominal (mkTcNomReflCo arg_ty) co, arg_ty:tys, ty_r) }
+ go n acc_args (ForAllTy (Anon arg_ty) res_ty)
+ = ASSERT( not (isPredTy arg_ty) )
+ do { (wrap_res, tys, ty_r) <- go (n-1) (arg_ty : acc_args) res_ty
+ ; return ( mkWpFun idHsWrapper wrap_res arg_ty (mkFunTys tys ty_r)
+ , arg_ty:tys, ty_r ) }
- go n_req ty@(TyVarTy tv)
+ go n acc_args ty@(TyVarTy tv)
| ASSERT( isTcTyVar tv) isMetaTyVar tv
= do { cts <- readMetaTyVar tv
; case cts of
- Indirect ty' -> go n_req ty'
- Flexi -> defer n_req ty (isReturnTyVar tv) }
+ Indirect ty' -> go n acc_args ty'
+ Flexi -> defer n ty (isReturnTyVar tv) }
-- In all other cases we bale out into ordinary unification
-- However unlike the meta-tyvar case, we are sure that the
@@ -161,19 +246,21 @@ matchExpectedFunTys herald arity orig_ty
--
-- But in that case we add specialized type into error context
-- anyway, because it may be useful. See also Trac #9605.
- go n_req ty = addErrCtxtM mk_ctxt $
- defer n_req ty False
+ go n acc_args ty = addErrCtxtM (mk_ctxt (reverse acc_args) ty) $
+ defer n ty False
------------
-- If we decide that a ReturnTv (see Note [ReturnTv] in TcType) should
- -- really be a function type, then we need to allow the argument and
- -- result types also to be ReturnTvs.
- defer n_req fun_ty is_return
- = do { arg_tys <- replicateM n_req new_flexi
- -- See Note [Foralls to left of arrow]
+ -- really be a function type, then we need to allow the
+ -- result types also to be a ReturnTv.
+ defer n fun_ty is_return
+ = do { arg_tys <- replicateM n new_flexi
; res_ty <- new_flexi
- ; co <- unifyType noThing fun_ty (mkFunTys arg_tys res_ty)
- ; return (co, arg_tys, res_ty) }
+ ; let unif_fun_ty = mkFunTys arg_tys res_ty
+ ; co <- if swap_tys
+ then mkTcSymCo <$> unifyType noThing unif_fun_ty fun_ty
+ else unifyType noThing fun_ty unif_fun_ty
+ ; return (mkWpCastN co, arg_tys, res_ty) }
where
-- preserve ReturnTv-ness
new_flexi :: TcM TcType
@@ -181,35 +268,26 @@ matchExpectedFunTys herald arity orig_ty
| otherwise = newOpenFlexiTyVarTy
------------
- mk_ctxt :: TidyEnv -> TcM (TidyEnv, MsgDoc)
- mk_ctxt env = do { (env', ty) <- zonkTidyTcType env orig_ty
- ; let (args, _) = tcSplitFunTys ty
- n_actual = length args
- (env'', orig_ty') = tidyOpenType env' orig_ty
- ; return (env'', mk_msg orig_ty' ty n_actual) }
-
- mk_msg orig_ty ty n_args
- = herald <+> speakNOf arity (ptext (sLit "argument")) <> comma $$
- if n_args == arity
- then ptext (sLit "its type is") <+> quotes (pprType orig_ty) <>
+ mk_ctxt :: [TcSigmaType] -> TcSigmaType -> TidyEnv -> TcM (TidyEnv, MsgDoc)
+ mk_ctxt arg_tys res_ty env
+ = do { let ty = mkFunTys arg_tys res_ty
+ ; (env1, zonked) <- zonkTidyTcType env ty
+ -- zonking might change # of args
+ ; let (zonked_args, _) = tcSplitFunTys zonked
+ n_actual = length zonked_args
+ (env2, unzonked) = tidyOpenType env1 ty
+ ; return (env2, mk_msg unzonked zonked n_actual) }
+
+ mk_msg full_ty ty n_args
+ = herald <+> speakNOf full_arity (text "argument") <> comma $$
+ if n_args == full_arity
+ then ptext (sLit "its type is") <+> quotes (pprType full_ty) <>
comma $$
ptext (sLit "it is specialized to") <+> quotes (pprType ty)
else sep [ptext (sLit "but its type") <+> quotes (pprType ty),
if n_args == 0 then ptext (sLit "has none")
else ptext (sLit "has only") <+> speakN n_args]
-{-
-Note [Foralls to left of arrow]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Consider
- f (x :: forall a. a -> a) = x
-We give 'f' the type (alpha -> beta), and then want to unify
-the alpha with (forall a. a->a). We want to the arg and result
-of (->) to be sort-polymorphic, and this also permits foralls, so
-we are ok. See Note [Sort-polymorphic tyvars accept foralls] in TcUnify
-and Note [TYPE] in TysPrim.
--}
-
----------------------
matchExpectedListTy :: TcRhoType -> TcM (TcCoercionN, TcRhoType)
-- Special case for lists
@@ -251,9 +329,9 @@ matchExpectedTyConApp tc orig_ty
= do { cts <- readMetaTyVar tv
; case cts of
Indirect ty -> go ty
- Flexi -> defer (isReturnTyVar tv) }
+ Flexi -> defer }
- go _ = defer False
+ go _ = defer
-- If the common case does not occur, instantiate a template
-- T k1 .. kn t1 .. tm, and unify with the original type
@@ -265,12 +343,12 @@ matchExpectedTyConApp tc orig_ty
-- (a::*) ~ Maybe
-- because that'll make types that are utterly ill-kinded.
-- This happened in Trac #7368
- defer is_return
+ defer
= ASSERT2( classifiesTypeWithValues res_kind, ppr tc )
do { (k_subst, kvs') <- newMetaTyVars kvs
; let arg_kinds' = substTys k_subst arg_kinds
kappa_tys = mkTyVarTys kvs'
- ; tau_tys <- mapM (newMaybeReturnTyVarTy is_return) arg_kinds'
+ ; tau_tys <- mapM newFlexiTyVarTy arg_kinds'
; co <- unifyType noThing (mkTyConApp tc (kappa_tys ++ tau_tys)) orig_ty
; return (co, kappa_tys ++ tau_tys) }
@@ -298,14 +376,14 @@ matchExpectedAppTy orig_ty
= do { cts <- readMetaTyVar tv
; case cts of
Indirect ty -> go ty
- Flexi -> defer (isReturnTyVar tv) }
+ Flexi -> defer }
- go _ = defer False
+ go _ = defer
-- Defer splitting by generating an equality constraint
- defer is_return
- = do { ty1 <- newMaybeReturnTyVarTy is_return kind1
- ; ty2 <- newMaybeReturnTyVarTy is_return kind2
+ defer
+ = do { ty1 <- newFlexiTyVarTy kind1
+ ; ty2 <- newFlexiTyVarTy kind2
; co <- unifyType noThing (mkAppTy ty1 ty2) orig_ty
; return (co, (ty1, ty2)) }
@@ -338,11 +416,26 @@ It returns a coercion function
which takes an HsExpr of type actual_ty into one of type
expected_ty.
+These functions do not actually check for subsumption. They check if
+expected_ty is an appropriate annotation to use for something of type
+actual_ty. This difference matters when thinking about visible type
+application. For example,
+
+ forall a. a -> forall b. b -> b
+ DOES NOT SUBSUME
+ forall a b. a -> b -> b
+
+because the type arguments appear in a different order. (Neither does
+it work the other way around.) BUT, these types are appropriate annotations
+for one another. Because the user directs annotations, it's OK if some
+arguments shuffle around -- after all, it's what the user wants.
+Bottom line: none of this changes with visible type application.
+
There are a number of wrinkles (below).
Notice that Wrinkle 1 and 2 both require eta-expansion, which technically
may increase termination. We just put up with this, in exchange for getting
-more predicatble type inference.
+more predictable type inference.
Wrinkle 1: Note [Deep skolemisation]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -350,7 +443,7 @@ We want (forall a. Int -> a -> a) <= (Int -> forall a. a->a)
(see section 4.6 of "Practical type inference for higher rank types")
So we must deeply-skolemise the RHS before we instantiate the LHS.
-That is why tc_sub_type starts with a call to tcGen (which does the
+That is why tc_sub_type starts with a call to tcSkolemise (which does the
deep skolemisation), and then calls the DS variant (which assumes
that expected_ty is deeply skolemised)
@@ -367,7 +460,7 @@ But f1 will only typecheck if we have that
(Int->Int) -> Int <= (forall a. a->a) -> Int
And that is only true if we do the full co/contravariant thing
in the subsumption check. That happens in the FunTy case of
-tc_sub_type_ds, and is the sole reason for the WpFun form of
+tcSubTypeDS_NC_O, and is the sole reason for the WpFun form of
HsWrapper.
Another powerful reason for doing this co/contra stuff is visible
@@ -387,30 +480,53 @@ So it's important that we unify beta := forall a. a->a, rather than
skolemising the type.
-}
-tcSubType :: UserTypeCtxt -> Maybe Id -- ^ If present, it has type ty_actual
+
+-- | Call this variant when you are in a higher-rank situation and
+-- you know the right-hand type is deeply skolemised.
+tcSubTypeHR :: Outputable a
+ => CtOrigin -- ^ of the actual type
+ -> Maybe a -- ^ If present, it has type ty_actual
+ -> TcSigmaType -> TcRhoType -> TcM HsWrapper
+tcSubTypeHR orig = tcSubTypeDS_NC_O orig GenSigCtxt
+
+tcSubType :: Outputable a
+ => UserTypeCtxt -> Maybe a -- ^ If present, it has type ty_actual
-> TcSigmaType -> TcSigmaType -> TcM HsWrapper
-- Checks that actual <= expected
-- Returns HsWrapper :: actual ~ expected
-tcSubType ctxt maybe_id ty_actual ty_expected
+tcSubType ctxt maybe_thing ty_actual ty_expected
= addSubTypeCtxt ty_actual ty_expected $
do { traceTc "tcSubType" (vcat [ pprUserTypeCtxt ctxt
- , ppr maybe_id
+ , ppr maybe_thing
, ppr ty_actual
, ppr ty_expected ])
- ; tc_sub_type origin ctxt ty_actual ty_expected }
+ ; tc_sub_type origin origin ctxt ty_actual ty_expected }
where
origin = TypeEqOrigin { uo_actual = ty_actual
, uo_expected = ty_expected
- , uo_thing = mkErrorThing <$> maybe_id }
+ , uo_thing = mkErrorThing <$> maybe_thing }
-tcSubTypeDS :: Outputable a => UserTypeCtxt -> a -- ^ has type ty_actual
+tcSubTypeDS :: Outputable a => UserTypeCtxt -> Maybe a -- ^ has type ty_actual
-> TcSigmaType -> TcRhoType -> TcM HsWrapper
-- Just like tcSubType, but with the additional precondition that
-- ty_expected is deeply skolemised (hence "DS")
-tcSubTypeDS ctxt expr ty_actual ty_expected
+tcSubTypeDS ctxt m_expr ty_actual ty_expected
= addSubTypeCtxt ty_actual ty_expected $
- tcSubTypeDS_NC ctxt (Just expr) ty_actual ty_expected
-
+ tcSubTypeDS_NC ctxt m_expr ty_actual ty_expected
+
+-- | Like 'tcSubTypeDS', but takes a 'CtOrigin' to use when instantiating
+-- the "actual" type
+tcSubTypeDS_O :: Outputable a
+ => CtOrigin -> UserTypeCtxt
+ -> Maybe a -> TcSigmaType -> TcRhoType
+ -> TcM HsWrapper
+tcSubTypeDS_O orig ctxt maybe_thing ty_actual ty_expected
+ = addSubTypeCtxt ty_actual ty_expected $
+ do { traceTc "tcSubTypeDS_O" (vcat [ pprCtOrigin orig
+ , pprUserTypeCtxt ctxt
+ , ppr ty_actual
+ , ppr ty_expected ])
+ ; tcSubTypeDS_NC_O orig ctxt maybe_thing ty_actual ty_expected }
addSubTypeCtxt :: TcType -> TcType -> TcM a -> TcM a
addSubTypeCtxt ty_actual ty_expected thing_inside
@@ -436,7 +552,7 @@ addSubTypeCtxt ty_actual ty_expected thing_inside
tcSubType_NC :: UserTypeCtxt -> TcSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubType_NC ctxt ty_actual ty_expected
= do { traceTc "tcSubType_NC" (vcat [pprUserTypeCtxt ctxt, ppr ty_actual, ppr ty_expected])
- ; tc_sub_type origin ctxt ty_actual ty_expected }
+ ; tc_sub_type origin origin ctxt ty_actual ty_expected }
where
origin = TypeEqOrigin { uo_actual = ty_actual
, uo_expected = ty_expected
@@ -448,57 +564,157 @@ tcSubTypeDS_NC :: Outputable a
-> TcSigmaType -> TcRhoType -> TcM HsWrapper
tcSubTypeDS_NC ctxt maybe_thing ty_actual ty_expected
= do { traceTc "tcSubTypeDS_NC" (vcat [pprUserTypeCtxt ctxt, ppr ty_actual, ppr ty_expected])
- ; tc_sub_type_ds origin ctxt ty_actual ty_expected }
+ ; tcSubTypeDS_NC_O origin ctxt maybe_thing ty_actual ty_expected }
where
origin = TypeEqOrigin { uo_actual = ty_actual
, uo_expected = ty_expected
, uo_thing = mkErrorThing <$> maybe_thing }
+tcSubTypeDS_NC_O :: Outputable a
+ => CtOrigin -- origin used for instantiation only
+ -> UserTypeCtxt
+ -> Maybe a
+ -> TcSigmaType -> TcRhoType -> TcM HsWrapper
+-- Just like tcSubType, but with the additional precondition that
+-- ty_expected is deeply skolemised
+tcSubTypeDS_NC_O inst_orig ctxt m_thing ty_actual ty_expected
+ = tc_sub_type_ds eq_orig inst_orig ctxt ty_actual ty_expected
+ where
+ eq_orig = TypeEqOrigin { uo_actual = ty_actual, uo_expected = ty_expected
+ , uo_thing = mkErrorThing <$> m_thing}
+
---------------
-tc_sub_type :: CtOrigin -> UserTypeCtxt -> TcSigmaType -> TcSigmaType -> TcM HsWrapper
-tc_sub_type origin ctxt ty_actual ty_expected
- | isTyVarTy ty_actual -- See Note [Higher rank types]
- = do { cow <- uType origin TypeLevel ty_actual ty_expected
- ; return (mkWpCastN cow) }
+tc_sub_type :: CtOrigin -- origin used when calling uType
+ -> CtOrigin -- origin used when instantiating
+ -> UserTypeCtxt -> TcSigmaType -> TcSigmaType -> TcM HsWrapper
+tc_sub_type eq_orig inst_orig ctxt ty_actual ty_expected
+ | Just tv_actual <- tcGetTyVar_maybe ty_actual -- See Note [Higher rank types]
+ = do { lookup_res <- lookupTcTyVar tv_actual
+ ; case lookup_res of
+ Filled ty_actual' -> tc_sub_type eq_orig inst_orig
+ ctxt ty_actual' ty_expected
+
+ -- It's tempting to see if tv_actual can unify with a polytype
+ -- and, if so, call uType; otherwise, skolemise first. But this
+ -- is wrong, because skolemising will bump the TcLevel and the
+ -- unification will fail anyway.
+ -- It's also tempting to call uUnfilledVar directly, but calling
+ -- uType seems safer in the presence of possible refactoring
+ -- later.
+ Unfilled _ -> mkWpCastN <$>
+ uType eq_orig TypeLevel ty_actual ty_expected }
| otherwise -- See Note [Deep skolemisation]
- = do { (sk_wrap, inner_wrap) <- tcGen ctxt ty_expected $ \ _ sk_rho ->
- tc_sub_type_ds origin ctxt ty_actual sk_rho
+ = do { (sk_wrap, inner_wrap) <- tcSkolemise ctxt ty_expected $
+ \ _ sk_rho ->
+ tc_sub_type_ds eq_orig inst_orig ctxt
+ ty_actual sk_rho
; return (sk_wrap <.> inner_wrap) }
---------------
-tc_sub_type_ds :: CtOrigin -> UserTypeCtxt -> TcSigmaType -> TcRhoType -> TcM HsWrapper
+tc_sub_type_ds :: CtOrigin -- used when calling uType
+ -> CtOrigin -- used when instantiating
+ -> UserTypeCtxt -> TcSigmaType -> TcRhoType -> TcM HsWrapper
-- Just like tcSubType, but with the additional precondition that
-- ty_expected is deeply skolemised
-tc_sub_type_ds origin ctxt ty_actual ty_expected
- | Just (act_arg, act_res) <- tcSplitFunTy_maybe ty_actual
- , Just (exp_arg, exp_res) <- tcSplitFunTy_maybe ty_expected
- = -- See Note [Co/contra-variance of subsumption checking]
- do { res_wrap <- tc_sub_type_ds origin ctxt act_res exp_res
- ; arg_wrap <- tc_sub_type origin ctxt exp_arg act_arg
- ; return (mkWpFun arg_wrap res_wrap exp_arg exp_res) }
- -- arg_wrap :: exp_arg ~ act_arg
- -- res_wrap :: act-res ~ exp_res
-
- | (tvs, theta, in_rho) <- tcSplitSigmaTy ty_actual
- , not (null tvs && null theta)
- = do { (subst, tvs') <- newMetaTyVars tvs
- ; let tys' = mkTyVarTys tvs'
- theta' = substTheta subst theta
- in_rho' = substTy subst in_rho
- ; in_wrap <- instCall origin tys' theta'
- ; body_wrap <- tcSubTypeDS_NC ctxt noThing in_rho' ty_expected
- ; return (body_wrap <.> in_wrap) }
-
- | otherwise -- Revert to unification
- = do { cow <- uType origin TypeLevel ty_actual ty_expected
- ; return (mkWpCastN cow) }
+tc_sub_type_ds eq_orig inst_orig ctxt ty_actual ty_expected
+ = go ty_actual ty_expected
+ where
+ go ty_a ty_e | Just ty_a' <- coreView ty_a = go ty_a' ty_e
+ | Just ty_e' <- coreView ty_e = go ty_a ty_e'
+
+ go (TyVarTy tv_a) ty_e
+ = do { lookup_res <- lookupTcTyVar tv_a
+ ; case lookup_res of
+ Filled ty_a' ->
+ do { traceTc "tcSubTypeDS_NC_O following filled act meta-tyvar:"
+ (ppr tv_a <+> text "-->" <+> ppr ty_a')
+ ; tc_sub_type_ds eq_orig inst_orig ctxt ty_a' ty_e }
+ Unfilled _ -> mkWpCastN <$> unify }
+
+
+ go ty_a (TyVarTy tv_e)
+ = do { dflags <- getDynFlags
+ ; tclvl <- getTcLevel
+ ; lookup_res <- lookupTcTyVar tv_e
+ ; case lookup_res of
+ Filled ty_e' ->
+ do { traceTc "tcSubTypeDS_NC_O following filled exp meta-tyvar:"
+ (ppr tv_e <+> text "-->" <+> ppr ty_e')
+ ; tc_sub_type eq_orig inst_orig ctxt ty_a ty_e' }
+ Unfilled details
+ | canUnifyWithPolyType dflags details
+ && isTouchableMetaTyVar tclvl tv_e -- don't want skolems here
+ -> mkWpCastN <$> unify
+
+ -- We've avoided instantiating ty_actual just in case ty_expected is
+ -- polymorphic. But we've now assiduously determined that it is *not*
+ -- polymorphic. So instantiate away. This is needed for e.g. test
+ -- typecheck/should_compile/T4284.
+ | otherwise
+ -> do { (wrap, rho_a) <- deeplyInstantiate inst_orig ty_actual
+
+ -- if we haven't recurred through an arrow, then
+ -- the eq_orig will list ty_actual. In this case,
+ -- we want to update the origin to reflect the
+ -- instantiation. If we *have* recurred through
+ -- an arrow, it's better not to update.
+ ; let eq_orig' = case eq_orig of
+ TypeEqOrigin { uo_actual = orig_ty_actual
+ , uo_expected = orig_ty_expected
+ , uo_thing = thing }
+ | orig_ty_actual `tcEqType` ty_actual
+ -> TypeEqOrigin
+ { uo_actual = rho_a
+ , uo_expected = orig_ty_expected
+ , uo_thing = thing }
+ _ -> eq_orig
+
+ ; cow <- uType eq_orig' TypeLevel rho_a ty_expected
+ ; return (mkWpCastN cow <.> wrap) } }
+
+ go (ForAllTy (Anon act_arg) act_res) (ForAllTy (Anon exp_arg) exp_res)
+ | not (isPredTy act_arg)
+ , not (isPredTy exp_arg)
+ = -- See Note [Co/contra-variance of subsumption checking]
+ do { res_wrap <- tc_sub_type_ds eq_orig inst_orig ctxt act_res exp_res
+ ; arg_wrap
+ <- tc_sub_type eq_orig (GivenOrigin (SigSkol GenSigCtxt exp_arg))
+ ctxt exp_arg act_arg
+ ; return (mkWpFun arg_wrap res_wrap exp_arg exp_res) }
+ -- arg_wrap :: exp_arg ~ act_arg
+ -- res_wrap :: act-res ~ exp_res
+
+ go ty_a ty_e
+ | let (tvs, theta, _) = tcSplitSigmaTy ty_a
+ , not (null tvs && null theta)
+ = do { (in_wrap, in_rho) <- topInstantiate inst_orig ty_a
+ ; body_wrap <- tcSubTypeDS_NC_O inst_orig ctxt noThing in_rho ty_e
+ ; return (body_wrap <.> in_wrap) }
+
+ | otherwise -- Revert to unification
+ = do { cow <- unify
+ ; return (mkWpCastN cow) }
+
+ -- use versions without synonyms expanded
+ unify = uType eq_orig TypeLevel ty_actual ty_expected
-----------------
-tcWrapResult :: HsExpr TcId -> TcRhoType -> TcRhoType -> TcM (HsExpr TcId)
-tcWrapResult expr actual_ty res_ty
- = do { cow <- tcSubTypeDS GenSigCtxt expr actual_ty res_ty
- -- Both types are deeply skolemised
+-- needs both un-type-checked (for origins) and type-checked (for wrapping)
+-- expressions
+tcWrapResult :: HsExpr Name -> HsExpr TcId -> TcSigmaType -> TcRhoType
+ -> TcM (HsExpr TcId)
+tcWrapResult rn_expr = tcWrapResultO (exprCtOrigin rn_expr)
+
+-- | Sometimes we don't have a @HsExpr Name@ to hand, and this is more
+-- convenient.
+tcWrapResultO :: CtOrigin -> HsExpr TcId -> TcSigmaType -> TcRhoType
+ -> TcM (HsExpr TcId)
+tcWrapResultO orig expr actual_ty res_ty
+ = do { traceTc "tcWrapResult" (vcat [ text "Actual: " <+> ppr actual_ty
+ , text "Expected:" <+> ppr res_ty ])
+ ; cow <- tcSubTypeDS_NC_O orig GenSigCtxt
+ (Just expr) actual_ty res_ty
; return (mkHsWrap cow expr) }
-----------------------------------
@@ -540,23 +756,26 @@ tcInfer tc_check
************************************************************************
-}
-tcGen :: UserTypeCtxt -> TcType
- -> ([TcTyVar] -> TcRhoType -> TcM result)
+-- | Take an "expected type" and strip off quantifiers to expose the
+-- type underneath, binding the new skolems for the @thing_inside@.
+-- The returned 'HsWrapper' has type @specific_ty -> expected_ty@.
+tcSkolemise :: UserTypeCtxt -> TcSigmaType
+ -> ([TcTyVar] -> TcType -> TcM result)
-- ^ thing_inside is passed only the *type* variables, not
-- *coercion* variables. They are only ever used for scoped type
-- variables.
- -> TcM (HsWrapper, result)
- -- ^ The expression has type: spec_ty -> expected_ty
+ -> TcM (HsWrapper, result)
+ -- ^ The expression has type: spec_ty -> expected_ty
-tcGen ctxt expected_ty thing_inside
+tcSkolemise ctxt expected_ty thing_inside
-- We expect expected_ty to be a forall-type
-- If not, the call is a no-op
- = do { traceTc "tcGen" Outputable.empty
+ = do { traceTc "tcSkolemise" Outputable.empty
; (wrap, tvs', given, rho') <- deeplySkolemise expected_ty
; lvl <- getTcLevel
; when debugIsOn $
- traceTc "tcGen" $ vcat [
+ traceTc "tcSkolemise" $ vcat [
ppr lvl,
text "expected_ty" <+> ppr expected_ty,
text "inst tyvars" <+> ppr tvs',
@@ -613,7 +832,7 @@ buildImplication skol_info skol_tvs given thing_inside
then do { res <- thing_inside
; return (emptyBag, emptyTcEvBinds, res) }
-- Fast path. We check every function argument with
- -- tcPolyExpr, which uses tcGen and hence checkConstraints.
+ -- tcPolyExpr, which uses tcSkolemise and hence checkConstraints.
-- But with the solver producing unlifted equalities, we need
-- to have an EvBindsVar for them when they might be deferred to
-- runtime. Otherwise, they end up as top-level unlifted bindings,
diff --git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs
index 9555c0704a..98b78db450 100644
--- a/compiler/typecheck/TcValidity.hs
+++ b/compiler/typecheck/TcValidity.hs
@@ -309,11 +309,12 @@ checkValidType ctxt ty
RuleSigCtxt _ -> rank1
TySynCtxt _ -> rank0
- ExprSigCtxt -> rank1
- FunSigCtxt {} -> rank1
- InfSigCtxt _ -> ArbitraryRank -- Inferred type
- ConArgCtxt _ -> rank1 -- We are given the type of the entire
- -- constructor, hence rank 1
+ ExprSigCtxt -> rank1
+ TypeAppCtxt -> rank0
+ FunSigCtxt {} -> rank1
+ InfSigCtxt _ -> ArbitraryRank -- Inferred type
+ ConArgCtxt _ -> rank1 -- We are given the type of the entire
+ -- constructor, hence rank 1
ForSigCtxt _ -> rank1
SpecInstCtxt -> rank1
@@ -381,6 +382,7 @@ expectedKindInCtxt GhciCtxt = AnythingKind
-- The types in a 'default' decl can have varying kinds
-- See Note [Extended defaults]" in TcEnv
expectedKindInCtxt DefaultDeclCtxt = AnythingKind
+expectedKindInCtxt TypeAppCtxt = AnythingKind
expectedKindInCtxt (ForSigCtxt _) = TheKind liftedTypeKind
expectedKindInCtxt InstDeclCtxt = TheKind constraintKind
expectedKindInCtxt SpecInstCtxt = TheKind constraintKind
@@ -791,6 +793,7 @@ okIPCtxt :: UserTypeCtxt -> Bool
okIPCtxt (FunSigCtxt {}) = True
okIPCtxt (InfSigCtxt {}) = True
okIPCtxt ExprSigCtxt = True
+okIPCtxt TypeAppCtxt = True
okIPCtxt PatSigCtxt = True
okIPCtxt ResSigCtxt = True
okIPCtxt GenSigCtxt = True
@@ -1080,7 +1083,7 @@ checkValidInstance ctxt hs_type ty
else checkInstTermination inst_tys theta
; case (checkInstCoverage undecidable_ok clas theta inst_tys) of
- IsValid -> return () -- Check succeeded
+ IsValid -> return () -- Check succeeded
NotValid msg -> addErrTc (instTypeErr clas inst_tys msg)
; return (tvs, theta, clas, inst_tys) }
diff --git a/compiler/types/TyCoRep.hs b/compiler/types/TyCoRep.hs
index 48f7c0f9a9..fd39a17133 100644
--- a/compiler/types/TyCoRep.hs
+++ b/compiler/types/TyCoRep.hs
@@ -38,9 +38,11 @@ module TyCoRep (
mkFunTy, mkFunTys,
isLiftedTypeKind, isUnliftedTypeKind,
isCoercionType, isLevityTy, isLevityVar,
+ sameVis,
-- Functions over binders
- binderType, delBinderVar,
+ binderType, delBinderVar, isInvisibleBinder, isVisibleBinder,
+ isNamedBinder, isAnonBinder,
-- Functions over coercions
pickLR,
@@ -228,19 +230,32 @@ data TyBinder
| Anon Type -- visibility is determined by the type (Constraint vs. *)
deriving (Data.Typeable, Data.Data)
--- | Is something required to appear in source Haskell ('Visible') or
--- prohibited from appearing in source Haskell ('Invisible')?
-data VisibilityFlag = Visible | Invisible
+-- | Is something required to appear in source Haskell ('Visible'),
+-- permitted by request ('Specified') (visible type application), or
+-- prohibited entirely from appearing in source Haskell ('Invisible')?
+-- Examples in Note [VisibilityFlag]
+data VisibilityFlag = Visible | Specified | Invisible
deriving (Eq, Data.Typeable, Data.Data)
+-- | Do these denote the same level of visibility? Except that
+-- 'Specified' and 'Invisible' are considered the same. Used
+-- for printing.
+sameVis :: VisibilityFlag -> VisibilityFlag -> Bool
+sameVis Visible Visible = True
+sameVis Visible _ = False
+sameVis _ Visible = False
+sameVis _ _ = True
+
instance Binary VisibilityFlag where
put_ bh Visible = putByte bh 0
- put_ bh Invisible = putByte bh 1
+ put_ bh Specified = putByte bh 1
+ put_ bh Invisible = putByte bh 2
get bh = do
h <- getByte bh
case h of
0 -> return Visible
+ 1 -> return Specified
_ -> return Invisible
type KindOrType = Type -- See Note [Arguments to type constructors]
@@ -309,6 +324,49 @@ two types have the same kind. This allows us to be a little sloppier
in keeping track of coercions, which is a good thing. It also means
that eqType does not depend on eqCoercion, which is also a good thing.
+Note [VisibilityFlag]
+~~~~~~~~~~~~~~~~~~~~~
+All named binders are equipped with a visibility flag, which says
+whether or not arguments for this binder should be visible (explicit)
+in source Haskell. Historically, all named binders (that is, polytype
+binders) have been Invisible. But now it's more complicated.
+
+Invisible:
+ Argument does not ever appear in source Haskell. With visible type
+ application, only GHC-generated polytypes have Invisible binders.
+ This exactly corresponds to "generalized" variables from the
+ Visible Type Applications paper (ESOP'16).
+
+ Example: f x = x
+ `f` will be inferred to have type `forall a. a -> a`, where `a` is
+ Invisible. Note that there is no type annotation for `f`.
+
+ Printing: With -fprint-explicit-foralls, Invisible binders are written
+ in braces. Otherwise, they are printed like Specified binders.
+
+Specified:
+ The argument for this binder may appear in source Haskell only with
+ visible type application. Otherwise, it is omitted.
+
+ Example: id :: forall a. a -> a
+ `a` is a Specified binder, because you can say `id @Int` in source Haskell.
+
+ Example: const :: a -> b -> a
+ Both `a` and `b` are Specified binders, even though they are not bound
+ by an explicit forall.
+
+ Printing: a list of Specified binders are put between `forall` and `.`:
+ const :: forall a b. a -> b -> a
+
+Visible:
+ The argument must be given. Visible binders come up only with TypeInType.
+
+ Example: data Proxy k (a :: k) = P
+ The kind of Proxy is forall k -> k -> *, where k is a Visible binder.
+
+ Printing: As in the example above, Visible binders are put between `forall`
+ and `->`. This syntax is not parsed (yet), however.
+
-------------------------------------
Note [PredTy]
-}
@@ -403,6 +461,23 @@ delBinderVarFV :: TyBinder -> FV -> FV
delBinderVarFV (Named tv _) vars fv_cand in_scope acc = delFV tv vars fv_cand in_scope acc
delBinderVarFV (Anon {}) vars fv_cand in_scope acc = vars fv_cand in_scope acc
+-- | Does this binder bind an invisible argument?
+isInvisibleBinder :: TyBinder -> Bool
+isInvisibleBinder (Named _ vis) = vis /= Visible
+isInvisibleBinder (Anon ty) = isPredTy ty
+
+-- | Does this binder bind a visible argument?
+isVisibleBinder :: TyBinder -> Bool
+isVisibleBinder = not . isInvisibleBinder
+
+isNamedBinder :: TyBinder -> Bool
+isNamedBinder (Named {}) = True
+isNamedBinder _ = False
+
+isAnonBinder :: TyBinder -> Bool
+isAnonBinder (Anon {}) = True
+isAnonBinder _ = False
+
-- | Create the plain type constructor type which has been applied to no type arguments at all.
mkTyConTy :: TyCon -> Type
mkTyConTy tycon = TyConApp tycon []
@@ -2063,10 +2138,11 @@ ppr_type _ (CoercionTy co)
ppr_forall_type :: TyPrec -> Type -> SDoc
ppr_forall_type p ty
- = maybeParen p FunPrec $ ppr_sigma_type True ty
+ = maybeParen p FunPrec $
+ sdocWithDynFlags $ \dflags ->
+ ppr_sigma_type dflags True ty
-- True <=> we always print the foralls on *nested* quantifiers
-- Opt_PrintExplicitForalls only affects top-level quantifiers
- -- False <=> we don't print an extra-constraints wildcard
ppr_tvar :: TyVar -> SDoc
ppr_tvar tv -- Note [Infix type variables]
@@ -2090,13 +2166,27 @@ if_print_coercions yes no
else no
-------------------
-ppr_sigma_type :: Bool -> Type -> SDoc
--- First Bool <=> Show the foralls unconditionally
--- Second Bool <=> Show an extra-constraints wildcard
-ppr_sigma_type show_foralls_unconditionally ty
- = sep [ if show_foralls_unconditionally
- then pprForAll bndrs
- else pprUserForAll bndrs
+ppr_sigma_type :: DynFlags
+ -> Bool -- ^ True <=> Show the foralls unconditionally
+ -> Type -> SDoc
+-- Suppose we have (forall a. Show a => forall b. a -> b). When we're not
+-- printing foralls, we want to drop both the (forall a) and the (forall b).
+-- This logic does so.
+ppr_sigma_type dflags False orig_ty
+ | not (gopt Opt_PrintExplicitForalls dflags)
+ , all (isEmptyVarSet . tyCoVarsOfType . binderType) named
+ -- See Note [When to print foralls]
+ = sep [ pprThetaArrowTy (map binderType ctxt)
+ , pprArrowChain TopPrec (ppr_fun_tail tau) ]
+ where
+ (invis_bndrs, tau) = split [] orig_ty
+ (named, ctxt) = partition isNamedBinder invis_bndrs
+
+ split acc (ForAllTy bndr ty) | isInvisibleBinder bndr = split (bndr:acc) ty
+ split acc ty = (reverse acc, ty)
+
+ppr_sigma_type _ _ ty
+ = sep [ pprForAll bndrs
, pprThetaArrowTy ctxt
, pprArrowChain TopPrec (ppr_fun_tail tau) ]
where
@@ -2110,12 +2200,13 @@ ppr_sigma_type show_foralls_unconditionally ty
split2 ps ty = (reverse ps, ty)
-- We don't want to lose synonyms, so we mustn't use splitFunTys here.
- ppr_fun_tail (ForAllTy (Anon ty1) ty2)
- | not (isPredTy ty1) = ppr_type FunPrec ty1 : ppr_fun_tail ty2
- ppr_fun_tail other_ty = [ppr_type TopPrec other_ty]
+ppr_fun_tail :: Type -> [SDoc]
+ppr_fun_tail (ForAllTy (Anon ty1) ty2)
+ | not (isPredTy ty1) = ppr_type FunPrec ty1 : ppr_fun_tail ty2
+ppr_fun_tail other_ty = [ppr_type TopPrec other_ty]
pprSigmaType :: Type -> SDoc
-pprSigmaType ty = ppr_sigma_type False ty
+pprSigmaType ty = sdocWithDynFlags $ \dflags -> ppr_sigma_type dflags False ty
pprUserForAll :: [TyBinder] -> SDoc
-- Print a user-level forall; see Note [When to print foralls]
@@ -2128,7 +2219,7 @@ pprUserForAll bndrs
= not (isEmptyVarSet (tyCoVarsOfType (binderType bndr)))
pprForAllImplicit :: [TyVar] -> SDoc
-pprForAllImplicit tvs = pprForAll (zipWith Named tvs (repeat Invisible))
+pprForAllImplicit tvs = pprForAll (zipWith Named tvs (repeat Specified))
-- | Render the "forall ... ." or "forall ... ->" bit of a type.
-- Do not pass in anonymous binders!
@@ -2140,8 +2231,8 @@ pprForAll bndrs@(Named _ vis : _)
(bndrs', doc) = ppr_tv_bndrs bndrs vis
add_separator stuff = case vis of
- Invisible -> stuff <> dot
Visible -> stuff <+> arrow
+ _inv -> stuff <> dot
pprForAll bndrs = pprPanic "pprForAll: anonymous binder" (ppr bndrs)
pprTvBndrs :: [TyVar] -> SDoc
@@ -2154,8 +2245,14 @@ ppr_tv_bndrs :: [TyBinder]
-> VisibilityFlag -- ^ visibility of the first binder in the list
-> ([TyBinder], SDoc)
ppr_tv_bndrs all_bndrs@(Named tv vis : bndrs) vis1
- | vis == vis1 = let (bndrs', doc) = ppr_tv_bndrs bndrs vis1 in
- (bndrs', pprTvBndr tv <+> doc)
+ | vis `sameVis` vis1 = let (bndrs', doc) = ppr_tv_bndrs bndrs vis1
+ pp_tv = sdocWithDynFlags $ \dflags ->
+ if Invisible == vis &&
+ gopt Opt_PrintExplicitForalls dflags
+ then braces (pprTvBndrNoParens tv)
+ else pprTvBndr tv
+ in
+ (bndrs', pp_tv <+> doc)
| otherwise = (all_bndrs, empty)
ppr_tv_bndrs [] _ = ([], empty)
ppr_tv_bndrs bndrs _ = pprPanic "ppr_tv_bndrs: anonymous binder" (ppr bndrs)
@@ -2167,13 +2264,22 @@ pprTvBndr tv
where
kind = tyVarKind tv
+pprTvBndrNoParens :: TyVar -> SDoc
+pprTvBndrNoParens tv
+ | isLiftedTypeKind kind = ppr_tvar tv
+ | otherwise = ppr_tvar tv <+> dcolon <+> pprKind kind
+ where
+ kind = tyVarKind tv
+
instance Outputable TyBinder where
ppr (Named v Visible) = ppr v
+ ppr (Named v Specified) = char '@' <> ppr v
ppr (Named v Invisible) = braces (ppr v)
ppr (Anon ty) = text "[anon]" <+> ppr ty
instance Outputable VisibilityFlag where
ppr Visible = text "[vis]"
+ ppr Specified = text "[spec]"
ppr Invisible = text "[invis]"
-----------------
@@ -2231,7 +2337,7 @@ pprDataConWithArgs :: DataCon -> SDoc
pprDataConWithArgs dc = sep [forAllDoc, thetaDoc, ppr dc <+> argsDoc]
where
(univ_tvs, ex_tvs, eq_spec, theta, arg_tys, _res_ty) = dataConFullSig dc
- forAllDoc = pprUserForAll $ map (\tv -> Named tv Invisible) $
+ forAllDoc = pprUserForAll $ map (\tv -> Named tv Specified) $
((univ_tvs `minusList` map eqSpecTyVar eq_spec) ++ ex_tvs)
thetaDoc = pprThetaArrowTy theta
argsDoc = hsep (fmap pprParendType arg_tys)
diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs
index 685ec830f1..fbb59542f8 100644
--- a/compiler/types/Type.hs
+++ b/compiler/types/Type.hs
@@ -35,7 +35,8 @@ module Type (
splitListTyConApp_maybe,
repSplitTyConApp_maybe,
- mkForAllTy, mkForAllTys, mkInvForAllTys, mkVisForAllTys,
+ mkForAllTy, mkForAllTys, mkInvForAllTys, mkSpecForAllTys,
+ mkVisForAllTys,
mkNamedForAllTy,
splitForAllTy_maybe, splitForAllTys, splitForAllTy,
splitPiTy_maybe, splitPiTys, splitPiTy,
@@ -83,6 +84,7 @@ module Type (
predTypeEqRel,
-- ** Binders
+ sameVis,
mkNamedBinder, mkAnonBinder, isNamedBinder, isAnonBinder,
isIdLikeBinder, binderVisibility, binderVar_maybe,
binderVar, binderRelevantType_maybe, caseBinder,
@@ -1187,6 +1189,12 @@ mkInvForAllTys :: [TyVar] -> Type -> Type
mkInvForAllTys tvs = ASSERT( all isTyVar tvs )
mkForAllTys (map (flip Named Invisible) tvs)
+-- | Like mkForAllTys, but assumes all variables are dependent and specified,
+-- a common case
+mkSpecForAllTys :: [TyVar] -> Type -> Type
+mkSpecForAllTys tvs = ASSERT( all isTyVar tvs )
+ mkForAllTys (map (flip Named Specified) tvs)
+
-- | Like mkForAllTys, but assumes all variables are dependent and visible
mkVisForAllTys :: [TyVar] -> Type -> Type
mkVisForAllTys tvs = ASSERT( all isTyVar tvs )
@@ -1196,6 +1204,7 @@ mkPiType :: Var -> Type -> Type
-- ^ Makes a @(->)@ type or an implicit forall type, depending
-- on whether it is given a type variable or a term variable.
-- This is used, for example, when producing the type of a lambda.
+-- Always uses Invisible binders.
mkPiTypes :: [Var] -> Type -> Type
-- ^ 'mkPiType' for multiple type or value arguments
@@ -1422,14 +1431,6 @@ mkNamedBinder = Named
mkAnonBinder :: Type -> TyBinder
mkAnonBinder = Anon
-isNamedBinder :: TyBinder -> Bool
-isNamedBinder (Named {}) = True
-isNamedBinder _ = False
-
-isAnonBinder :: TyBinder -> Bool
-isAnonBinder (Anon {}) = True
-isAnonBinder _ = False
-
-- | Does this binder bind a variable that is /not/ erased? Returns
-- 'True' for anonymous binders.
isIdLikeBinder :: TyBinder -> Bool
@@ -1448,15 +1449,6 @@ binderVisibility (Anon ty)
| isVisibleType ty = Visible
| otherwise = Invisible
--- | Does this binder bind an invisible argument?
-isInvisibleBinder :: TyBinder -> Bool
-isInvisibleBinder (Named _ vis) = vis == Invisible
-isInvisibleBinder (Anon ty) = isPredTy ty
-
--- | Does this binder bind a visible argument?
-isVisibleBinder :: TyBinder -> Bool
-isVisibleBinder = not . isInvisibleBinder
-
-- | Extract a bound variable in a binder, if any
binderVar_maybe :: TyBinder -> Maybe Var
binderVar_maybe (Named v _) = Just v
diff --git a/docs/users_guide/7.12.1-notes.rst b/docs/users_guide/7.12.1-notes.rst
index bb4c55e71e..81609423ca 100644
--- a/docs/users_guide/7.12.1-notes.rst
+++ b/docs/users_guide/7.12.1-notes.rst
@@ -83,6 +83,11 @@ Language
See :ref:`lib-base` for a description of the ``CallStack`` type.
+- GHC now supports visible type application, allowing
+ programmers to easily specify how type parameters should be
+ instantiated when calling a function. See
+ :ref:`visible-type-application` for the details.
+
- To conform to the common case, the default role assigned to
parameters of datatypes declared in ``hs-boot`` files is
``representational``. However, if the constructor(s) for the datatype
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index d847517140..8a5b9b6138 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -2245,6 +2245,56 @@ data constructor in an import or export list with the keyword
``pattern``, to allow the import or export of a data constructor without
its parent type constructor (see :ref:`patsyn-impexp`).
+.. _visible-type-application:
+
+Visible type application
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+The ``-XTypeApplications`` extension allows you to use
+*visible type application* in expressions. Here is an
+example: ``show (read @Int "5")``. The ``@Int``
+is the visible type application; it specifies the value of the type variable
+in ``read``'s type.
+
+A visible type application is preceded with an ``@``
+sign. (To disambiguate the syntax, the ``@`` must be
+preceded with a non-identifier letter, usually a space. For example,
+``read@Int 5`` would not parse.) It can be used whenever
+the full polymorphic type of the function is known. If the function
+is an identifier (the common case), its type is considered known only when
+the identifier has been given a type signature. If the identifier does
+not have a type signature, visible type application cannot be used.
+
+Here are the details:
+
+- If an identifier's type signature does not include an
+ explicit ``forall``, the type variable arguments appear
+ in the left-to-right order in which the variables appear in the type.
+ So, ``foo :: Monad m => a b -> m (a c)``
+ will have its type variables
+ ordered as ``m, a, b, c``.
+
+- Class methods' type arguments include the class type
+ variables, followed by any variables an individual method is polymorphic
+ in. So, ``class Monad m where return :: a -> m a`` means
+ that ``return``'s type arguments are ``m, a``.
+
+- With the ``-XRankNTypes`` extension
+ (:ref:`universal-quantification`), it is possible to declare
+ type arguments somewhere other than the beginning of a type. For example,
+ we can have ``pair :: forall a. a -> forall b. b -> (a, b)``
+ and then say ``pair @Bool True @Char`` which would have
+ type ``Char -> (Bool, Char)``.
+
+- Partial type signatures (:ref:`partial-type-signatures`)
+ work nicely with visible type
+ application. If you want to specify only the second type argument to
+ ``wurble``, then you can say ``wurble @_ @Int``.
+ The first argument is a wildcard, just like in a partial type signature.
+ However, if used in a visible type application, it is *not*
+ necessary to specify ``-XPartialTypeSignatures`` and your
+ code will not generate a warning informing you of the omitted type.
+
.. _syntax-stolen:
Summary of stolen syntax
diff --git a/libraries/base/tests/T9681.stderr b/libraries/base/tests/T9681.stderr
index 7945ff7353..af6e7dc63a 100644
--- a/libraries/base/tests/T9681.stderr
+++ b/libraries/base/tests/T9681.stderr
@@ -1,5 +1,5 @@
-T9681.hs:3:9:
+T9681.hs:3:7: error:
No instance for (Num [Char]) arising from a use of ‘+’
In the expression: 1 + "\n"
In an equation for ‘foo’: foo = 1 + "\n"
diff --git a/libraries/ghc-boot/GHC/LanguageExtensions.hs b/libraries/ghc-boot/GHC/LanguageExtensions.hs
index 39c1b11bf4..68455194e6 100644
--- a/libraries/ghc-boot/GHC/LanguageExtensions.hs
+++ b/libraries/ghc-boot/GHC/LanguageExtensions.hs
@@ -120,6 +120,7 @@ data Extension
| PartialTypeSignatures
| NamedWildCards
| StaticPointers
+ | TypeApplications
| Strict
| StrictData
| MonadFailDesugaring
diff --git a/testsuite/tests/ado/ado002.stderr b/testsuite/tests/ado/ado002.stderr
index cdfdbc4b19..9e7eba0a67 100644
--- a/testsuite/tests/ado/ado002.stderr
+++ b/testsuite/tests/ado/ado002.stderr
@@ -1,55 +1,81 @@
ado002.hs:8:8: error:
- Couldn't match expected type ‘Char -> IO t1’
- with actual type ‘IO Char’
- The function ‘getChar’ is applied to one argument,
- but its type ‘IO Char’ has none
- In a stmt of a 'do' block: y <- getChar 'a'
- In the expression:
- do { x <- getChar;
- y <- getChar 'a';
- print (x, y) }
+ • Couldn't match expected type ‘Char -> IO t1’
+ with actual type ‘IO Char’
+ • The function ‘getChar’ is applied to one argument,
+ but its type ‘IO Char’ has none
+ In a stmt of a 'do' block: y <- getChar 'a'
+ In the expression:
+ do { x <- getChar;
+ y <- getChar 'a';
+ print (x, y) }
ado002.hs:9:3: error:
- Couldn't match type ‘()’ with ‘Int’
- Expected type: IO Int
- Actual type: IO ()
- In a stmt of a 'do' block: print (x, y)
- In the expression:
- do { x <- getChar;
- y <- getChar 'a';
- print (x, y) }
+ • Couldn't match type ‘()’ with ‘Int’
+ Expected type: IO Int
+ Actual type: IO ()
+ • In a stmt of a 'do' block: print (x, y)
+ In the expression:
+ do { x <- getChar;
+ y <- getChar 'a';
+ print (x, y) }
+ In an equation for ‘f’:
+ f = do { x <- getChar;
+ y <- getChar 'a';
+ print (x, y) }
ado002.hs:15:11: error:
- Couldn't match expected type ‘Int’ with actual type ‘Char’
- In the expression: y
- In a stmt of a 'do' block: return (y, x)
+ • Couldn't match expected type ‘Int’ with actual type ‘Char’
+ • In the expression: y
+ In a stmt of a 'do' block: return (y, x)
+ In the expression:
+ do { x <- getChar;
+ y <- getChar;
+ return (y, x) }
ado002.hs:15:13: error:
- Couldn't match expected type ‘Int’ with actual type ‘Char’
- In the expression: x
- In a stmt of a 'do' block: return (y, x)
+ • Couldn't match expected type ‘Int’ with actual type ‘Char’
+ • In the expression: x
+ In a stmt of a 'do' block: return (y, x)
+ In the expression:
+ do { x <- getChar;
+ y <- getChar;
+ return (y, x) }
ado002.hs:23:9: error:
- Couldn't match expected type ‘Char -> IO t0’
- with actual type ‘IO Char’
- The function ‘getChar’ is applied to one argument,
- but its type ‘IO Char’ has none
- In a stmt of a 'do' block: x5 <- getChar x4
- In the expression:
- do { x1 <- getChar;
- x2 <- getChar;
- x3 <- const (return ()) x1;
- x4 <- getChar;
- x5 <- getChar x4;
- return (x2, x4) }
+ • Couldn't match expected type ‘Char -> IO t0’
+ with actual type ‘IO Char’
+ • The function ‘getChar’ is applied to one argument,
+ but its type ‘IO Char’ has none
+ In a stmt of a 'do' block: x5 <- getChar x4
+ In the expression:
+ do { x1 <- getChar;
+ x2 <- getChar;
+ x3 <- const (return ()) x1;
+ x4 <- getChar;
+ x5 <- getChar x4;
+ return (x2, x4) }
ado002.hs:24:11: error:
- Couldn't match expected type ‘Int’ with actual type ‘Char’
- In the expression: x2
- In a stmt of a 'do' block: return (x2, x4)
+ • Couldn't match expected type ‘Int’ with actual type ‘Char’
+ • In the expression: x2
+ In a stmt of a 'do' block: return (x2, x4)
+ In the expression:
+ do { x1 <- getChar;
+ x2 <- getChar;
+ x3 <- const (return ()) x1;
+ x4 <- getChar;
+ x5 <- getChar x4;
+ return (x2, x4) }
ado002.hs:24:14: error:
- Couldn't match expected type ‘Int’ with actual type ‘Char’
- In the expression: x4
- In a stmt of a 'do' block: return (x2, x4)
+ • Couldn't match expected type ‘Int’ with actual type ‘Char’
+ • In the expression: x4
+ In a stmt of a 'do' block: return (x2, x4)
+ In the expression:
+ do { x1 <- getChar;
+ x2 <- getChar;
+ x3 <- const (return ()) x1;
+ x4 <- getChar;
+ x5 <- getChar x4;
+ return (x2, x4) }
diff --git a/testsuite/tests/annotations/should_fail/annfail08.stderr b/testsuite/tests/annotations/should_fail/annfail08.stderr
index 6fafaf919e..47a54243fe 100644
--- a/testsuite/tests/annotations/should_fail/annfail08.stderr
+++ b/testsuite/tests/annotations/should_fail/annfail08.stderr
@@ -5,7 +5,7 @@ annfail08.hs:9:1: error:
(maybe you haven't applied a function to enough arguments?)
• In the annotation: {-# ANN f (id + 1) #-}
-annfail08.hs:9:15: error:
+annfail08.hs:9:12: error:
• No instance for (Num (a0 -> a0)) arising from a use of ‘+’
(maybe you haven't applied a function to enough arguments?)
• In the annotation: {-# ANN f (id + 1) #-}
diff --git a/testsuite/tests/arrows/should_fail/T5380.stderr b/testsuite/tests/arrows/should_fail/T5380.stderr
index 2aeb01f1c0..0e258a2c28 100644
--- a/testsuite/tests/arrows/should_fail/T5380.stderr
+++ b/testsuite/tests/arrows/should_fail/T5380.stderr
@@ -8,6 +8,8 @@ T5380.hs:7:27: error:
at T5380.hs:6:10
• In the expression: b
In the expression: proc () -> if b then f -< () else f -< ()
+ In an equation for ‘testB’:
+ testB b f = proc () -> if b then f -< () else f -< ()
• Relevant bindings include
b :: not_bool (bound at T5380.hs:7:7)
testB :: not_bool -> (() -> ()) -> () -> not_unit
@@ -24,6 +26,7 @@ T5380.hs:7:34: error:
Actual type: () -> ()
• In the expression: f
In the command: f -< ()
+ In the expression: proc () -> if b then f -< () else f -< ()
• Relevant bindings include
testB :: not_bool -> (() -> ()) -> () -> not_unit
(bound at T5380.hs:7:1)
diff --git a/testsuite/tests/boxy/all.T b/testsuite/tests/boxy/all.T
index 0294d01629..d2be5e314b 100644
--- a/testsuite/tests/boxy/all.T
+++ b/testsuite/tests/boxy/all.T
@@ -1,6 +1,6 @@
# Boxy-type tests
-test('Base1', expect_broken(4295), compile, [''])
+test('Base1', normal, compile, [''])
test('Church1', expect_broken(4295), compile, [''])
test('Church2', expect_broken(1330), compile_fail, [''])
test('PList1', expect_broken(4295), compile, [''])
@@ -8,4 +8,4 @@ test('PList2', expect_broken(4295), compile, [''])
test('SystemF', expect_broken(4295), compile, [''])
test('boxy', expect_broken(4295), compile, [''])
test('Compose', normal, compile, [''])
-test('T2193', normal, compile_and_run, [''])
+test('T2193', expect_broken(4295), compile_and_run, [''])
diff --git a/testsuite/tests/deSugar/should_compile/T2431.stderr b/testsuite/tests/deSugar/should_compile/T2431.stderr
index 241a13c777..37bf170f28 100644
--- a/testsuite/tests/deSugar/should_compile/T2431.stderr
+++ b/testsuite/tests/deSugar/should_compile/T2431.stderr
@@ -37,7 +37,9 @@ a2 = GHC.Types.TrNameS "'Refl"#
-- RHS size: {terms: 5, types: 0, coercions: 0}
T2431.$tc'Refl :: GHC.Types.TyCon
[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType]
-T2431.$tc'Refl = GHC.Types.TyCon 0## 0## T2431.$trModule a2
+T2431.$tc'Refl =
+ GHC.Types.TyCon
+ 15026191172322750497## 3898273167927206410## T2431.$trModule a2
-- RHS size: {terms: 2, types: 0, coercions: 0}
a3 :: GHC.Types.TrName
@@ -47,7 +49,9 @@ a3 = GHC.Types.TrNameS ":~:"#
-- RHS size: {terms: 5, types: 0, coercions: 0}
T2431.$tc:~: :: GHC.Types.TyCon
[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType]
-T2431.$tc:~: = GHC.Types.TyCon 0## 0## T2431.$trModule a3
+T2431.$tc:~: =
+ GHC.Types.TyCon
+ 9759653149176674453## 12942818337407067047## T2431.$trModule a3
-- RHS size: {terms: 4, types: 8, coercions: 0}
absurd :: forall a. Int :~: Bool -> a
diff --git a/testsuite/tests/driver/T2182.stderr b/testsuite/tests/driver/T2182.stderr
index 0585e4c701..b5a5f1d349 100644
--- a/testsuite/tests/driver/T2182.stderr
+++ b/testsuite/tests/driver/T2182.stderr
@@ -5,7 +5,7 @@ T2182.hs:5:5: error:
In the expression: show (\ x -> x)
In an equation for ‘y’: y = show (\ x -> x)
-T2182.hs:6:15: error:
+T2182.hs:6:5: error:
No instance for (Eq (t0 -> t0)) arising from a use of ‘==’
(maybe you haven't applied a function to enough arguments?)
In the expression: (\ x -> x) == (\ y -> y)
@@ -17,7 +17,7 @@ T2182.hs:5:5: error:
In the expression: show (\ x -> x)
In an equation for ‘y’: y = show (\ x -> x)
-T2182.hs:6:15: error:
+T2182.hs:6:5: error:
No instance for (Eq (t0 -> t0)) arising from a use of ‘==’
(maybe you haven't applied a function to enough arguments?)
In the expression: (\ x -> x) == (\ y -> y)
diff --git a/testsuite/tests/driver/T4437.hs b/testsuite/tests/driver/T4437.hs
index b6d04ef6c1..4120e91d99 100644
--- a/testsuite/tests/driver/T4437.hs
+++ b/testsuite/tests/driver/T4437.hs
@@ -37,7 +37,8 @@ expectedGhcOnlyExtensions = ["RelaxedLayout",
"UndecidableSuperClasses",
"TemplateHaskellQuotes",
"MonadFailDesugaring",
- "TypeInType"]
+ "TypeInType",
+ "TypeApplications"]
expectedCabalOnlyExtensions :: [String]
expectedCabalOnlyExtensions = ["Generics",
diff --git a/testsuite/tests/driver/werror.stderr b/testsuite/tests/driver/werror.stderr
index ce6dba6347..a20dc5e689 100644
--- a/testsuite/tests/driver/werror.stderr
+++ b/testsuite/tests/driver/werror.stderr
@@ -1,30 +1,30 @@
-werror.hs:6:1: Warning:
+werror.hs:6:1: warning:
Top-level binding with no type signature: main :: IO ()
-werror.hs:7:13: Warning:
+werror.hs:7:13: warning:
This binding for ‘main’ shadows the existing binding
defined at werror.hs:6:1
-werror.hs:7:13: Warning: Defined but not used: ‘main’
+werror.hs:7:13: warning: Defined but not used: ‘main’
-werror.hs:8:1: Warning:
+werror.hs:8:1: warning:
Tab character found here.
Please use spaces instead.
-werror.hs:10:1: Warning: Defined but not used: ‘f’
+werror.hs:10:1: warning: Defined but not used: ‘f’
-werror.hs:10:1: Warning:
+werror.hs:10:1: warning:
Top-level binding with no type signature:
- f :: forall r r1. [r] -> [r1]
+ f :: forall t t1. [t] -> [t1]
-werror.hs:10:1: Warning:
+werror.hs:10:1: warning:
Pattern match(es) are redundant
In an equation for ‘f’: f [] = ...
-werror.hs:10:1: Warning:
+werror.hs:10:1: warning:
Pattern match(es) are non-exhaustive
In an equation for ‘f’: Patterns not matched: (_:_)
-<no location info>:
+<no location info>: error:
Failing due to -Werror.
diff --git a/testsuite/tests/gadt/T3169.stderr b/testsuite/tests/gadt/T3169.stderr
index 0ec531c526..4c9097eacd 100644
--- a/testsuite/tests/gadt/T3169.stderr
+++ b/testsuite/tests/gadt/T3169.stderr
@@ -9,6 +9,9 @@ T3169.hs:13:22: error:
Actual type: Map (a, b) elt
• In the second argument of ‘lookup’, namely ‘m’
In the expression: lookup a m :: Maybe (Map b elt)
+ In the expression:
+ case lookup a m :: Maybe (Map b elt) of {
+ Just (m2 :: Map b elt) -> lookup b m2 :: Maybe elt }
• Relevant bindings include
m :: Map (a, b) elt (bound at T3169.hs:12:17)
b :: b (bound at T3169.hs:12:13)
diff --git a/testsuite/tests/gadt/gadt-escape1.stderr b/testsuite/tests/gadt/gadt-escape1.stderr
index 829dfa0e2b..215426ed15 100644
--- a/testsuite/tests/gadt/gadt-escape1.stderr
+++ b/testsuite/tests/gadt/gadt-escape1.stderr
@@ -10,8 +10,10 @@ gadt-escape1.hs:19:58: error:
the inferred type of weird1 :: r at gadt-escape1.hs:19:1
Possible fix: add a type signature for ‘weird1’
Expected type: r
- Actual type: ExpGADT t
+ Actual type: ExpGADT t
• In the expression: a
In a case alternative: Hidden (ExpInt _) a -> a
+ In the expression:
+ case (hval :: Hidden) of { Hidden (ExpInt _) a -> a }
• Relevant bindings include
weird1 :: r (bound at gadt-escape1.hs:19:1)
diff --git a/testsuite/tests/gadt/gadt13.stderr b/testsuite/tests/gadt/gadt13.stderr
index 44b100b059..57ee3fdc92 100644
--- a/testsuite/tests/gadt/gadt13.stderr
+++ b/testsuite/tests/gadt/gadt13.stderr
@@ -3,14 +3,15 @@ gadt13.hs:15:13: error:
• Couldn't match expected type ‘r’
with actual type ‘String -> [Char]’
‘r’ is untouchable
- inside the constraints: r1 ~ Int
+ inside the constraints: t ~ Int
bound by a pattern with constructor: I :: Int -> Term Int,
in an equation for ‘shw’
at gadt13.hs:15:6-8
‘r’ is a rigid type variable bound by
- the inferred type of shw :: Term r1 -> r at gadt13.hs:15:1
+ the inferred type of shw :: Term t -> r at gadt13.hs:15:1
Possible fix: add a type signature for ‘shw’
- • In the expression: ("I " ++) . shows t
+ • Possible cause: ‘(.)’ is applied to too many arguments
+ In the expression: ("I " ++) . shows t
In an equation for ‘shw’: shw (I t) = ("I " ++) . shows t
• Relevant bindings include
- shw :: Term r1 -> r (bound at gadt13.hs:15:1)
+ shw :: Term t -> r (bound at gadt13.hs:15:1)
diff --git a/testsuite/tests/gadt/gadt7.stderr b/testsuite/tests/gadt/gadt7.stderr
index 8720d7fe10..93b8c70c1f 100644
--- a/testsuite/tests/gadt/gadt7.stderr
+++ b/testsuite/tests/gadt/gadt7.stderr
@@ -13,6 +13,7 @@ gadt7.hs:16:38: error:
Possible fix: add a type signature for ‘i1b’
• In the expression: y1
In a case alternative: K -> y1
+ In the expression: case t1 of { K -> y1 }
• Relevant bindings include
y1 :: r1 (bound at gadt7.hs:16:16)
y :: r1 (bound at gadt7.hs:16:7)
diff --git a/testsuite/tests/gadt/rw.stderr b/testsuite/tests/gadt/rw.stderr
index 39529a7003..c79bb72b4c 100644
--- a/testsuite/tests/gadt/rw.stderr
+++ b/testsuite/tests/gadt/rw.stderr
@@ -13,16 +13,17 @@ rw.hs:14:47: error:
v :: T a (bound at rw.hs:13:10)
writeInt :: T a -> IORef a -> IO () (bound at rw.hs:13:1)
-rw.hs:19:51: error:
+rw.hs:19:43: error:
• Couldn't match type ‘a’ with ‘Bool’
‘a’ is a rigid type variable bound by
the type signature for:
readBool :: forall a. T a -> IORef a -> IO ()
at rw.hs:16:12
- Expected type: a -> Bool
- Actual type: Bool -> Bool
- • In the second argument of ‘(.)’, namely ‘not’
- In the second argument of ‘(>>=)’, namely ‘(print . not)’
+ Expected type: a -> IO ()
+ Actual type: Bool -> IO ()
+ • In the second argument of ‘(>>=)’, namely ‘(print . not)’
+ In the expression: readIORef ref >>= (print . not)
+ In a case alternative: ~(Lb x) -> readIORef ref >>= (print . not)
• Relevant bindings include
ref :: IORef a (bound at rw.hs:17:12)
v :: T a (bound at rw.hs:17:10)
diff --git a/testsuite/tests/ghc-api/annotations/T10280.stderr b/testsuite/tests/ghc-api/annotations/T10280.stderr
index f2a2a56e63..e5ec0774da 100644
--- a/testsuite/tests/ghc-api/annotations/T10280.stderr
+++ b/testsuite/tests/ghc-api/annotations/T10280.stderr
@@ -1,8 +1,8 @@
-
-Test10280.hs:4:8: error:
- Variable not in scope:
- atomicModifyIORef :: t0 -> (a0 -> (b0, ())) -> t
-
-Test10280.hs:4:26: error: Variable not in scope: ciTokens
-
-Test10280.hs:4:44: error: Variable not in scope: f :: a0 -> b0
+
+Test10280.hs:4:8: error:
+ Variable not in scope:
+ atomicModifyIORef :: t0 -> (a0 -> (t1, ())) -> t
+
+Test10280.hs:4:26: error: Variable not in scope: ciTokens
+
+Test10280.hs:4:44: error: Variable not in scope: f :: a0 -> t1
diff --git a/testsuite/tests/ghc-api/annotations/T10357.stderr b/testsuite/tests/ghc-api/annotations/T10357.stderr
index 09f29ddfb8..971657668f 100644
--- a/testsuite/tests/ghc-api/annotations/T10357.stderr
+++ b/testsuite/tests/ghc-api/annotations/T10357.stderr
@@ -4,34 +4,34 @@ Test10357.hs:4:13: error: Variable not in scope: one
Test10357.hs:4:19: error: Variable not in scope: x
Test10357.hs:5:7: error:
- Variable not in scope: multPoly :: t0 -> t1 -> t
+ Variable not in scope: multPoly :: t0 -> t2 -> t
Test10357.hs:6:10: error:
- Variable not in scope: poly :: t2 -> [Double] -> t0
+ Variable not in scope: poly :: t1 -> [Double] -> t0
Test10357.hs:6:15: error:
- Data constructor not in scope: LE
- Perhaps you meant ‘LT’ (imported from Prelude)
+ • Data constructor not in scope: LE
+ • Perhaps you meant ‘LT’ (imported from Prelude)
Test10357.hs:7:10: error:
- Variable not in scope: addPoly :: t3 -> t4 -> t1
+ Variable not in scope: addPoly :: t3 -> t6 -> t2
Test10357.hs:7:19: error:
- Variable not in scope: poly :: t6 -> [Double] -> t5
+ Variable not in scope: poly :: t5 -> [Double] -> t4
Test10357.hs:7:24: error:
- Data constructor not in scope: LE
- Perhaps you meant ‘LT’ (imported from Prelude)
+ • Data constructor not in scope: LE
+ • Perhaps you meant ‘LT’ (imported from Prelude)
Test10357.hs:7:43: error:
- Variable not in scope: multPoly :: t5 -> t -> t3
+ Variable not in scope: multPoly :: t4 -> t -> t3
Test10357.hs:8:19: error:
Variable not in scope: poly :: t8 -> [Double] -> t7
Test10357.hs:8:24: error:
- Data constructor not in scope: LE
- Perhaps you meant ‘LT’ (imported from Prelude)
+ • Data constructor not in scope: LE
+ • Perhaps you meant ‘LT’ (imported from Prelude)
Test10357.hs:8:43: error:
- Variable not in scope: multPoly :: t7 -> t -> t4
+ Variable not in scope: multPoly :: t7 -> t -> t6
diff --git a/testsuite/tests/ghci.debugger/scripts/break003.stderr b/testsuite/tests/ghci.debugger/scripts/break003.stderr
index c19e8b45ce..66310e5355 100644
--- a/testsuite/tests/ghci.debugger/scripts/break003.stderr
+++ b/testsuite/tests/ghci.debugger/scripts/break003.stderr
@@ -1,5 +1,5 @@
<interactive>:4:1: error:
- No instance for (Show (t1 -> t)) arising from a use of ‘print’
- (maybe you haven't applied a function to enough arguments?)
- In a stmt of an interactive GHCi command: print it
+ • No instance for (Show (t -> a2)) arising from a use of ‘print’
+ (maybe you haven't applied a function to enough arguments?)
+ • In a stmt of an interactive GHCi command: print it
diff --git a/testsuite/tests/ghci.debugger/scripts/break003.stdout b/testsuite/tests/ghci.debugger/scripts/break003.stdout
index 1d0844c6cc..e1f4d351d1 100644
--- a/testsuite/tests/ghci.debugger/scripts/break003.stdout
+++ b/testsuite/tests/ghci.debugger/scripts/break003.stdout
@@ -1,6 +1,6 @@
Breakpoint 0 activated at ../Test3.hs:2:18-31
Stopped in Main.mymap, ../Test3.hs:2:18-31
-_result :: [t] = _
-f :: t1 -> t = _
-x :: t1 = _
-xs :: [t1] = [_]
+_result :: [a2] = _
+f :: t -> a2 = _
+x :: t = _
+xs :: [t] = [_]
diff --git a/testsuite/tests/ghci.debugger/scripts/break005.stdout b/testsuite/tests/ghci.debugger/scripts/break005.stdout
index 81eae63726..d6b287eb58 100644
--- a/testsuite/tests/ghci.debugger/scripts/break005.stdout
+++ b/testsuite/tests/ghci.debugger/scripts/break005.stdout
@@ -4,7 +4,7 @@ a :: Integer = 1
left :: [Integer] = _
right :: [Integer] = _
Stopped in QSort.qsort, ../QSort.hs:5:17-26
-_result :: [t] = _
-left :: [t] = _
+_result :: [a2] = _
+left :: [a2] = _
()
left = []
diff --git a/testsuite/tests/ghci.debugger/scripts/break006.stderr b/testsuite/tests/ghci.debugger/scripts/break006.stderr
index 3b57eb3a64..9098cc9c65 100644
--- a/testsuite/tests/ghci.debugger/scripts/break006.stderr
+++ b/testsuite/tests/ghci.debugger/scripts/break006.stderr
@@ -1,9 +1,9 @@
<interactive>:4:1: error:
- • No instance for (Show t) arising from a use of ‘print’
- Cannot resolve unknown runtime type ‘t’
+ • No instance for (Show a2) arising from a use of ‘print’
+ Cannot resolve unknown runtime type ‘a2’
Use :print or :force to determine these types
- Relevant bindings include it :: t (bound at <interactive>:4:1)
+ Relevant bindings include it :: a2 (bound at <interactive>:4:1)
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
@@ -15,10 +15,10 @@
• In a stmt of an interactive GHCi command: print it
<interactive>:6:1: error:
- • No instance for (Show t) arising from a use of ‘print’
- Cannot resolve unknown runtime type ‘t’
+ • No instance for (Show a2) arising from a use of ‘print’
+ Cannot resolve unknown runtime type ‘a2’
Use :print or :force to determine these types
- Relevant bindings include it :: t (bound at <interactive>:6:1)
+ Relevant bindings include it :: a2 (bound at <interactive>:6:1)
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
diff --git a/testsuite/tests/ghci.debugger/scripts/break006.stdout b/testsuite/tests/ghci.debugger/scripts/break006.stdout
index d8f1b65864..93326416e0 100644
--- a/testsuite/tests/ghci.debugger/scripts/break006.stdout
+++ b/testsuite/tests/ghci.debugger/scripts/break006.stdout
@@ -1,13 +1,13 @@
Stopped in Main.mymap, ../Test3.hs:2:18-31
-_result :: [t] = _
-f :: Integer -> t = _
+_result :: [a2] = _
+f :: Integer -> a2 = _
x :: Integer = 1
xs :: [Integer] = [2,3]
xs :: [Integer] = [2,3]
x :: Integer = 1
-f :: Integer -> t = _
-_result :: [t] = _
-y = (_t1::t)
+f :: Integer -> a2 = _
+_result :: [a2] = _
+y = (_t1::a2)
y = 2
xs :: [Integer] = [2,3]
x :: Integer = 1
diff --git a/testsuite/tests/ghci.debugger/scripts/hist001.stdout b/testsuite/tests/ghci.debugger/scripts/hist001.stdout
index 7ef5dc1e8e..c5b2787db5 100644
--- a/testsuite/tests/ghci.debugger/scripts/hist001.stdout
+++ b/testsuite/tests/ghci.debugger/scripts/hist001.stdout
@@ -9,25 +9,25 @@ _result :: [a] = _
-6 : mymap (../Test3.hs:2:18-31)
<end of history>
Logged breakpoint at ../Test3.hs:2:22-31
-_result :: [t]
-f :: t1 -> t
-xs :: [t1]
-xs :: [t1] = []
-f :: t1 -> t = _
-_result :: [t] = _
+_result :: [a2]
+f :: t -> a2
+xs :: [t]
+xs :: [t] = []
+f :: t -> a2 = _
+_result :: [a2] = _
Logged breakpoint at ../Test3.hs:2:18-20
-_result :: t
-f :: Integer -> t
+_result :: a2
+f :: Integer -> a2
x :: Integer
-xs :: [t1] = []
+xs :: [t] = []
x :: Integer = 2
-f :: Integer -> t = _
-_result :: t = _
+f :: Integer -> a2 = _
+_result :: a2 = _
_result = 3
Logged breakpoint at ../Test3.hs:2:18-31
-_result :: [t]
-f :: Integer -> t
+_result :: [a2]
+f :: Integer -> a2
x :: Integer
xs :: [Integer]
Logged breakpoint at ../Test3.hs:2:18-20
-_result :: t
+_result :: a2
diff --git a/testsuite/tests/ghci/scripts/Defer02.stderr b/testsuite/tests/ghci/scripts/Defer02.stderr
index ad39191d08..29feadd24b 100644
--- a/testsuite/tests/ghci/scripts/Defer02.stderr
+++ b/testsuite/tests/ghci/scripts/Defer02.stderr
@@ -12,7 +12,7 @@
• In the expression: 'p'
In an equation for ‘a’: a = 'p'
-../../typecheck/should_run/Defer01.hs:18:9: warning:
+../../typecheck/should_run/Defer01.hs:18:7: warning:
• No instance for (Eq B) arising from a use of ‘==’
• In the expression: x == x
In an equation for ‘b’: b x = x == x
@@ -52,6 +52,7 @@
at ../../typecheck/should_run/Defer01.hs:33:6
• In the expression: x
In the expression: (x, 'c')
+ In an equation for ‘h’: h x = (x, 'c')
• Relevant bindings include
x :: a (bound at ../../typecheck/should_run/Defer01.hs:34:3)
h :: a -> (Char, Char)
@@ -61,6 +62,7 @@
• Couldn't match expected type ‘Bool’ with actual type ‘T a’
• In the first argument of ‘not’, namely ‘(K a)’
In the expression: (not (K a))
+ In the expression: seq (not (K a)) ()
• Relevant bindings include
a :: a (bound at ../../typecheck/should_run/Defer01.hs:39:3)
i :: a -> () (bound at ../../typecheck/should_run/Defer01.hs:39:1)
@@ -110,6 +112,7 @@
• Probable cause: ‘putChar’ is applied to too few arguments
In the first argument of ‘(>>)’, namely ‘putChar’
In the expression: putChar >> putChar 'p'
+ In an equation for ‘l’: l = putChar >> putChar 'p'
*** Exception: ../../typecheck/should_run/Defer01.hs:11:40: error:
• Couldn't match type ‘Char’ with ‘[Char]’
Expected type: String
@@ -123,7 +126,7 @@
• In the expression: 'p'
In an equation for ‘a’: a = 'p'
(deferred type error)
-*** Exception: ../../typecheck/should_run/Defer01.hs:18:9: error:
+*** Exception: ../../typecheck/should_run/Defer01.hs:18:7: error:
• No instance for (Eq B) arising from a use of ‘==’
• In the expression: x == x
In an equation for ‘b’: b x = x == x
@@ -135,6 +138,7 @@
Actual type: C Bool
• In the first argument of ‘c’, namely ‘(C2 True)’
In the first argument of ‘print’, namely ‘(c (C2 True))’
+ In the expression: print (c (C2 True))
*** Exception: ../../typecheck/should_run/Defer01.hs:28:5: error:
• No instance for (Num (a -> a)) arising from the literal ‘1’
(maybe you haven't applied a function to enough arguments?)
@@ -158,6 +162,7 @@
at ../../typecheck/should_run/Defer01.hs:33:6
• In the expression: x
In the expression: (x, 'c')
+ In an equation for ‘h’: h x = (x, 'c')
• Relevant bindings include
x :: a (bound at ../../typecheck/should_run/Defer01.hs:34:3)
h :: a -> (Char, Char)
@@ -167,6 +172,7 @@
• Couldn't match expected type ‘Bool’ with actual type ‘T a’
• In the first argument of ‘not’, namely ‘(K a)’
In the expression: (not (K a))
+ In the expression: seq (not (K a)) ()
• Relevant bindings include
a :: a (bound at ../../typecheck/should_run/Defer01.hs:39:3)
i :: a -> () (bound at ../../typecheck/should_run/Defer01.hs:39:1)
@@ -188,4 +194,5 @@
• Probable cause: ‘putChar’ is applied to too few arguments
In the first argument of ‘(>>)’, namely ‘putChar’
In the expression: putChar >> putChar 'p'
+ In an equation for ‘l’: l = putChar >> putChar 'p'
(deferred type error)
diff --git a/testsuite/tests/ghci/scripts/T10122.stdout b/testsuite/tests/ghci/scripts/T10122.stdout
index 84d8856c1b..8d6f0182dc 100644
--- a/testsuite/tests/ghci/scripts/T10122.stdout
+++ b/testsuite/tests/ghci/scripts/T10122.stdout
@@ -1,2 +1,2 @@
T :: (k -> *) -> k -> *
-T :: forall k. (k -> *) -> k -> *
+T :: forall {k}. (k -> *) -> k -> *
diff --git a/testsuite/tests/ghci/scripts/T10508.stderr b/testsuite/tests/ghci/scripts/T10508.stderr
index 86ee279393..86cdc82e92 100644
--- a/testsuite/tests/ghci/scripts/T10508.stderr
+++ b/testsuite/tests/ghci/scripts/T10508.stderr
@@ -1,8 +1,12 @@
-<interactive>:1:15: error:
- Couldn't match type ‘a0 -> a0’ with ‘[Char]’
- Expected type: Prelude.String
- Actual type: a0 -> a0
- Probable cause: ‘id’ is applied to too few arguments
- In the first argument of ‘return’, namely ‘id’
- In the expression: return id
+<interactive>:1:8: error:
+ • Couldn't match type ‘a0 -> a0’ with ‘[Char]’
+ Expected type: IO Prelude.String
+ Actual type: IO (a0 -> a0)
+ • In the expression: return id
+ In the second argument of ‘(.)’, namely ‘\ _ -> return id’
+ In the expression:
+ (.)
+ (GHC.GHCi.ghciStepIO :: IO Prelude.String -> IO Prelude.String)
+ (\ _ -> return id) ::
+ Prelude.String -> IO Prelude.String
diff --git a/testsuite/tests/ghci/scripts/T7627.stdout b/testsuite/tests/ghci/scripts/T7627.stdout
index 81a360facb..4b16acc1a2 100644
--- a/testsuite/tests/ghci/scripts/T7627.stdout
+++ b/testsuite/tests/ghci/scripts/T7627.stdout
@@ -28,6 +28,12 @@ instance (Monoid a, Monoid b) => Monoid (a, b)
data (#,#) (c :: TYPE a) (d :: TYPE b) = (#,#) c d
-- Defined in ‘GHC.Prim’
(,) :: a -> b -> (a, b)
-(#,#) :: c -> d -> (# c, d #)
+(#,#)
+ :: forall (a :: GHC.Types.Levity) (b :: GHC.Types.Levity) (c :: TYPE
+ a) (d :: TYPE b).
+ c -> d -> (# c, d #)
( , ) :: a -> b -> (a, b)
-(# , #) :: c -> d -> (# c, d #)
+(# , #)
+ :: forall (a :: GHC.Types.Levity) (b :: GHC.Types.Levity) (c :: TYPE
+ a) (d :: TYPE b).
+ c -> d -> (# c, d #)
diff --git a/testsuite/tests/ghci/scripts/T8649.stderr b/testsuite/tests/ghci/scripts/T8649.stderr
index ae766e5aec..aa40d50c2e 100644
--- a/testsuite/tests/ghci/scripts/T8649.stderr
+++ b/testsuite/tests/ghci/scripts/T8649.stderr
@@ -6,3 +6,4 @@
‘Ghci1.X’ is defined at <interactive>:1:1-14
In the first argument of ‘f’, namely ‘(Y 3)’
In the expression: f (Y 3)
+ In an equation for ‘it’: it = f (Y 3)
diff --git a/testsuite/tests/ghci/scripts/T8959b.stderr b/testsuite/tests/ghci/scripts/T8959b.stderr
index 6a20f07421..d968f8ac56 100644
--- a/testsuite/tests/ghci/scripts/T8959b.stderr
+++ b/testsuite/tests/ghci/scripts/T8959b.stderr
@@ -1,16 +1,16 @@
-T8959b.hs:5:7:
- Couldn't match expected type ‘Int → Int’ with actual type ‘()’
- In the expression: ()
- In an equation for ‘foo’: foo = ()
+T8959b.hs:5:7: error:
+ • Couldn't match expected type ‘Int → Int’ with actual type ‘()’
+ • In the expression: ()
+ In an equation for ‘foo’: foo = ()
-T8959b.hs:8:7:
- Couldn't match expected type ‘()’ with actual type ‘t0 → m0 t0’
- In the expression: proc x -> do { return ⤙ x }
- In an equation for ‘bar’: bar = proc x -> do { return ⤙ x }
+T8959b.hs:8:7: error:
+ • Couldn't match expected type ‘()’ with actual type ‘t0 → m0 t0’
+ • In the expression: proc x -> do { return ⤙ x }
+ In an equation for ‘bar’: bar = proc x -> do { return ⤙ x }
-T8959b.hs:10:7:
- Couldn't match expected type ‘(∀ a2. a2 → a2) → a1’
- with actual type ‘()’
- In the expression: () ∷ (∀ a. a -> a) -> a
- In an equation for ‘baz’: baz = () ∷ (∀ a. a -> a) -> a
+T8959b.hs:10:7: error:
+ • Couldn't match expected type ‘(∀ a2. a2 → a2) → a1’
+ with actual type ‘()’
+ • In the expression: () ∷ (∀ a. a -> a) -> a
+ In an equation for ‘baz’: baz = () ∷ (∀ a. a -> a) -> a
diff --git a/testsuite/tests/ghci/scripts/ghci013.stdout b/testsuite/tests/ghci/scripts/ghci013.stdout
index b7065c5169..d70c57fd67 100644
--- a/testsuite/tests/ghci/scripts/ghci013.stdout
+++ b/testsuite/tests/ghci/scripts/ghci013.stdout
@@ -1,2 +1,2 @@
f :: (?callStack::GHC.Stack.Types.CallStack, Monad m) =>
- (m a, r) -> m b
+ (m a, t) -> m b
diff --git a/testsuite/tests/ghci/scripts/ghci025.stdout b/testsuite/tests/ghci/scripts/ghci025.stdout
index 80c4d4b7a5..7cea3e97ef 100644
--- a/testsuite/tests/ghci/scripts/ghci025.stdout
+++ b/testsuite/tests/ghci/scripts/ghci025.stdout
@@ -96,24 +96,24 @@ c4 :: forall a b. C a b => forall a1. a1 -> b
-- test :browse! <target> relative to different contexts
:browse! Ghci025C -- from *Ghci025C>
-- defined locally
-g :: forall a. Num a => a -> a
-h :: forall a. Integral a => a -> a
+g :: forall {a}. Num a => a -> a
+h :: forall {a}. Integral a => a -> a
-- imported via Ghci025D
-f :: forall a. Num a => a -> a
+f :: forall {a}. Num a => a -> a
:browse! Ghci025C -- from *Ghci025B>, after :add Ghci025B
-- imported via Ghci025C
-g :: forall a. Num a => a -> a
-h :: forall a. Integral a => a -> a
-f :: forall a. Num a => a -> a
+g :: forall {a}. Num a => a -> a
+h :: forall {a}. Integral a => a -> a
+f :: forall {a}. Num a => a -> a
:browse! Ghci025C -- from *Ghci025C>, after :m *Ghci025C
-- defined locally
-g :: forall a. Num a => a -> a
-h :: forall a. Integral a => a -> a
+g :: forall {a}. Num a => a -> a
+h :: forall {a}. Integral a => a -> a
-- imported via Ghci025D
-f :: forall a. Num a => a -> a
+f :: forall {a}. Num a => a -> a
:browse! Ghci025C -- from *Ghci025D>, after :m *Ghci025D
-- not currently imported
-Ghci025C.g :: forall a. Num a => a -> a
-Ghci025C.h :: forall a. Integral a => a -> a
+Ghci025C.g :: forall {a}. Num a => a -> a
+Ghci025C.h :: forall {a}. Integral a => a -> a
-- defined locally
-f :: forall a. Num a => a -> a
+f :: forall {a}. Num a => a -> a
diff --git a/testsuite/tests/ghci/scripts/ghci047.stderr b/testsuite/tests/ghci/scripts/ghci047.stderr
index 7e696c02c4..badfc1ebb1 100644
--- a/testsuite/tests/ghci/scripts/ghci047.stderr
+++ b/testsuite/tests/ghci/scripts/ghci047.stderr
@@ -2,13 +2,11 @@
<interactive>:38:1: error:
• Couldn't match type ‘HFalse’ with ‘HTrue’
arising from a use of ‘f’
- • In the expression: f
- In the expression: f $ Baz 'a'
+ • In the expression: f $ Baz 'a'
In an equation for ‘it’: it = f $ Baz 'a'
<interactive>:39:1: error:
• Couldn't match type ‘HFalse’ with ‘HTrue’
arising from a use of ‘f’
- • In the expression: f
- In the expression: f $ Quz
+ • In the expression: f $ Quz
In an equation for ‘it’: it = f $ Quz
diff --git a/testsuite/tests/ghci/scripts/ghci050.stderr b/testsuite/tests/ghci/scripts/ghci050.stderr
index e8cc7971db..588d130172 100644
--- a/testsuite/tests/ghci/scripts/ghci050.stderr
+++ b/testsuite/tests/ghci/scripts/ghci050.stderr
@@ -1,14 +1,14 @@
<interactive>:5:49: error:
- Couldn't match expected type ‘ListableElem (a, a)’
- with actual type ‘a’
- ‘a’ is a rigid type variable bound by
+ • Couldn't match expected type ‘ListableElem (a, a)’
+ with actual type ‘a’
+ ‘a’ is a rigid type variable bound by
the instance declaration at <interactive>:5:10
- In the expression: a
- In the expression: [a, b]
- Relevant bindings include
- b :: a (bound at <interactive>:5:43)
- a :: a (bound at <interactive>:5:41)
- asList :: (a, a) -> [ListableElem (a, a)]
- (bound at <interactive>:5:33)
-
+ • In the expression: a
+ In the expression: [a, b]
+ In an equation for ‘asList’: asList (a, b) = [a, b]
+ • Relevant bindings include
+ b :: a (bound at <interactive>:5:43)
+ a :: a (bound at <interactive>:5:41)
+ asList :: (a, a) -> [ListableElem (a, a)]
+ (bound at <interactive>:5:33)
diff --git a/testsuite/tests/ghci/scripts/ghci052.stderr b/testsuite/tests/ghci/scripts/ghci052.stderr
index 4464891168..224726f822 100644
--- a/testsuite/tests/ghci/scripts/ghci052.stderr
+++ b/testsuite/tests/ghci/scripts/ghci052.stderr
@@ -6,6 +6,7 @@
‘Ghci1.Planet’ is defined at <interactive>:4:1-37
In the first argument of ‘pn’, namely ‘Mercury’
In the expression: pn Mercury
+ In an equation for ‘it’: it = pn Mercury
<interactive>:9:4: error:
Couldn't match expected type ‘Ghci1.Planet’
@@ -14,6 +15,7 @@
‘Ghci1.Planet’ is defined at <interactive>:4:1-37
In the first argument of ‘pn’, namely ‘Venus’
In the expression: pn Venus
+ In an equation for ‘it’: it = pn Venus
<interactive>:10:4: error:
Couldn't match expected type ‘Ghci1.Planet’
@@ -22,6 +24,7 @@
‘Ghci1.Planet’ is defined at <interactive>:4:1-37
In the first argument of ‘pn’, namely ‘Mars’
In the expression: pn Mars
+ In an equation for ‘it’: it = pn Mars
<interactive>:12:44: error:
Couldn't match expected type ‘Planet’
diff --git a/testsuite/tests/ghci/scripts/ghci053.stderr b/testsuite/tests/ghci/scripts/ghci053.stderr
index bb038faf23..76d5ae2548 100644
--- a/testsuite/tests/ghci/scripts/ghci053.stderr
+++ b/testsuite/tests/ghci/scripts/ghci053.stderr
@@ -6,6 +6,7 @@
‘Ghci1.Planet’ is defined at <interactive>:4:1-49
In the second argument of ‘(==)’, namely ‘Mercury’
In the expression: mercury == Mercury
+ In an equation for ‘it’: it = mercury == Mercury
<interactive>:11:10: error:
Couldn't match expected type ‘Planet’
@@ -14,3 +15,4 @@
‘Planet’ is defined at <interactive>:7:1-41
In the second argument of ‘(==)’, namely ‘Earth’
In the expression: Venus == Earth
+ In an equation for ‘it’: it = Venus == Earth
diff --git a/testsuite/tests/ghci/scripts/ghci055.stdout b/testsuite/tests/ghci/scripts/ghci055.stdout
index c7450d0def..e878582a2b 100644
--- a/testsuite/tests/ghci/scripts/ghci055.stdout
+++ b/testsuite/tests/ghci/scripts/ghci055.stdout
@@ -1,3 +1,3 @@
x = _
-x :: ?callStack::GHC.Stack.Types.CallStack => r = _
+x :: ?callStack::GHC.Stack.Types.CallStack => a = _
y :: Integer = 3
diff --git a/testsuite/tests/indexed-types/should_compile/PushedInAsGivens.stderr b/testsuite/tests/indexed-types/should_compile/PushedInAsGivens.stderr
index ce3f4f9048..37b1135c48 100644
--- a/testsuite/tests/indexed-types/should_compile/PushedInAsGivens.stderr
+++ b/testsuite/tests/indexed-types/should_compile/PushedInAsGivens.stderr
@@ -8,6 +8,7 @@ PushedInAsGivens.hs:10:31: error:
at PushedInAsGivens.hs:9:13-44
• In the expression: y
In the first argument of ‘length’, namely ‘[x, y]’
+ In the expression: length [x, y]
• Relevant bindings include
x :: a1 (bound at PushedInAsGivens.hs:10:17)
foo :: a1 -> Int (bound at PushedInAsGivens.hs:10:13)
diff --git a/testsuite/tests/indexed-types/should_fail/GADTwrong1.stderr b/testsuite/tests/indexed-types/should_fail/GADTwrong1.stderr
index 7f806db271..5a0892ed31 100644
--- a/testsuite/tests/indexed-types/should_fail/GADTwrong1.stderr
+++ b/testsuite/tests/indexed-types/should_fail/GADTwrong1.stderr
@@ -11,6 +11,7 @@ GADTwrong1.hs:12:21: error:
at GADTwrong1.hs:10:20
• In the expression: y
In a case alternative: T y -> y
+ In the expression: case T x :: T (Const b) of { T y -> y }
• Relevant bindings include
y :: c (bound at GADTwrong1.hs:12:16)
coerce :: a -> b (bound at GADTwrong1.hs:11:1)
diff --git a/testsuite/tests/indexed-types/should_fail/T2544.stderr b/testsuite/tests/indexed-types/should_fail/T2544.stderr
index e60cdab2a5..a296a36910 100644
--- a/testsuite/tests/indexed-types/should_fail/T2544.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T2544.stderr
@@ -1,22 +1,24 @@
T2544.hs:17:18: error:
- Couldn't match type ‘IxMap i0’ with ‘IxMap l’
- NB: ‘IxMap’ is a type function, and may not be injective
- The type variable ‘i0’ is ambiguous
- Expected type: IxMap l [Int]
- Actual type: IxMap i0 [Int]
- In the first argument of ‘BiApp’, namely ‘empty’
- In the expression: BiApp empty empty
- Relevant bindings include
- empty :: IxMap (l :|: r) [Int] (bound at T2544.hs:17:4)
+ • Couldn't match type ‘IxMap i0’ with ‘IxMap l’
+ NB: ‘IxMap’ is a type function, and may not be injective
+ The type variable ‘i0’ is ambiguous
+ Expected type: IxMap l [Int]
+ Actual type: IxMap i0 [Int]
+ • In the first argument of ‘BiApp’, namely ‘empty’
+ In the expression: BiApp empty empty
+ In an equation for ‘empty’: empty = BiApp empty empty
+ • Relevant bindings include
+ empty :: IxMap (l :|: r) [Int] (bound at T2544.hs:17:4)
T2544.hs:17:24: error:
- Couldn't match type ‘IxMap i1’ with ‘IxMap r’
- NB: ‘IxMap’ is a type function, and may not be injective
- The type variable ‘i1’ is ambiguous
- Expected type: IxMap r [Int]
- Actual type: IxMap i1 [Int]
- In the second argument of ‘BiApp’, namely ‘empty’
- In the expression: BiApp empty empty
- Relevant bindings include
- empty :: IxMap (l :|: r) [Int] (bound at T2544.hs:17:4)
+ • Couldn't match type ‘IxMap i1’ with ‘IxMap r’
+ NB: ‘IxMap’ is a type function, and may not be injective
+ The type variable ‘i1’ is ambiguous
+ Expected type: IxMap r [Int]
+ Actual type: IxMap i1 [Int]
+ • In the second argument of ‘BiApp’, namely ‘empty’
+ In the expression: BiApp empty empty
+ In an equation for ‘empty’: empty = BiApp empty empty
+ • Relevant bindings include
+ empty :: IxMap (l :|: r) [Int] (bound at T2544.hs:17:4)
diff --git a/testsuite/tests/indexed-types/should_fail/T2693.stderr b/testsuite/tests/indexed-types/should_fail/T2693.stderr
index d3546c21ba..1d5ebefb9d 100644
--- a/testsuite/tests/indexed-types/should_fail/T2693.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T2693.stderr
@@ -4,6 +4,7 @@ T2693.hs:12:15: error:
The type variables ‘b1’, ‘a6’, ‘a8’ are ambiguous
• In the first argument of ‘fst’, namely ‘x’
In the first argument of ‘(+)’, namely ‘fst x’
+ In the expression: fst x + fst x
• Relevant bindings include n :: a8 (bound at T2693.hs:12:7)
T2693.hs:12:23: error:
@@ -11,6 +12,7 @@ T2693.hs:12:23: error:
The type variables ‘b2’, ‘a7’, ‘a8’ are ambiguous
• In the first argument of ‘fst’, namely ‘x’
In the second argument of ‘(+)’, namely ‘fst x’
+ In the expression: fst x + fst x
• Relevant bindings include n :: a8 (bound at T2693.hs:12:7)
T2693.hs:19:15: error:
@@ -18,6 +20,7 @@ T2693.hs:19:15: error:
The type variables ‘b0’, ‘a2’, ‘a5’ are ambiguous
• In the first argument of ‘fst’, namely ‘x’
In the first argument of ‘(+)’, namely ‘fst x’
+ In the expression: fst x + snd x
• Relevant bindings include n :: a5 (bound at T2693.hs:19:7)
T2693.hs:19:23: error:
@@ -25,6 +28,7 @@ T2693.hs:19:23: error:
The type variables ‘a3’, ‘a4’, ‘a5’ are ambiguous
• In the first argument of ‘snd’, namely ‘x’
In the second argument of ‘(+)’, namely ‘snd x’
+ In the expression: fst x + snd x
• Relevant bindings include n :: a5 (bound at T2693.hs:19:7)
T2693.hs:29:20: error:
@@ -34,3 +38,7 @@ T2693.hs:29:20: error:
Actual type: () -> Maybe (TFn a0)
• In the first argument of ‘mapM’, namely ‘g’
In a stmt of a 'do' block: pvs <- mapM g undefined
+ In the expression:
+ do { pvs <- mapM g undefined;
+ let n = (map pvrX pvs) `min` (map pvrX pvs);
+ undefined }
diff --git a/testsuite/tests/indexed-types/should_fail/T3330a.stderr b/testsuite/tests/indexed-types/should_fail/T3330a.stderr
index f6a5deeeb7..c90ea43c9c 100644
--- a/testsuite/tests/indexed-types/should_fail/T3330a.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T3330a.stderr
@@ -11,6 +11,7 @@ T3330a.hs:19:34: error:
Actual type: s ix
• In the first argument of ‘hmapM’, namely ‘p’
In the first argument of ‘execWriter’, namely ‘(hmapM p collect x)’
+ In the expression: execWriter (hmapM p collect x)
• Relevant bindings include
x :: PF s r ix (bound at T3330a.hs:19:12)
p :: s ix (bound at T3330a.hs:19:10)
@@ -28,6 +29,7 @@ T3330a.hs:19:44: error:
Actual type: PF s r ix
• In the third argument of ‘hmapM’, namely ‘x’
In the first argument of ‘execWriter’, namely ‘(hmapM p collect x)’
+ In the expression: execWriter (hmapM p collect x)
• Relevant bindings include
x :: PF s r ix (bound at T3330a.hs:19:12)
p :: s ix (bound at T3330a.hs:19:10)
diff --git a/testsuite/tests/indexed-types/should_fail/T3330c.stderr b/testsuite/tests/indexed-types/should_fail/T3330c.stderr
index 4d9e6d5be6..8526c17f5e 100644
--- a/testsuite/tests/indexed-types/should_fail/T3330c.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T3330c.stderr
@@ -5,9 +5,10 @@ T3330c.hs:23:43: error:
f1 :: * -> *
Der f1 x :: *
Expected type: Der ((->) x) (Der f1 x)
- Actual type: R f1
+ Actual type: R f1
• In the first argument of ‘plug’, namely ‘rf’
In the first argument of ‘Inl’, namely ‘(plug rf df x)’
+ In the expression: Inl (plug rf df x)
• Relevant bindings include
x :: x (bound at T3330c.hs:23:29)
df :: Der f1 x (bound at T3330c.hs:23:25)
diff --git a/testsuite/tests/indexed-types/should_fail/T3440.stderr b/testsuite/tests/indexed-types/should_fail/T3440.stderr
index 7b29bb6f52..8289d144c2 100644
--- a/testsuite/tests/indexed-types/should_fail/T3440.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T3440.stderr
@@ -17,6 +17,7 @@ T3440.hs:11:22: error:
at T3440.hs:10:11
• In the expression: x
In the expression: (x, y)
+ In an equation for ‘unwrap’: unwrap (GADT x y) = (x, y)
• Relevant bindings include
y :: Fam a1 (bound at T3440.hs:11:16)
x :: a1 (bound at T3440.hs:11:14)
diff --git a/testsuite/tests/indexed-types/should_fail/T4099.stderr b/testsuite/tests/indexed-types/should_fail/T4099.stderr
index c5b4245c17..a0ddc964ff 100644
--- a/testsuite/tests/indexed-types/should_fail/T4099.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T4099.stderr
@@ -1,21 +1,23 @@
-T4099.hs:11:30:
- Couldn't match expected type ‘T a0’ with actual type ‘T b’
- NB: ‘T’ is a type function, and may not be injective
- The type variable ‘a0’ is ambiguous
- In the second argument of ‘foo’, namely ‘x’
- In the expression: foo (error "urk") x
- Relevant bindings include
- x :: T b (bound at T4099.hs:11:8)
- a :: b (bound at T4099.hs:11:6)
- bar1 :: b -> T b -> Int (bound at T4099.hs:11:1)
+T4099.hs:11:30: error:
+ • Couldn't match expected type ‘T a0’ with actual type ‘T b’
+ NB: ‘T’ is a type function, and may not be injective
+ The type variable ‘a0’ is ambiguous
+ • In the second argument of ‘foo’, namely ‘x’
+ In the expression: foo (error "urk") x
+ In an equation for ‘bar1’: bar1 a x = foo (error "urk") x
+ • Relevant bindings include
+ x :: T b (bound at T4099.hs:11:8)
+ a :: b (bound at T4099.hs:11:6)
+ bar1 :: b -> T b -> Int (bound at T4099.hs:11:1)
-T4099.hs:14:30:
- Couldn't match expected type ‘T a1’ with actual type ‘Maybe b’
- The type variable ‘a1’ is ambiguous
- In the second argument of ‘foo’, namely ‘x’
- In the expression: foo (error "urk") x
- Relevant bindings include
- x :: Maybe b (bound at T4099.hs:14:8)
- a :: b (bound at T4099.hs:14:6)
- bar2 :: b -> Maybe b -> Int (bound at T4099.hs:14:1)
+T4099.hs:14:30: error:
+ • Couldn't match expected type ‘T a1’ with actual type ‘Maybe b’
+ The type variable ‘a1’ is ambiguous
+ • In the second argument of ‘foo’, namely ‘x’
+ In the expression: foo (error "urk") x
+ In an equation for ‘bar2’: bar2 a x = foo (error "urk") x
+ • Relevant bindings include
+ x :: Maybe b (bound at T4099.hs:14:8)
+ a :: b (bound at T4099.hs:14:6)
+ bar2 :: b -> Maybe b -> Int (bound at T4099.hs:14:1)
diff --git a/testsuite/tests/indexed-types/should_fail/T4179.stderr b/testsuite/tests/indexed-types/should_fail/T4179.stderr
index 4173eff8da..1a2a18bebf 100644
--- a/testsuite/tests/indexed-types/should_fail/T4179.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T4179.stderr
@@ -1,15 +1,16 @@
T4179.hs:26:16: error:
- • Couldn't match type ‘A3 (x (A2 (FCon x) -> A3 (FCon x)))’
- with ‘A3 (FCon x)’
- NB: ‘A3’ is a type function, and may not be injective
+ • Couldn't match type ‘A2 (x (A2 (FCon x) -> A3 (FCon x)))’
+ with ‘A2 (FCon x)’
+ NB: ‘A2’ is a type function, and may not be injective
Expected type: x (A2 (FCon x) -> A3 (FCon x))
-> A2 (FCon x) -> A3 (FCon x)
- Actual type: x (A2 (FCon x) -> A3 (FCon x))
- -> A2 (x (A2 (FCon x) -> A3 (FCon x)))
- -> A3 (x (A2 (FCon x) -> A3 (FCon x)))
+ Actual type: x (A2 (FCon x) -> A3 (FCon x))
+ -> A2 (x (A2 (FCon x) -> A3 (FCon x)))
+ -> A3 (x (A2 (FCon x) -> A3 (FCon x)))
• In the first argument of ‘foldDoC’, namely ‘op’
In the expression: foldDoC op
+ In an equation for ‘fCon’: fCon = foldDoC op
• Relevant bindings include
fCon :: Con x -> A2 (FCon x) -> A3 (FCon x)
(bound at T4179.hs:26:1)
diff --git a/testsuite/tests/indexed-types/should_fail/T4485.stderr b/testsuite/tests/indexed-types/should_fail/T4485.stderr
index 92d8efc3cd..4cf3b153fd 100644
--- a/testsuite/tests/indexed-types/should_fail/T4485.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T4485.stderr
@@ -1,30 +1,31 @@
T4485.hs:50:15: error:
- Overlapping instances for EmbedAsChild
- (IdentityT IO) (XMLGenT m0 (XML m0))
- arising from a use of ‘asChild’
- Matching instances:
- instance [overlapping] (EmbedAsChild m c, m1 ~ m) =>
- EmbedAsChild m (XMLGenT m1 c)
- -- Defined at T4485.hs:28:30
- instance [overlapping] EmbedAsChild
- (IdentityT IO) (XMLGenT Identity ())
- -- Defined at T4485.hs:45:30
- (The choice depends on the instantiation of ‘m0’
- To pick the first instance above, use IncoherentInstances
- when compiling the other instance declarations)
- In the expression: asChild
- In the expression: asChild $ (genElement "foo")
- In an equation for ‘asChild’:
- asChild b = asChild $ (genElement "foo")
+ • Overlapping instances for EmbedAsChild
+ (IdentityT IO) (XMLGenT m0 (XML m0))
+ arising from a use of ‘asChild’
+ Matching instances:
+ instance [overlapping] (EmbedAsChild m c, m1 ~ m) =>
+ EmbedAsChild m (XMLGenT m1 c)
+ -- Defined at T4485.hs:28:30
+ instance [overlapping] EmbedAsChild
+ (IdentityT IO) (XMLGenT Identity ())
+ -- Defined at T4485.hs:45:30
+ (The choice depends on the instantiation of ‘m0’
+ To pick the first instance above, use IncoherentInstances
+ when compiling the other instance declarations)
+ • In the expression: asChild $ (genElement "foo")
+ In an equation for ‘asChild’:
+ asChild b = asChild $ (genElement "foo")
+ In the instance declaration for
+ ‘EmbedAsChild (IdentityT IO) FooBar’
T4485.hs:50:26: error:
- Ambiguous type variable ‘m0’ arising from a use of ‘genElement’
- prevents the constraint ‘(XMLGen m0)’ from being solved.
- Probable fix: use a type annotation to specify what ‘m0’ should be.
- These potential instance exist:
- instance XMLGen (IdentityT m) -- Defined at T4485.hs:37:10
- In the second argument of ‘($)’, namely ‘(genElement "foo")’
- In the expression: asChild $ (genElement "foo")
- In an equation for ‘asChild’:
- asChild b = asChild $ (genElement "foo")
+ • Ambiguous type variable ‘m0’ arising from a use of ‘genElement’
+ prevents the constraint ‘(XMLGen m0)’ from being solved.
+ Probable fix: use a type annotation to specify what ‘m0’ should be.
+ These potential instance exist:
+ instance XMLGen (IdentityT m) -- Defined at T4485.hs:37:10
+ • In the second argument of ‘($)’, namely ‘(genElement "foo")’
+ In the expression: asChild $ (genElement "foo")
+ In an equation for ‘asChild’:
+ asChild b = asChild $ (genElement "foo")
diff --git a/testsuite/tests/indexed-types/should_fail/T5439.stderr b/testsuite/tests/indexed-types/should_fail/T5439.stderr
index 193b1536ec..f1ae705f5e 100644
--- a/testsuite/tests/indexed-types/should_fail/T5439.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T5439.stderr
@@ -6,6 +6,8 @@ T5439.hs:82:28: error:
Actual type: f (Attempt (WaitOpResult (WaitOps rs)))
• In the first argument of ‘complete’, namely ‘ev’
In the expression: complete ev
+ In a stmt of a 'do' block:
+ c <- complete ev $ inj $ Failure (e :: SomeException)
• Relevant bindings include
register :: Bool -> Peano n -> WaitOps (HDrop n rs) -> IO Bool
(bound at T5439.hs:64:9)
@@ -23,3 +25,5 @@ T5439.hs:82:39: error:
‘Failure (e :: SomeException)’
In the second argument of ‘($)’, namely
‘inj $ Failure (e :: SomeException)’
+ In a stmt of a 'do' block:
+ c <- complete ev $ inj $ Failure (e :: SomeException)
diff --git a/testsuite/tests/indexed-types/should_fail/T7010.stderr b/testsuite/tests/indexed-types/should_fail/T7010.stderr
index 9441b3857e..0da40f7a69 100644
--- a/testsuite/tests/indexed-types/should_fail/T7010.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T7010.stderr
@@ -1,7 +1,8 @@
-T7010.hs:53:27:
- Couldn't match type ‘IO Float’ with ‘Serial (IO Float)’
- Expected type: (Float, ValueTuple Vector)
- Actual type: (Float, ValueTuple Float)
- In the first argument of ‘withArgs’, namely ‘plug’
- In the expression: withArgs plug
+T7010.hs:53:27: error:
+ • Couldn't match type ‘IO Float’ with ‘Serial (IO Float)’
+ Expected type: (Float, ValueTuple Vector)
+ Actual type: (Float, ValueTuple Float)
+ • In the first argument of ‘withArgs’, namely ‘plug’
+ In the expression: withArgs plug
+ In an equation for ‘filterFormants’: filterFormants = withArgs plug
diff --git a/testsuite/tests/indexed-types/should_fail/T7194.stderr b/testsuite/tests/indexed-types/should_fail/T7194.stderr
index d8655f0146..c48a3de15d 100644
--- a/testsuite/tests/indexed-types/should_fail/T7194.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T7194.stderr
@@ -8,6 +8,7 @@ T7194.hs:18:35: error:
at T7194.hs:17:18-41
• In the expression: foo y
In the first argument of ‘length’, namely ‘[x, foo y]’
+ In the expression: length [x, foo y]
• Relevant bindings include
y :: a (bound at T7194.hs:18:20)
g :: a -> Int (bound at T7194.hs:18:18)
diff --git a/testsuite/tests/indexed-types/should_fail/T7354.stderr b/testsuite/tests/indexed-types/should_fail/T7354.stderr
index f115604b10..b56db1398f 100644
--- a/testsuite/tests/indexed-types/should_fail/T7354.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T7354.stderr
@@ -1,10 +1,11 @@
-T7354.hs:28:11:
- Occurs check: cannot construct the infinite type:
- a ~ Base t (Prim [a] a)
- Expected type: Prim [a] a -> Base t (Prim [a] a)
- Actual type: Prim [a] a -> a
- In the first argument of ‘ana’, namely ‘alg’
- In the expression: ana alg
- Relevant bindings include
- foo :: Prim [a] a -> t (bound at T7354.hs:28:1)
+T7354.hs:28:11: error:
+ • Occurs check: cannot construct the infinite type:
+ t1 ~ Base t (Prim [t1] t1)
+ Expected type: Prim [t1] t1 -> Base t (Prim [t1] t1)
+ Actual type: Prim [t1] t1 -> t1
+ • In the first argument of ‘ana’, namely ‘alg’
+ In the expression: ana alg
+ In an equation for ‘foo’: foo = ana alg
+ • Relevant bindings include
+ foo :: Prim [t1] t1 -> t (bound at T7354.hs:28:1)
diff --git a/testsuite/tests/indexed-types/should_fail/T7354a.stderr b/testsuite/tests/indexed-types/should_fail/T7354a.stderr
index ed38da6ed2..a5ec40630e 100644
--- a/testsuite/tests/indexed-types/should_fail/T7354a.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T7354a.stderr
@@ -1,6 +1,7 @@
-T7354a.hs:5:13:
- Couldn't match expected type ‘Base t t’ with actual type ‘()’
- In the first argument of ‘embed’, namely ‘()’
- In the expression: embed ()
- Relevant bindings include foo :: t (bound at T7354a.hs:5:1)
+T7354a.hs:5:13: error:
+ • Couldn't match expected type ‘Base t t’ with actual type ‘()’
+ • In the first argument of ‘embed’, namely ‘()’
+ In the expression: embed ()
+ In an equation for ‘foo’: foo = embed ()
+ • Relevant bindings include foo :: t (bound at T7354a.hs:5:1)
diff --git a/testsuite/tests/indexed-types/should_fail/T7729.stderr b/testsuite/tests/indexed-types/should_fail/T7729.stderr
index 6686f39ca0..e892eea3c0 100644
--- a/testsuite/tests/indexed-types/should_fail/T7729.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T7729.stderr
@@ -1,11 +1,12 @@
T7729.hs:36:14: error:
- Couldn't match type ‘BasePrimMonad m’ with ‘t0 (BasePrimMonad m)’
- The type variable ‘t0’ is ambiguous
- Expected type: t0 (BasePrimMonad m) a -> Rand m a
- Actual type: BasePrimMonad (Rand m) a -> Rand m a
- In the first argument of ‘(.)’, namely ‘liftPrim’
- In the expression: liftPrim . lift
- Relevant bindings include
- liftPrim :: BasePrimMonad (Rand m) a -> Rand m a
- (bound at T7729.hs:36:3)
+ • Couldn't match type ‘BasePrimMonad m’ with ‘t0 (BasePrimMonad m)’
+ The type variable ‘t0’ is ambiguous
+ Expected type: t0 (BasePrimMonad m) a -> Rand m a
+ Actual type: BasePrimMonad (Rand m) a -> Rand m a
+ • In the first argument of ‘(.)’, namely ‘liftPrim’
+ In the expression: liftPrim . lift
+ In an equation for ‘liftPrim’: liftPrim = liftPrim . lift
+ • Relevant bindings include
+ liftPrim :: BasePrimMonad (Rand m) a -> Rand m a
+ (bound at T7729.hs:36:3)
diff --git a/testsuite/tests/indexed-types/should_fail/T7729a.stderr b/testsuite/tests/indexed-types/should_fail/T7729a.stderr
index ca5f29f2c7..513a132191 100644
--- a/testsuite/tests/indexed-types/should_fail/T7729a.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T7729a.stderr
@@ -1,12 +1,13 @@
-T7729a.hs:36:26:
- Couldn't match type ‘BasePrimMonad m’ with ‘t0 (BasePrimMonad m)’
- The type variable ‘t0’ is ambiguous
- Expected type: BasePrimMonad (Rand m) a
- Actual type: t0 (BasePrimMonad m) a
- In the first argument of ‘liftPrim’, namely ‘(lift x)’
- In the expression: liftPrim (lift x)
- Relevant bindings include
- x :: BasePrimMonad (Rand m) a (bound at T7729a.hs:36:12)
- liftPrim :: BasePrimMonad (Rand m) a -> Rand m a
- (bound at T7729a.hs:36:3)
+T7729a.hs:36:26: error:
+ • Couldn't match type ‘BasePrimMonad m’ with ‘t0 (BasePrimMonad m)’
+ The type variable ‘t0’ is ambiguous
+ Expected type: BasePrimMonad (Rand m) a
+ Actual type: t0 (BasePrimMonad m) a
+ • In the first argument of ‘liftPrim’, namely ‘(lift x)’
+ In the expression: liftPrim (lift x)
+ In an equation for ‘liftPrim’: liftPrim x = liftPrim (lift x)
+ • Relevant bindings include
+ x :: BasePrimMonad (Rand m) a (bound at T7729a.hs:36:12)
+ liftPrim :: BasePrimMonad (Rand m) a -> Rand m a
+ (bound at T7729a.hs:36:3)
diff --git a/testsuite/tests/indexed-types/should_fail/T7788.stderr b/testsuite/tests/indexed-types/should_fail/T7788.stderr
index 757c05089e..fa4f3ed260 100644
--- a/testsuite/tests/indexed-types/should_fail/T7788.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T7788.stderr
@@ -1,10 +1,11 @@
T7788.hs:19:20: error:
- Reduction stack overflow; size = 201
- When simplifying the following type: F (Id (Fix Id))
- Use -freduction-depth=0 to disable this check
- (any upper bound you could choose might fail unpredictably with
- minor updates to GHC, so disabling the check is recommended if
- you're sure that type checking should terminate)
- In the first argument of ‘foo’, namely ‘Proxy’
- In the second argument of ‘($)’, namely ‘foo Proxy’
+ • Reduction stack overflow; size = 201
+ When simplifying the following type: F (Id (Fix Id))
+ Use -freduction-depth=0 to disable this check
+ (any upper bound you could choose might fail unpredictably with
+ minor updates to GHC, so disabling the check is recommended if
+ you're sure that type checking should terminate)
+ • In the first argument of ‘foo’, namely ‘Proxy’
+ In the second argument of ‘($)’, namely ‘foo Proxy’
+ In the expression: print $ foo Proxy
diff --git a/testsuite/tests/indexed-types/should_fail/T8227.stderr b/testsuite/tests/indexed-types/should_fail/T8227.stderr
index 8ac3d94a55..6dec5d0191 100644
--- a/testsuite/tests/indexed-types/should_fail/T8227.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T8227.stderr
@@ -5,6 +5,8 @@ T8227.hs:16:44: error:
NB: ‘Scalar’ is a type function, and may not be injective
• In the first argument of ‘arcLengthToParam’, namely ‘eps’
In the expression: arcLengthToParam eps eps
+ In an equation for ‘absoluteToParam’:
+ absoluteToParam eps seg = arcLengthToParam eps eps
• Relevant bindings include
seg :: a (bound at T8227.hs:16:21)
eps :: Scalar (V a) (bound at T8227.hs:16:17)
diff --git a/testsuite/tests/indexed-types/should_fail/T8518.stderr b/testsuite/tests/indexed-types/should_fail/T8518.stderr
index 8a267d7bd0..0df2b3cf83 100644
--- a/testsuite/tests/indexed-types/should_fail/T8518.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T8518.stderr
@@ -1,28 +1,32 @@
-T8518.hs:14:18:
- Couldn't match expected type ‘Maybe (F c)’ with actual type ‘F c’
- In the expression: rpt (4 :: Int) c z b
- In an equation for ‘callCont’:
- callCont c z b
- = rpt (4 :: Int) c z b
- where
- rpt 0 c' z' b' = fromJust (fst <$> (continue c' z' b'))
- rpt i c' z' b' = let ... in rpt (i - 1) c''
- Relevant bindings include
- b :: B c (bound at T8518.hs:14:14)
- z :: Z c (bound at T8518.hs:14:12)
- c :: c (bound at T8518.hs:14:10)
- callCont :: c -> Z c -> B c -> Maybe (F c) (bound at T8518.hs:14:1)
+T8518.hs:14:18: error:
+ • Couldn't match expected type ‘Maybe (F c)’ with actual type ‘F c’
+ • In the expression: rpt (4 :: Int) c z b
+ In an equation for ‘callCont’:
+ callCont c z b
+ = rpt (4 :: Int) c z b
+ where
+ rpt 0 c' z' b' = fromJust (fst <$> (continue c' z' b'))
+ rpt i c' z' b' = let ... in rpt (i - 1) c''
+ • Relevant bindings include
+ b :: B c (bound at T8518.hs:14:14)
+ z :: Z c (bound at T8518.hs:14:12)
+ c :: c (bound at T8518.hs:14:10)
+ callCont :: c -> Z c -> B c -> Maybe (F c) (bound at T8518.hs:14:1)
-T8518.hs:17:78:
- Couldn't match expected type ‘F a1’
- with actual type ‘Z a1 -> B a1 -> F a1’
- In the expression: rpt (i - 1) c''
- In the expression:
- let c'' = fromJust (snd <$> (continue c' z' b')) in rpt (i - 1) c''
- Relevant bindings include
- c'' :: a1 (bound at T8518.hs:17:30)
- b' :: B a1 (bound at T8518.hs:17:21)
- z' :: Z a1 (bound at T8518.hs:17:18)
- c' :: a1 (bound at T8518.hs:17:15)
- rpt :: a -> a1 -> Z a1 -> B a1 -> F a1 (bound at T8518.hs:16:9)
+T8518.hs:17:78: error:
+ • Couldn't match expected type ‘F a’
+ with actual type ‘Z a -> B a -> F a’
+ • In the expression: rpt (i - 1) c''
+ In the expression:
+ let c'' = fromJust (snd <$> (continue c' z' b')) in rpt (i - 1) c''
+ In an equation for ‘rpt’:
+ rpt i c' z' b'
+ = let c'' = fromJust (snd <$> (continue c' z' b'))
+ in rpt (i - 1) c''
+ • Relevant bindings include
+ c'' :: a (bound at T8518.hs:17:30)
+ b' :: B a (bound at T8518.hs:17:21)
+ z' :: Z a (bound at T8518.hs:17:18)
+ c' :: a (bound at T8518.hs:17:15)
+ rpt :: a1 -> a -> Z a -> B a -> F a (bound at T8518.hs:16:9)
diff --git a/testsuite/tests/indexed-types/should_fail/T9554.stderr b/testsuite/tests/indexed-types/should_fail/T9554.stderr
index 0baf5d78ff..b62badda9d 100644
--- a/testsuite/tests/indexed-types/should_fail/T9554.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T9554.stderr
@@ -1,22 +1,24 @@
-T9554.hs:11:9:
- Reduction stack overflow; size = 201
- When simplifying the following type:
- F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F Bool)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
- Use -freduction-depth=0 to disable this check
- (any upper bound you could choose might fail unpredictably with
- minor updates to GHC, so disabling the check is recommended if
- you're sure that type checking should terminate)
- In the expression: x
- In an equation for ‘foo’: foo x = x
+T9554.hs:11:9: error:
+ • Reduction stack overflow; size = 201
+ When simplifying the following type:
+ F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F Bool)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+ Use -freduction-depth=0 to disable this check
+ (any upper bound you could choose might fail unpredictably with
+ minor updates to GHC, so disabling the check is recommended if
+ you're sure that type checking should terminate)
+ • In the expression: x
+ In an equation for ‘foo’: foo x = x
-T9554.hs:13:17:
- Reduction stack overflow; size = 201
- When simplifying the following type:
- F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F Bool)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
- Use -freduction-depth=0 to disable this check
- (any upper bound you could choose might fail unpredictably with
- minor updates to GHC, so disabling the check is recommended if
- you're sure that type checking should terminate)
- In the first argument of ‘foo’, namely ‘Proxy’
- In the expression: foo Proxy
+T9554.hs:13:17: error:
+ • Reduction stack overflow; size = 201
+ When simplifying the following type:
+ F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F (F Bool)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+ Use -freduction-depth=0 to disable this check
+ (any upper bound you could choose might fail unpredictably with
+ minor updates to GHC, so disabling the check is recommended if
+ you're sure that type checking should terminate)
+ • In the first argument of ‘foo’, namely ‘Proxy’
+ In the expression: foo Proxy
+ In the expression:
+ case foo Proxy of { Proxy -> putStrLn "Made it!" }
diff --git a/testsuite/tests/indexed-types/should_fail/T9662.stderr b/testsuite/tests/indexed-types/should_fail/T9662.stderr
index 36b0716a9a..efa3a73bf5 100644
--- a/testsuite/tests/indexed-types/should_fail/T9662.stderr
+++ b/testsuite/tests/indexed-types/should_fail/T9662.stderr
@@ -6,7 +6,7 @@ T9662.hs:47:8: error:
test :: forall sh k m n.
Shape (((sh :. k) :. m) :. n) -> Shape (((sh :. m) :. n) :. k)
at T9662.hs:44:9
- Expected type: Exp (((sh :. k) :. m) :. n)
+ Expected type: Exp (((sh :. m) :. n) :. k)
-> Exp (((sh :. m) :. n) :. k)
Actual type: Exp
(Tuple (((Atom a0 :. Atom Int) :. Atom Int) :. Atom Int))
@@ -22,6 +22,13 @@ T9662.hs:47:8: error:
(atom :. atom :. atom :. atom)
(\ (sh :. k :. m :. n) -> (sh :. m :. n :. k)))
id
+ In an equation for ‘test’:
+ test
+ = backpermute
+ (modify
+ (atom :. atom :. atom :. atom)
+ (\ (sh :. k :. m :. n) -> (sh :. m :. n :. k)))
+ id
• Relevant bindings include
test :: Shape (((sh :. k) :. m) :. n)
-> Shape (((sh :. m) :. n) :. k)
diff --git a/testsuite/tests/module/mod121.stderr b/testsuite/tests/module/mod121.stderr
index aa0a8cd4af..fda1dec212 100644
--- a/testsuite/tests/module/mod121.stderr
+++ b/testsuite/tests/module/mod121.stderr
@@ -1,4 +1,4 @@
-
-mod121.hs:5:5: error:
- Variable not in scope: m2 :: Int -> t
- Perhaps you meant ‘m1’ (imported from Mod121_A)
+
+mod121.hs:5:5: error:
+ • Variable not in scope: m2 :: Int -> t
+ • Perhaps you meant ‘m1’ (imported from Mod121_A)
diff --git a/testsuite/tests/module/mod147.stderr b/testsuite/tests/module/mod147.stderr
index 335dbd2211..39bf7d2dc7 100644
--- a/testsuite/tests/module/mod147.stderr
+++ b/testsuite/tests/module/mod147.stderr
@@ -1,3 +1,3 @@
-
-mod147.hs:6:5: error:
- Data constructor not in scope: D :: Integer -> t
+
+mod147.hs:6:5: error:
+ Data constructor not in scope: D :: Integer -> t
diff --git a/testsuite/tests/module/mod160.stderr b/testsuite/tests/module/mod160.stderr
index a4b8669de8..d853c67e6b 100644
--- a/testsuite/tests/module/mod160.stderr
+++ b/testsuite/tests/module/mod160.stderr
@@ -1,6 +1,6 @@
-
-mod160.hs:12:5: error:
- Variable not in scope: m3 :: Char -> t
- Perhaps you meant one of these:
- ‘m1’ (imported from Mod159_D), ‘m2’ (imported from Mod159_D)
-exit(1)
+
+mod160.hs:12:5: error:
+ • Variable not in scope: m3 :: Char -> t
+ • Perhaps you meant one of these:
+ ‘m1’ (imported from Mod159_D), ‘m2’ (imported from Mod159_D)
+exit(1)
diff --git a/testsuite/tests/module/mod69.stderr b/testsuite/tests/module/mod69.stderr
index d7f92be69a..db7487485e 100644
--- a/testsuite/tests/module/mod69.stderr
+++ b/testsuite/tests/module/mod69.stderr
@@ -1,2 +1,4 @@
-mod69.hs:3:7: Pattern syntax in expression context: x@1
+mod69.hs:3:7: error:
+ Pattern syntax in expression context: x@1
+ Did you mean to enable TypeApplications?
diff --git a/testsuite/tests/module/mod70.stderr b/testsuite/tests/module/mod70.stderr
index 110ff24afe..f0e3042d3d 100644
--- a/testsuite/tests/module/mod70.stderr
+++ b/testsuite/tests/module/mod70.stderr
@@ -1,2 +1,4 @@
-mod70.hs:3:8: Pattern syntax in expression context: ~1
+mod70.hs:3:8: error:
+ Pattern syntax in expression context: ~1
+ Did you mean to enable TypeApplications?
diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail07.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail07.stderr
index 87de242e4b..73a1b9b4d8 100644
--- a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail07.stderr
+++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail07.stderr
@@ -1,6 +1,7 @@
-overloadedrecfldsfail07.hs:7:7:
- Couldn't match expected type ‘T’ with actual type ‘T -> Int’
- Probable cause: ‘x’ is applied to too few arguments
- In the first argument of ‘x’, namely ‘x’
- In the expression: x x
+overloadedrecfldsfail07.hs:7:7: error:
+ • Couldn't match expected type ‘T’ with actual type ‘T -> Int’
+ • Probable cause: ‘x’ is applied to too few arguments
+ In the first argument of ‘x’, namely ‘x’
+ In the expression: x x
+ In an equation for ‘y’: y = x x
diff --git a/testsuite/tests/parser/should_compile/T2245.stderr b/testsuite/tests/parser/should_compile/T2245.stderr
index 1f5f87f7c7..783b751b34 100644
--- a/testsuite/tests/parser/should_compile/T2245.stderr
+++ b/testsuite/tests/parser/should_compile/T2245.stderr
@@ -13,10 +13,10 @@ T2245.hs:5:10: warning:
T2245.hs:7:29: warning:
• Defaulting the following constraints to type ‘T’
- (Fractional b0)
+ (Fractional a0)
arising from the literal ‘1e400’ at T2245.hs:7:29-33
- (Ord b0) arising from a use of ‘<’ at T2245.hs:7:27
- (Read b0) arising from a use of ‘read’ at T2245.hs:7:38-41
+ (Ord a0) arising from an operator section at T2245.hs:7:27-33
+ (Read a0) arising from a use of ‘read’ at T2245.hs:7:38-41
• In the second argument of ‘(<)’, namely ‘1e400’
In the first argument of ‘(.)’, namely ‘(< 1e400)’
In the second argument of ‘(.)’, namely ‘(< 1e400) . read’
diff --git a/testsuite/tests/parser/should_compile/VtaParse.hs b/testsuite/tests/parser/should_compile/VtaParse.hs
new file mode 100644
index 0000000000..b1cfd7d4d0
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/VtaParse.hs
@@ -0,0 +1,63 @@
+{-# LANGUAGE TypeApplications, RankNTypes, DataKinds, PolyKinds #-}
+
+module VtaParse where
+
+import Data.Proxy
+
+data Foo = Foo { first :: Int, second :: Bool} deriving Show
+
+f :: a -> b -> (a,b)
+f u v = (u, v)
+
+g :: Int -> Int -> (Int, Int)
+g u v = f @(Int) @Int u v
+
+dblTuple :: (a, b) -> ((a, b), b)
+dblTuple e@(_,y) = (e, y)
+
+
+-- interesting note:
+-- listpair :: forall a. [a] -> ([a], [a])
+-- therefore when explicitly applying, you do NOT put the type in "[ ]"
+
+listpair :: [a] -> ([a], [a])
+listpair [] = ([], [])
+listpair b@(_:_) = (b, b)
+
+-- suggested two cases by R. Eisenberg
+newtype N = MkN { unMkN :: forall a. Show a => a -> String }
+n = MkN show
+foo :: Bool -> String
+foo = unMkN n @Bool -- Fails without parens! Not anymore!
+
+(&&) :: Bool -> Bool -> Bool
+(b@True) && True = True
+_ && _ = False
+
+(*@&) :: a -> a -> (a, a)
+x *@& y = (x, y)
+
+(@&) :: a -> a -> (a, a)
+x @& y = (x, y)
+
+main :: IO ()
+main = do
+ print $ g 5 12
+ print $ ((id @String (concat ["hello ", "world ", []])):"Hamidhasan":[])
+ print $ dblTuple @(Foo) @String ((Foo 5 True), "hello")
+ print $ listpair @(Maybe Int) [Just 12, Nothing]
+ print $ listpair @(Maybe Bool) $ (Just True) : (Just False) : (Nothing @Bool) : []
+ print $ dblTuple @Foo @[Maybe Int] ((Foo 7 False), ([Just 5, Nothing]))
+ print $ 12 @& 5
+
+pro :: Proxy a -> ()
+pro _ = ()
+
+x = pro @'True
+
+(@@) :: Int -> Int -> Int
+(@@) = (+)
+
+five = 3 @@ 2
+
+silly = pro {- hi! -}@Int
diff --git a/testsuite/tests/parser/should_compile/all.T b/testsuite/tests/parser/should_compile/all.T
index 0030040aed..9446bf1cfa 100644
--- a/testsuite/tests/parser/should_compile/all.T
+++ b/testsuite/tests/parser/should_compile/all.T
@@ -101,5 +101,6 @@ test('T5682', normal, compile, [''])
test('T9723a', normal, compile, [''])
test('T9723b', normal, compile, [''])
test('T10188', normal, compile, [''])
+test('VtaParse', normal, compile, [''])
test('T10196', normal, compile, [''])
test('T10582', expect_broken(10582), compile, [''])
diff --git a/testsuite/tests/parser/should_compile/read014.stderr b/testsuite/tests/parser/should_compile/read014.stderr
index 5302b3476e..ebc07af88e 100644
--- a/testsuite/tests/parser/should_compile/read014.stderr
+++ b/testsuite/tests/parser/should_compile/read014.stderr
@@ -1,13 +1,13 @@
-read014.hs:4:1: Warning:
+read014.hs:4:1: warning:
Top-level binding with no type signature:
ng1 :: forall r a. Num a => r -> a -> a
-read014.hs:4:5: Warning: Defined but not used: ‘x’
+read014.hs:4:5: warning: Defined but not used: ‘x’
-read014.hs:6:10: Warning:
+read014.hs:6:10: warning:
No explicit implementation for
‘+’, ‘*’, ‘abs’, ‘signum’, and ‘fromInteger’
In the instance declaration for ‘Num (a, b)’
-read014.hs:8:53: Warning: Defined but not used: ‘x’
+read014.hs:8:53: warning: Defined but not used: ‘x’
diff --git a/testsuite/tests/parser/should_fail/readFail003.stderr b/testsuite/tests/parser/should_fail/readFail003.stderr
index 8b9b4d0295..e837eeedd1 100644
--- a/testsuite/tests/parser/should_fail/readFail003.stderr
+++ b/testsuite/tests/parser/should_fail/readFail003.stderr
@@ -1,7 +1,7 @@
readFail003.hs:4:27: error:
• Occurs check: cannot construct the infinite type:
- r ~ (r, [a], [a1])
+ t ~ (t, [a], [a1])
• In the expression: a
In a pattern binding:
~(a, b, c)
@@ -11,6 +11,6 @@ readFail003.hs:4:27: error:
where
nullity = null
• Relevant bindings include
- a :: r (bound at readFail003.hs:4:3)
+ a :: t (bound at readFail003.hs:4:3)
b :: [a] (bound at readFail003.hs:4:5)
c :: [a1] (bound at readFail003.hs:4:7)
diff --git a/testsuite/tests/partial-sigs/should_compile/T10403.stderr b/testsuite/tests/partial-sigs/should_compile/T10403.stderr
index 5337cc3d12..9cda918ae8 100644
--- a/testsuite/tests/partial-sigs/should_compile/T10403.stderr
+++ b/testsuite/tests/partial-sigs/should_compile/T10403.stderr
@@ -59,7 +59,7 @@ T10403.hs:28:8: warning:
app2 :: H (B t)
at T10403.hs:27:1-15
Expected type: H (B t)
- Actual type: H f0
+ Actual type: H f0
• In the expression: h2 (H . I) (B ())
In an equation for ‘app2’: app2 = h2 (H . I) (B ())
• Relevant bindings include
@@ -73,8 +73,9 @@ T10403.hs:28:20: warning:
app2 :: H (B t)
at T10403.hs:27:1-15
Expected type: f0 ()
- Actual type: B t ()
+ Actual type: B t ()
• In the second argument of ‘h2’, namely ‘(B ())’
In the expression: h2 (H . I) (B ())
+ In an equation for ‘app2’: app2 = h2 (H . I) (B ())
• Relevant bindings include
app2 :: H (B t) (bound at T10403.hs:28:1)
diff --git a/testsuite/tests/partial-sigs/should_compile/T10438.stderr b/testsuite/tests/partial-sigs/should_compile/T10438.stderr
index 5624d8dc9e..f26bfe7a8d 100644
--- a/testsuite/tests/partial-sigs/should_compile/T10438.stderr
+++ b/testsuite/tests/partial-sigs/should_compile/T10438.stderr
@@ -25,4 +25,4 @@ T10438.hs:7:22: warning:
r :: r2 (bound at T10438.hs:6:11)
g :: r2 -> r2 (bound at T10438.hs:6:9)
f :: r (bound at T10438.hs:5:5)
- foo :: r -> r1 -> r1 (bound at T10438.hs:5:1)
+ foo :: r -> forall r1. r1 -> r1 (bound at T10438.hs:5:1)
diff --git a/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInExpressionSignature.stderr b/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInExpressionSignature.stderr
index f08e1807c0..9f04fc2cf2 100644
--- a/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInExpressionSignature.stderr
+++ b/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInExpressionSignature.stderr
@@ -1,4 +1,4 @@
-
-ExtraConstraintsWildcardInExpressionSignature.hs:3:20: error:
- Extra-contraint wildcard ‘_’ not allowed
- in an expression type signature
+
+ExtraConstraintsWildcardInExpressionSignature.hs:3:20: error:
+ Extra-constraint wildcard ‘_’ not allowed
+ in an expression type signature
diff --git a/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInPatternSignature.stderr b/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInPatternSignature.stderr
index 0e2a66a877..9711e34121 100644
--- a/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInPatternSignature.stderr
+++ b/testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInPatternSignature.stderr
@@ -1,4 +1,4 @@
-
-ExtraConstraintsWildcardInPatternSignature.hs:4:11: error:
- Extra-contraint wildcard ‘_’ not allowed
- in a pattern type-signature
+
+ExtraConstraintsWildcardInPatternSignature.hs:4:11: error:
+ Extra-constraint wildcard ‘_’ not allowed
+ in a pattern type-signature
diff --git a/testsuite/tests/partial-sigs/should_fail/Forall1Bad.stderr b/testsuite/tests/partial-sigs/should_fail/Forall1Bad.stderr
index 266232cab0..26c895ef3c 100644
--- a/testsuite/tests/partial-sigs/should_fail/Forall1Bad.stderr
+++ b/testsuite/tests/partial-sigs/should_fail/Forall1Bad.stderr
@@ -1,5 +1,5 @@
-Forall1Bad.hs:9:13:
- Couldn't match expected type ‘Char’ with actual type ‘Bool’
- In the first argument of ‘fall’, namely ‘True’
- In the expression: fall True
+Forall1Bad.hs:9:8: error:
+ • Couldn't match expected type ‘Char’ with actual type ‘Bool’
+ • In the expression: fall True
+ In an equation for ‘test’: test = fall True
diff --git a/testsuite/tests/partial-sigs/should_fail/NamedWildcardExplicitForall.stderr b/testsuite/tests/partial-sigs/should_fail/NamedWildcardExplicitForall.stderr
index bfe68d8718..83a9019401 100644
--- a/testsuite/tests/partial-sigs/should_fail/NamedWildcardExplicitForall.stderr
+++ b/testsuite/tests/partial-sigs/should_fail/NamedWildcardExplicitForall.stderr
@@ -29,12 +29,13 @@ NamedWildcardExplicitForall.hs:13:26: error:
baz :: _a -> Bool -> (_a, Bool)
(bound at NamedWildcardExplicitForall.hs:14:1)
-NamedWildcardExplicitForall.hs:14:12: error:
- • Couldn't match expected type ‘_a’ with actual type ‘Bool’
+NamedWildcardExplicitForall.hs:14:16: error:
+ • Couldn't match expected type ‘Bool’ with actual type ‘_a’
‘_a’ is a rigid type variable bound by
the inferred type of baz :: _a -> Bool -> (_a, Bool)
at NamedWildcardExplicitForall.hs:13:15
- • In the expression: not x
+ • In the first argument of ‘not’, namely ‘x’
+ In the expression: not x
In the expression: (not x, not y)
• Relevant bindings include
x :: _a (bound at NamedWildcardExplicitForall.hs:14:5)
diff --git a/testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotEnabled.stderr b/testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotEnabled.stderr
index 0de48b4dcd..46cad28a12 100644
--- a/testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotEnabled.stderr
+++ b/testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotEnabled.stderr
@@ -18,6 +18,7 @@ NamedWildcardsNotEnabled.hs:4:13: error:
at NamedWildcardsNotEnabled.hs:3:8
• In the first argument of ‘not’, namely ‘x’
In the expression: not x
+ In an equation for ‘foo’: foo x = not x
• Relevant bindings include
x :: _a (bound at NamedWildcardsNotEnabled.hs:4:5)
foo :: _a -> _b (bound at NamedWildcardsNotEnabled.hs:4:1)
diff --git a/testsuite/tests/partial-sigs/should_fail/ScopedNamedWildcardsBad.stderr b/testsuite/tests/partial-sigs/should_fail/ScopedNamedWildcardsBad.stderr
index b943dfba2b..713bdc65c3 100644
--- a/testsuite/tests/partial-sigs/should_fail/ScopedNamedWildcardsBad.stderr
+++ b/testsuite/tests/partial-sigs/should_fail/ScopedNamedWildcardsBad.stderr
@@ -1,5 +1,6 @@
-ScopedNamedWildcardsBad.hs:8:21:
- Couldn't match expected type ‘Bool’ with actual type ‘Char’
- In the first argument of ‘not’, namely ‘x’
- In the expression: not x
+ScopedNamedWildcardsBad.hs:8:21: error:
+ • Couldn't match expected type ‘Bool’ with actual type ‘Char’
+ • In the first argument of ‘not’, namely ‘x’
+ In the expression: not x
+ In an equation for ‘v’: v = not x
diff --git a/testsuite/tests/patsyn/should_fail/records-poly-update.stderr b/testsuite/tests/patsyn/should_fail/records-poly-update.stderr
index ed456ff171..44bee9b2c3 100644
--- a/testsuite/tests/patsyn/should_fail/records-poly-update.stderr
+++ b/testsuite/tests/patsyn/should_fail/records-poly-update.stderr
@@ -1,5 +1,6 @@
records-poly-update.hs:11:14: error:
- Couldn't match expected type ‘Bool’ with actual type ‘A’
- In the ‘j’ field of a record
- In the expression: p1 {j = A}
+ • Couldn't match expected type ‘Bool’ with actual type ‘A’
+ • In the ‘j’ field of a record
+ In the expression: p1 {j = A}
+ In an equation for ‘p6’: p6 = p1 {j = A}
diff --git a/testsuite/tests/perf/compiler/all.T b/testsuite/tests/perf/compiler/all.T
index 42f2bc9c16..9c3daa71b1 100644
--- a/testsuite/tests/perf/compiler/all.T
+++ b/testsuite/tests/perf/compiler/all.T
@@ -394,7 +394,7 @@ test('T5631',
# expected value: 392904228 (x86/Linux)
# 2014-04-04: 346389856 (x86 Windows, 64 bit machine)
# 2014-12-01: 390199244 (Windows laptop)
- (wordsize(64), 1128828928, 5)]),
+ (wordsize(64), 1198327544, 5)]),
# expected value: 774595008 (amd64/Linux):
# expected value: 735486328 (amd64/Linux) 2012/12/12:
# expected value: 690742040 (amd64/Linux) Call Arity improvements
@@ -402,6 +402,7 @@ test('T5631',
# 2014-11-04: 776121120 (amd64/Linux) new-flatten-skolems
# 2015-06-01: 812288344 (amd64/Linux) unknown cause
# 2015-12-11: 1128828928 (amd64/Linux) TypeInType (see #11196)
+ # 2015-12-21: 1198327544 (Mac) TypeApplications (will fix with #11196)
only_ways(['normal'])
],
compile,
diff --git a/testsuite/tests/polykinds/T10503.stderr b/testsuite/tests/polykinds/T10503.stderr
index 7c39c41738..141f16fc6e 100644
--- a/testsuite/tests/polykinds/T10503.stderr
+++ b/testsuite/tests/polykinds/T10503.stderr
@@ -9,8 +9,6 @@ T10503.hs:8:6: error:
the type signature for:
h :: forall k r. ((Proxy 'KProxy ~ Proxy 'KProxy) => r) -> r
at T10503.hs:8:6
- Expected type: ((Proxy 'KProxy ~ Proxy 'KProxy) => r) -> r
- Actual type: ((Proxy 'KProxy ~ Proxy 'KProxy) => r) -> r
• In the ambiguity check for ‘h’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
diff --git a/testsuite/tests/polykinds/T6068.stdout b/testsuite/tests/polykinds/T6068.stdout
index e096418727..f0fe7de899 100644
--- a/testsuite/tests/polykinds/T6068.stdout
+++ b/testsuite/tests/polykinds/T6068.stdout
@@ -1 +1 @@
-exists Nothing :: Floop a mp => Existential mp
+exists Nothing :: Floop a mp => Existential mp
diff --git a/testsuite/tests/polykinds/T7438.stderr b/testsuite/tests/polykinds/T7438.stderr
index 539d15d406..46b7181840 100644
--- a/testsuite/tests/polykinds/T7438.stderr
+++ b/testsuite/tests/polykinds/T7438.stderr
@@ -2,18 +2,18 @@
T7438.hs:6:14: error:
• Couldn't match expected type ‘r1’ with actual type ‘r’
‘r1’ is untouchable
- inside the constraints: r3 ~ r2
+ inside the constraints: t1 ~ t
bound by a pattern with constructor:
Nil :: forall k (a :: k). Thrist a a,
in an equation for ‘go’
at T7438.hs:6:4-6
‘r1’ is a rigid type variable bound by
- the inferred type of go :: Thrist r2 r3 -> r -> r1 at T7438.hs:6:1
+ the inferred type of go :: Thrist t t1 -> r -> r1 at T7438.hs:6:1
‘r’ is a rigid type variable bound by
- the inferred type of go :: Thrist r2 r3 -> r -> r1 at T7438.hs:6:1
+ the inferred type of go :: Thrist t t1 -> r -> r1 at T7438.hs:6:1
Possible fix: add a type signature for ‘go’
• In the expression: acc
In an equation for ‘go’: go Nil acc = acc
• Relevant bindings include
acc :: r (bound at T7438.hs:6:8)
- go :: Thrist r2 r3 -> r -> r1 (bound at T7438.hs:6:1)
+ go :: Thrist t t1 -> r -> r1 (bound at T7438.hs:6:1)
diff --git a/testsuite/tests/polykinds/T7594.stderr b/testsuite/tests/polykinds/T7594.stderr
index 2f1844ecdb..be2acfebe0 100644
--- a/testsuite/tests/polykinds/T7594.stderr
+++ b/testsuite/tests/polykinds/T7594.stderr
@@ -13,4 +13,5 @@ T7594.hs:35:12: error:
Actual type: a -> IO ()
• In the first argument of ‘app’, namely ‘print’
In the expression: app print q2
+ In an equation for ‘bar2’: bar2 = app print q2
• Relevant bindings include bar2 :: b (bound at T7594.hs:35:1)
diff --git a/testsuite/tests/polykinds/T9144.stderr b/testsuite/tests/polykinds/T9144.stderr
index f2c65530ee..b62d1f175d 100644
--- a/testsuite/tests/polykinds/T9144.stderr
+++ b/testsuite/tests/polykinds/T9144.stderr
@@ -1,7 +1,9 @@
-
-T9144.hs:34:26:
- Couldn't match type ‘Integer’ with ‘FooTerm’
- Expected type: DemoteRep 'KProxy
- Actual type: DemoteRep 'KProxy
- In the first argument of ‘toSing’, namely ‘n’
- In the expression: toSing n
+
+T9144.hs:34:26: error:
+ • Couldn't match type ‘Integer’ with ‘FooTerm’
+ Expected type: DemoteRep 'KProxy
+ Actual type: DemoteRep 'KProxy
+ • In the first argument of ‘toSing’, namely ‘n’
+ In the expression: toSing n
+ In the expression:
+ case toSing n of { SomeSing n' -> SomeSing (SBar n') }
diff --git a/testsuite/tests/polykinds/TidyClassKinds.hs b/testsuite/tests/polykinds/TidyClassKinds.hs
new file mode 100644
index 0000000000..83f6eaaea2
--- /dev/null
+++ b/testsuite/tests/polykinds/TidyClassKinds.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE MultiParamTypeClasses, PolyKinds #-}
+{-# OPTIONS_GHC -fprint-explicit-kinds #-}
+
+module TidyClassKinds where
+
+import Data.Proxy
+
+class Poly a b
+
+type ProxySyn = Proxy
+
+instance Poly ProxySyn ProxySyn
+ -- output should really talk about k1 and k2, not about k and k!
diff --git a/testsuite/tests/polykinds/TidyClassKinds.stderr b/testsuite/tests/polykinds/TidyClassKinds.stderr
new file mode 100644
index 0000000000..69ca49c188
--- /dev/null
+++ b/testsuite/tests/polykinds/TidyClassKinds.stderr
@@ -0,0 +1,8 @@
+
+TidyClassKinds.hs:12:10: error:
+ • Illegal instance declaration for
+ ‘Poly (k1 -> *) (k1 -> *) (ProxySyn k1) (ProxySyn k1)’
+ (All instance types must be of the form (T t1 ... tn)
+ where T is not a synonym.
+ Use TypeSynonymInstances if you want to disable this.)
+ • In the instance declaration for ‘Poly ProxySyn ProxySyn’
diff --git a/testsuite/tests/polykinds/all.T b/testsuite/tests/polykinds/all.T
index 6387d1790d..5a8a9043ab 100644
--- a/testsuite/tests/polykinds/all.T
+++ b/testsuite/tests/polykinds/all.T
@@ -127,6 +127,7 @@ test('T11142', normal, compile_fail, [''])
test('SigTvKinds', normal, compile, [''])
test('SigTvKinds2', expect_broken(11203), compile_fail, [''])
test('T9017', normal, compile_fail, [''])
+test('TidyClassKinds', normal, compile_fail, ['-fprint-explicit-kinds'])
test('T11249', normal, compile, [''])
test('T11248', normal, compile, [''])
test('T11278', normal, compile, [''])
diff --git a/testsuite/tests/rename/should_compile/T3823.stderr b/testsuite/tests/rename/should_compile/T3823.stderr
index 8ab375fcd4..6287a3529f 100644
--- a/testsuite/tests/rename/should_compile/T3823.stderr
+++ b/testsuite/tests/rename/should_compile/T3823.stderr
@@ -1,5 +1,6 @@
-T3823B.hs:8:7:
+T3823B.hs:8:7: error:
Couldn't match expected type ‘A’ with actual type ‘Bool’
In the first argument of ‘y’, namely ‘a’
In the expression: y a
+ In an equation for ‘b’: b = y a
diff --git a/testsuite/tests/rename/should_fail/T10618.stderr b/testsuite/tests/rename/should_fail/T10618.stderr
index 01e194877f..8b4dc2c28d 100644
--- a/testsuite/tests/rename/should_fail/T10618.stderr
+++ b/testsuite/tests/rename/should_fail/T10618.stderr
@@ -1,6 +1,6 @@
-
-T10618.hs:3:22: error:
- Variable not in scope: (<>) :: Maybe (Maybe a0) -> Maybe a1 -> t
- Perhaps you meant one of these:
- ‘<$>’ (imported from Prelude), ‘*>’ (imported from Prelude),
- ‘<$’ (imported from Prelude)
+
+T10618.hs:3:22: error:
+ • Variable not in scope: (<>) :: Maybe (Maybe a0) -> Maybe a1 -> t
+ • Perhaps you meant one of these:
+ ‘<$>’ (imported from Prelude), ‘*>’ (imported from Prelude),
+ ‘<$’ (imported from Prelude)
diff --git a/testsuite/tests/rename/should_fail/T2993.stderr b/testsuite/tests/rename/should_fail/T2993.stderr
index 257e9d434b..4cae65ae88 100644
--- a/testsuite/tests/rename/should_fail/T2993.stderr
+++ b/testsuite/tests/rename/should_fail/T2993.stderr
@@ -1,4 +1,4 @@
T2993.hs:7:13: error:
- Variable not in scope: (<**>) :: t -> (a -> a) -> t1
- Perhaps you meant ‘<*>’ (imported from Prelude)
+ • Variable not in scope: (<**>) :: t -> (b -> b) -> t1
+ • Perhaps you meant ‘<*>’ (imported from Prelude)
diff --git a/testsuite/tests/rename/should_fail/T7937.stderr b/testsuite/tests/rename/should_fail/T7937.stderr
index 8a5edd37c7..7a65b0c06e 100644
--- a/testsuite/tests/rename/should_fail/T7937.stderr
+++ b/testsuite/tests/rename/should_fail/T7937.stderr
@@ -1,4 +1,4 @@
-
-T7937.hs:8:13: error:
- Variable not in scope: (***) :: Bool -> Bool -> t
- Perhaps you meant ‘**’ (imported from Prelude)
+
+T7937.hs:8:13: error:
+ • Variable not in scope: (***) :: Bool -> Bool -> t
+ • Perhaps you meant ‘**’ (imported from Prelude)
diff --git a/testsuite/tests/rename/should_fail/mc13.stderr b/testsuite/tests/rename/should_fail/mc13.stderr
index d4bc26b389..e55f179a46 100644
--- a/testsuite/tests/rename/should_fail/mc13.stderr
+++ b/testsuite/tests/rename/should_fail/mc13.stderr
@@ -1,2 +1,2 @@
-
-mc13.hs:12:37: error: Variable not in scope: f :: [a] -> m a
+
+mc13.hs:12:37: error: Variable not in scope: f :: [a] -> m a
diff --git a/testsuite/tests/rename/should_fail/rnfail016.stderr b/testsuite/tests/rename/should_fail/rnfail016.stderr
index eeeddfa58c..2193ffb068 100644
--- a/testsuite/tests/rename/should_fail/rnfail016.stderr
+++ b/testsuite/tests/rename/should_fail/rnfail016.stderr
@@ -1,4 +1,8 @@
-rnfail016.hs:6:7: Pattern syntax in expression context: x@x
+rnfail016.hs:6:7: error:
+ Pattern syntax in expression context: x@x
+ Did you mean to enable TypeApplications?
-rnfail016.hs:7:7: Pattern syntax in expression context: ~x
+rnfail016.hs:7:7: error:
+ Pattern syntax in expression context: ~x
+ Did you mean to enable TypeApplications?
diff --git a/testsuite/tests/rename/should_fail/rnfail051.stderr b/testsuite/tests/rename/should_fail/rnfail051.stderr
index 36eccc5724..a06ddc5265 100644
--- a/testsuite/tests/rename/should_fail/rnfail051.stderr
+++ b/testsuite/tests/rename/should_fail/rnfail051.stderr
@@ -1,3 +1,4 @@
-rnfail051.hs:7:17:
+rnfail051.hs:7:17: error:
Pattern syntax in expression context: _ -> putStrLn "_"
+ Did you mean to enable TypeApplications?
diff --git a/testsuite/tests/roles/should_compile/Roles1.stderr b/testsuite/tests/roles/should_compile/Roles1.stderr
index 581b043286..ef67f90d8b 100644
--- a/testsuite/tests/roles/should_compile/Roles1.stderr
+++ b/testsuite/tests/roles/should_compile/Roles1.stderr
@@ -15,10 +15,10 @@ TYPE CONSTRUCTORS
Kind: * -> *
type role T6 phantom
data T6 (a :: k) = K6
- Kind: forall k1. k1 -> *
+ Kind: forall {k1}. k1 -> *
type role T7 phantom representational
data T7 (a :: k) b = K7 b
- Kind: forall k1. k1 -> * -> *
+ Kind: forall {k1}. k1 -> * -> *
COERCION AXIOMS
Dependent modules: []
Dependent packages: [base-4.9.0.0, ghc-prim-0.5.0.0,
@@ -27,46 +27,88 @@ Dependent packages: [base-4.9.0.0, ghc-prim-0.5.0.0,
==================== Typechecker ====================
Roles1.$tcT7
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "T7"#)
+ 12795488517584970699##
+ 6852268802866176810##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "T7"#)
Roles1.$tc'K7
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "'K7"#)
+ 12022030613939361326##
+ 11727141136040515167##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "'K7"#)
Roles1.$tcT6
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "T6"#)
+ 1052116432298682626##
+ 4782516991847719023##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "T6"#)
Roles1.$tc'K6
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "'K6"#)
+ 14383224451764499060##
+ 13586832700239872984##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "'K6"#)
Roles1.$tcT5
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "T5"#)
+ 10855726709479635304##
+ 5574528370049939204##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "T5"#)
Roles1.$tc'K5
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "'K5"#)
+ 17986294396600628264##
+ 15784122741796850983##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "'K5"#)
Roles1.$tcT4
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "T4"#)
+ 5809060867006837344##
+ 8795972313583150301##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "T4"#)
Roles1.$tc'K4
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "'K4"#)
+ 6498964159768283182##
+ 956453098475971212##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "'K4"#)
Roles1.$tcT3
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "T3"#)
+ 17827258502042208248##
+ 10404219359416482652##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "T3"#)
Roles1.$tc'K3
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "'K3"#)
+ 18386915834109553575##
+ 773967725306507064##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "'K3"#)
Roles1.$tcT2
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "T2"#)
+ 14324923875690440398##
+ 17626224477681351106##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "T2"#)
Roles1.$tc'K2
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "'K2"#)
+ 17795591238510508397##
+ 10155757471958311507##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "'K2"#)
Roles1.$tcT1
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "T1"#)
+ 12633763300352597178##
+ 11103726621424210926##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "T1"#)
Roles1.$tc'K1
= GHC.Types.TyCon
- 0## 0## Roles1.$trModule (GHC.Types.TrNameS "'K1"#)
+ 1949157551035372857##
+ 3576433963139282451##
+ Roles1.$trModule
+ (GHC.Types.TrNameS "'K1"#)
Roles1.$trModule
= GHC.Types.Module
(GHC.Types.TrNameS "main"#) (GHC.Types.TrNameS "Roles1"#)
diff --git a/testsuite/tests/roles/should_compile/T8958.stderr b/testsuite/tests/roles/should_compile/T8958.stderr
index 40633142f0..ba97e8a45f 100644
--- a/testsuite/tests/roles/should_compile/T8958.stderr
+++ b/testsuite/tests/roles/should_compile/T8958.stderr
@@ -44,6 +44,7 @@ T8958.$trModule
(GHC.Types.TrNameS "main"#) (GHC.Types.TrNameS "T8958"#)
AbsBinds [a] []
{Exports: [T8958.$fRepresentationala <= $dRepresentational
+ <>
<>]
Exported types: T8958.$fRepresentationala
:: forall a. Representational a
@@ -52,6 +53,7 @@ AbsBinds [a] []
Evidence: [EvBinds{}]}
AbsBinds [a] []
{Exports: [T8958.$fNominala <= $dNominal
+ <>
<>]
Exported types: T8958.$fNominala :: forall a. Nominal a
[LclIdX[DFunId], Str=DmdType]
diff --git a/testsuite/tests/rts/T9045.hs b/testsuite/tests/rts/T9045.hs
index f01bf84e38..abd236d985 100644
--- a/testsuite/tests/rts/T9045.hs
+++ b/testsuite/tests/rts/T9045.hs
@@ -15,7 +15,7 @@ main :: IO ()
main = do
hSetBuffering stdout NoBuffering
[nthreads] <- fmap (map read) getArgs
- tids <- replicateM nthreads . mask $ \_ -> forkIO $ return ()
+ tids <- replicateM nthreads (mask $ \_ -> forkIO $ return ())
m <- newEmptyMVar
-- do it in a subthread to avoid bound-thread overhead
forkIO $ do mapM_ killThread tids; putMVar m ()
diff --git a/testsuite/tests/safeHaskell/ghci/p16.stderr b/testsuite/tests/safeHaskell/ghci/p16.stderr
index 893cf2d8ee..4b445166d2 100644
--- a/testsuite/tests/safeHaskell/ghci/p16.stderr
+++ b/testsuite/tests/safeHaskell/ghci/p16.stderr
@@ -3,13 +3,13 @@
-XGeneralizedNewtypeDeriving is not allowed in Safe Haskell; ignoring -XGeneralizedNewtypeDeriving
<interactive>:15:29: error:
- Can't make a derived instance of ‘Op T2’:
- ‘Op’ is not a standard derivable class (Eq, Show, etc.)
- Try GeneralizedNewtypeDeriving for GHC's newtype-deriving extension
- In the newtype declaration for ‘T2’
+ • Can't make a derived instance of ‘Op T2’:
+ ‘Op’ is not a standard derivable class (Eq, Show, etc.)
+ Try GeneralizedNewtypeDeriving for GHC's newtype-deriving extension
+ • In the newtype declaration for ‘T2’
<interactive>:18:9: error:
- Data constructor not in scope: T2 :: T -> t
- Perhaps you meant ‘T1’ (line 12)
+ • Data constructor not in scope: T2 :: T -> t
+ • Perhaps you meant ‘T1’ (line 12)
<interactive>:21:4: error: Variable not in scope: y
diff --git a/testsuite/tests/safeHaskell/ghci/p6.stderr b/testsuite/tests/safeHaskell/ghci/p6.stderr
index 8cca54eb2f..74beb053ca 100644
--- a/testsuite/tests/safeHaskell/ghci/p6.stderr
+++ b/testsuite/tests/safeHaskell/ghci/p6.stderr
@@ -1,10 +1,10 @@
-
-<interactive>:11:1: error:
- Unacceptable result type in foreign declaration:
- Safe Haskell is on, all FFI imports must be in the IO monad
- When checking declaration:
- foreign import ccall safe "static sin" c_sin :: Double -> Double
-
-<interactive>:12:1: error:
- Variable not in scope: c_sin :: Integer -> t
- Perhaps you meant ‘c_sin'’ (line 7)
+
+<interactive>:11:1: error:
+ • Unacceptable result type in foreign declaration:
+ Safe Haskell is on, all FFI imports must be in the IO monad
+ • When checking declaration:
+ foreign import ccall safe "static sin" c_sin :: Double -> Double
+
+<interactive>:12:1: error:
+ • Variable not in scope: c_sin :: Integer -> t
+ • Perhaps you meant ‘c_sin'’ (line 7)
diff --git a/testsuite/tests/simplCore/should_compile/T7360.stderr b/testsuite/tests/simplCore/should_compile/T7360.stderr
index 9ded9c1349..ca398ec6dc 100644
--- a/testsuite/tests/simplCore/should_compile/T7360.stderr
+++ b/testsuite/tests/simplCore/should_compile/T7360.stderr
@@ -66,7 +66,11 @@ T7360.$tc'Foo3 :: GHC.Types.TyCon
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 50}]
T7360.$tc'Foo3 =
- GHC.Types.TyCon 0## 0## T7360.$trModule T7360.$tc'Foo6
+ GHC.Types.TyCon
+ 10507205234936349519##
+ 8302184214013227554##
+ T7360.$trModule
+ T7360.$tc'Foo6
-- RHS size: {terms: 2, types: 0, coercions: 0}
T7360.$tc'Foo5 :: GHC.Types.TrName
@@ -85,7 +89,11 @@ T7360.$tc'Foo2 :: GHC.Types.TyCon
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 50}]
T7360.$tc'Foo2 =
- GHC.Types.TyCon 0## 0## T7360.$trModule T7360.$tc'Foo5
+ GHC.Types.TyCon
+ 9825259700232563546##
+ 11056638024476048052##
+ T7360.$trModule
+ T7360.$tc'Foo5
-- RHS size: {terms: 2, types: 0, coercions: 0}
T7360.$tc'Foo4 :: GHC.Types.TrName
@@ -104,7 +112,11 @@ T7360.$tc'Foo1 :: GHC.Types.TyCon
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 50}]
T7360.$tc'Foo1 =
- GHC.Types.TyCon 0## 0## T7360.$trModule T7360.$tc'Foo4
+ GHC.Types.TyCon
+ 2058692068419561651##
+ 9152017373001677943##
+ T7360.$trModule
+ T7360.$tc'Foo4
-- RHS size: {terms: 2, types: 0, coercions: 0}
T7360.$tcFoo1 :: GHC.Types.TrName
@@ -123,7 +135,11 @@ T7360.$tcFoo :: GHC.Types.TyCon
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 50}]
T7360.$tcFoo =
- GHC.Types.TyCon 0## 0## T7360.$trModule T7360.$tcFoo1
+ GHC.Types.TyCon
+ 8358641983981300860##
+ 582034888424804490##
+ T7360.$trModule
+ T7360.$tcFoo1
-- RHS size: {terms: 5, types: 2, coercions: 0}
fun1 [InlPrag=NOINLINE] :: Foo -> ()
diff --git a/testsuite/tests/simplCore/should_compile/simpl017.stderr b/testsuite/tests/simplCore/should_compile/simpl017.stderr
index 2d3c16ef71..bb74213dfe 100644
--- a/testsuite/tests/simplCore/should_compile/simpl017.stderr
+++ b/testsuite/tests/simplCore/should_compile/simpl017.stderr
@@ -1,38 +1,22 @@
-simpl017.hs:55:12:
- Couldn't match expected type ‘forall v. [E m i] -> E' v m a’
- with actual type ‘[E m i] -> E' v0 m a’
- In the first argument of ‘return’, namely ‘f’
- In a stmt of a 'do' block: return f
- Relevant bindings include
- f :: [E m i] -> E' v0 m a (bound at simpl017.hs:54:9)
- ix :: [E m i] -> m i (bound at simpl017.hs:52:9)
- a :: arr i a (bound at simpl017.hs:50:11)
- liftArray :: arr i a -> E m (forall v. [E m i] -> E' v m a)
- (bound at simpl017.hs:50:1)
-
-simpl017.hs:74:5:
- Couldn't match expected type ‘[E (ST t0) Int] -> E (ST s) Int’
- with actual type ‘forall v. [E (ST s) Int] -> E' v (ST s) Int’
- The function ‘a’ is applied to one argument,
- but its type ‘forall v. [E (ST s) Int] -> E' v (ST s) Int’ has none
- In the first argument of ‘plus’, namely ‘a [one]’
- In a stmt of a 'do' block: a [one] `plus` a [one]
- Relevant bindings include
- a :: forall v. [E (ST s) Int] -> E' v (ST s) Int
- (bound at simpl017.hs:71:5)
- ma :: STArray s Int Int (bound at simpl017.hs:70:5)
- foo :: STArray s Int Int -> ST s Int (bound at simpl017.hs:70:1)
-
-simpl017.hs:74:19:
- Couldn't match expected type ‘[E (ST t1) Int] -> E (ST s) Int’
- with actual type ‘forall v. [E (ST s) Int] -> E' v (ST s) Int’
- The function ‘a’ is applied to one argument,
- but its type ‘forall v. [E (ST s) Int] -> E' v (ST s) Int’ has none
- In the second argument of ‘plus’, namely ‘a [one]’
- In a stmt of a 'do' block: a [one] `plus` a [one]
- Relevant bindings include
- a :: forall v. [E (ST s) Int] -> E' v (ST s) Int
- (bound at simpl017.hs:71:5)
- ma :: STArray s Int Int (bound at simpl017.hs:70:5)
- foo :: STArray s Int Int -> ST s Int (bound at simpl017.hs:70:1)
+simpl017.hs:50:15: error:
+ • Couldn't match type ‘[E m i] -> E' v0 m a’
+ with ‘forall v. [E m i] -> E' v m a’
+ Expected type: E m (forall v. [E m i] -> E' v m a)
+ Actual type: E' RValue m ([E m i] -> E' v0 m a)
+ • In the expression:
+ E (do { let ix :: [E m i] -> m i
+ ix [i] = runE i
+ {-# INLINE f #-}
+ ....;
+ return f })
+ In an equation for ‘liftArray’:
+ liftArray a
+ = E (do { let ix :: [E m i] -> m i
+ ix [i] = runE i
+ ....;
+ return f })
+ • Relevant bindings include
+ a :: arr i a (bound at simpl017.hs:50:11)
+ liftArray :: arr i a -> E m (forall v. [E m i] -> E' v m a)
+ (bound at simpl017.hs:50:1)
diff --git a/testsuite/tests/th/T10945.stderr b/testsuite/tests/th/T10945.stderr
index 0c1d949053..c84fa38b61 100644
--- a/testsuite/tests/th/T10945.stderr
+++ b/testsuite/tests/th/T10945.stderr
@@ -1,29 +1,32 @@
-T10945.hs:7:11:
- Couldn't match expected type ‘TExp DecsQ’ with actual type ‘[Dec]’
- In the first argument of ‘return’, namely
- ‘[SigD
- (mkName "m")
- (ForallT
- [PlainTV (mkName "a")]
- []
- (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))),
- FunD (mkName "m") [Clause [...] (NormalB (VarE (mkName "x"))) []]]’
- In the expression:
- return
- [SigD
- (mkName "m")
- (ForallT
- [PlainTV (mkName "a")]
- []
- (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))),
- FunD (mkName "m") [Clause [...] (NormalB (VarE (mkName "x"))) []]]
- In the Template Haskell splice
- $$(return
- [SigD
- (mkName "m")
- (ForallT
- [PlainTV (mkName "a")]
- []
- (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))),
- FunD (mkName "m") [Clause [...] (NormalB (VarE (mkName "x"))) []]])
+T10945.hs:7:4: error:
+ • Couldn't match type ‘[Dec]’ with ‘TExp DecsQ’
+ Expected type: Q (TExp DecsQ)
+ Actual type: Q [Dec]
+ • In the expression:
+ return
+ [SigD
+ (mkName "m")
+ (ForallT
+ [PlainTV (mkName "a")]
+ []
+ (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))),
+ FunD (mkName "m") [Clause [...] (NormalB (VarE (mkName "x"))) []]]
+ In the Template Haskell splice
+ $$(return
+ [SigD
+ (mkName "m")
+ (ForallT
+ [PlainTV (mkName "a")]
+ []
+ (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))),
+ FunD (mkName "m") [Clause [...] (NormalB (VarE (mkName "x"))) []]])
+ In the expression:
+ $$(return
+ [SigD
+ (mkName "m")
+ (ForallT
+ [PlainTV (mkName "a")]
+ []
+ (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))),
+ FunD (mkName "m") [Clause ... (NormalB (VarE (mkName "x"))) ...]])
diff --git a/testsuite/tests/th/T8577.stderr b/testsuite/tests/th/T8577.stderr
index 734007e6cc..ef95cc313d 100644
--- a/testsuite/tests/th/T8577.stderr
+++ b/testsuite/tests/th/T8577.stderr
@@ -1,7 +1,8 @@
-T8577.hs:9:11:
+T8577.hs:9:11: error:
Couldn't match type ‘Int’ with ‘Bool’
Expected type: Q (TExp (A Bool))
Actual type: Q (TExp (A Int))
In the expression: y
In the Template Haskell splice $$y
+ In the expression: $$y
diff --git a/testsuite/tests/typecheck/bug1465/bug1465.stderr b/testsuite/tests/typecheck/bug1465/bug1465.stderr
index 1c67068762..4e31c7f195 100644
--- a/testsuite/tests/typecheck/bug1465/bug1465.stderr
+++ b/testsuite/tests/typecheck/bug1465/bug1465.stderr
@@ -6,3 +6,4 @@ C.hs:6:11: error:
‘bug1465-1.0:A.T’ is defined in ‘A’ in package ‘bug1465-1.0’
In the expression: B2.f
In the expression: [B1.f, B2.f]
+ In an equation for ‘x’: x = [B1.f, B2.f]
diff --git a/testsuite/tests/typecheck/should_compile/FD1.stderr b/testsuite/tests/typecheck/should_compile/FD1.stderr
index 19d698294a..395217af8b 100644
--- a/testsuite/tests/typecheck/should_compile/FD1.stderr
+++ b/testsuite/tests/typecheck/should_compile/FD1.stderr
@@ -1,6 +1,6 @@
FD1.hs:16:1: error:
- • Couldn't match expected type ‘Int -> Int’ with actual type ‘a’
+ • Couldn't match expected type ‘a’ with actual type ‘Int -> Int’
‘a’ is a rigid type variable bound by
the type signature for:
plus :: forall a. E a (Int -> Int) => Int -> a
diff --git a/testsuite/tests/typecheck/should_compile/FD2.stderr b/testsuite/tests/typecheck/should_compile/FD2.stderr
index 93997c52ec..ff3a923988 100644
--- a/testsuite/tests/typecheck/should_compile/FD2.stderr
+++ b/testsuite/tests/typecheck/should_compile/FD2.stderr
@@ -1,15 +1,16 @@
-FD2.hs:26:34: error:
- • Couldn't match expected type ‘e1’ with actual type ‘e’
- ‘e’ is a rigid type variable bound by
- the type signature for:
- foldr1 :: forall e. Elem a e => (e -> e -> e) -> a -> e
- at FD2.hs:21:13
+FD2.hs:26:36: error:
+ • Couldn't match expected type ‘e’ with actual type ‘e1’
‘e1’ is a rigid type variable bound by
the type signature for:
mf :: forall e1. Elem a e1 => e1 -> Maybe e1 -> Maybe e1
at FD2.hs:24:18
- • In the first argument of ‘Just’, namely ‘(f x y)’
+ ‘e’ is a rigid type variable bound by
+ the type signature for:
+ foldr1 :: forall e. Elem a e => (e -> e -> e) -> a -> e
+ at FD2.hs:21:13
+ • In the first argument of ‘f’, namely ‘x’
+ In the first argument of ‘Just’, namely ‘(f x y)’
In the expression: Just (f x y)
• Relevant bindings include
y :: e1 (bound at FD2.hs:26:23)
diff --git a/testsuite/tests/typecheck/should_compile/PushHRIf.hs b/testsuite/tests/typecheck/should_compile/PushHRIf.hs
new file mode 100644
index 0000000000..f6839133a0
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/PushHRIf.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE RankNTypes #-}
+
+module PushHRIf where
+
+foo = (if True then id else id) :: forall a. a -> a
+
+bar = (foo 'x', foo True)
diff --git a/testsuite/tests/typecheck/should_compile/T10072.stderr b/testsuite/tests/typecheck/should_compile/T10072.stderr
index ba15398874..eb14ad8de5 100644
--- a/testsuite/tests/typecheck/should_compile/T10072.stderr
+++ b/testsuite/tests/typecheck/should_compile/T10072.stderr
@@ -1,8 +1,8 @@
-
-T10072.hs:3:31: error:
- Found type wildcard ‘_’ standing for ‘b’
- Where: ‘b’ is a rigid type variable bound by
- the RULE "map/empty" at T10072.hs:3:1
- To use the inferred type, enable PartialTypeSignatures
- In a RULE for ‘f’: a -> _
- When checking the transformation rule "map/empty"
+
+T10072.hs:3:31: error:
+ • Found type wildcard ‘_’ standing for ‘b’
+ Where: ‘b’ is a rigid type variable bound by
+ the RULE "map/empty" at T10072.hs:3:1
+ To use the inferred type, enable PartialTypeSignatures
+ • In a RULE for ‘f’: a -> _
+ When checking the transformation rule "map/empty"
diff --git a/testsuite/tests/typecheck/should_compile/T10971a.stderr b/testsuite/tests/typecheck/should_compile/T10971a.stderr
index 7ca7680c52..eea8a11ea3 100644
--- a/testsuite/tests/typecheck/should_compile/T10971a.stderr
+++ b/testsuite/tests/typecheck/should_compile/T10971a.stderr
@@ -34,9 +34,9 @@ T10971a.hs:9:6: warning:
T10971a.hs:9:31: warning:
• Defaulting the following constraints to type ‘[]’
- (Foldable t0) arising from a use of ‘length’ at T10971a.hs:9:31-36
+ (Foldable t0) arising from a use of ‘length’ at T10971a.hs:9:31-38
(Traversable t0)
- arising from a use of ‘fmapDefault’ at T10971a.hs:9:14-24
+ arising from a use of ‘fmapDefault’ at T10971a.hs:9:14-28
• In the expression: length x
In the expression: (fmapDefault f x, length x)
In the expression: \ f x -> (fmapDefault f x, length x)
diff --git a/testsuite/tests/typecheck/should_compile/T2494.stderr b/testsuite/tests/typecheck/should_compile/T2494.stderr
index 71351cba0a..b398459aa9 100644
--- a/testsuite/tests/typecheck/should_compile/T2494.stderr
+++ b/testsuite/tests/typecheck/should_compile/T2494.stderr
@@ -1,34 +1,36 @@
-T2494.hs:15:14:
- Couldn't match type ‘b’ with ‘a’
+T2494.hs:15:14: error:
+ • Couldn't match type ‘b’ with ‘a’
‘b’ is a rigid type variable bound by
- the RULE "foo/foo" at T2494.hs:14:16
+ the RULE "foo/foo" at T2494.hs:14:16
‘a’ is a rigid type variable bound by
- the RULE "foo/foo" at T2494.hs:13:16
- Expected type: Maybe (m a) -> Maybe (m a)
- Actual type: Maybe (m b) -> Maybe (m b)
- In the first argument of ‘foo’, namely ‘g’
- In the second argument of ‘foo’, namely ‘(foo g x)’
- Relevant bindings include
- f :: forall (m :: * -> *). Monad m => Maybe (m a) -> Maybe (m a)
- (bound at T2494.hs:13:11)
- g :: forall (m :: * -> *). Monad m => Maybe (m b) -> Maybe (m b)
- (bound at T2494.hs:14:11)
- x :: Maybe a (bound at T2494.hs:14:65)
+ the RULE "foo/foo" at T2494.hs:13:16
+ Expected type: Maybe (m a) -> Maybe (m a)
+ Actual type: Maybe (m b) -> Maybe (m b)
+ • In the first argument of ‘foo’, namely ‘g’
+ In the second argument of ‘foo’, namely ‘(foo g x)’
+ In the expression: foo f (foo g x)
+ • Relevant bindings include
+ f :: forall (m :: * -> *). Monad m => Maybe (m a) -> Maybe (m a)
+ (bound at T2494.hs:13:11)
+ g :: forall (m :: * -> *). Monad m => Maybe (m b) -> Maybe (m b)
+ (bound at T2494.hs:14:11)
+ x :: Maybe a (bound at T2494.hs:14:65)
-T2494.hs:15:30:
- Couldn't match type ‘b’ with ‘a’
+T2494.hs:15:30: error:
+ • Couldn't match type ‘b’ with ‘a’
‘b’ is a rigid type variable bound by
- the RULE "foo/foo" at T2494.hs:14:16
+ the RULE "foo/foo" at T2494.hs:14:16
‘a’ is a rigid type variable bound by
- the RULE "foo/foo" at T2494.hs:13:16
- Expected type: Maybe (m a) -> Maybe (m a)
- Actual type: Maybe (m b) -> Maybe (m b)
- In the second argument of ‘(.)’, namely ‘g’
- In the first argument of ‘foo’, namely ‘(f . g)’
- Relevant bindings include
- f :: forall (m :: * -> *). Monad m => Maybe (m a) -> Maybe (m a)
- (bound at T2494.hs:13:11)
- g :: forall (m :: * -> *). Monad m => Maybe (m b) -> Maybe (m b)
- (bound at T2494.hs:14:11)
- x :: Maybe a (bound at T2494.hs:14:65)
+ the RULE "foo/foo" at T2494.hs:13:16
+ Expected type: Maybe (m b) -> Maybe (m a)
+ Actual type: Maybe (m b) -> Maybe (m b)
+ • In the second argument of ‘(.)’, namely ‘g’
+ In the first argument of ‘foo’, namely ‘(f . g)’
+ In the expression: foo (f . g) x
+ • Relevant bindings include
+ f :: forall (m :: * -> *). Monad m => Maybe (m a) -> Maybe (m a)
+ (bound at T2494.hs:13:11)
+ g :: forall (m :: * -> *). Monad m => Maybe (m b) -> Maybe (m b)
+ (bound at T2494.hs:14:11)
+ x :: Maybe a (bound at T2494.hs:14:65)
diff --git a/testsuite/tests/typecheck/should_compile/Vta1.hs b/testsuite/tests/typecheck/should_compile/Vta1.hs
new file mode 100644
index 0000000000..c3ba43de54
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/Vta1.hs
@@ -0,0 +1,95 @@
+{-# LANGUAGE TypeApplications, ScopedTypeVariables, PolyKinds,
+ TypeFamilies, RankNTypes,
+ FlexibleContexts #-}
+-- tests about visible type application
+
+module Vta1 where
+
+quad :: a -> b -> c -> d -> (a, b, c, d)
+quad = (,,,)
+
+silly = quad @_ @Bool @Char @_ 5 True 'a' "Hello"
+
+pairup_nosig x y = (x, y)
+
+pairup_sig :: a -> b -> (a,b)
+pairup_sig u w = (u, w)
+
+answer_sig = pairup_sig @Bool @Int False 7 --
+-- (False, 7) :: (Bool, Int)
+
+answer_read = show (read @Int "3") -- "3" :: String
+answer_show = show @Integer (read "5") -- "5" :: String
+answer_showread = show @Int (read @Int "7") -- "7" :: String
+
+intcons a = (:) @Int a
+
+intpair x y = pairup_sig @Int x y
+
+answer_pairup = pairup_sig @Int 5 True -- (5, True) :: (Int, Bool)
+answer_intpair = intpair 1 "hello" -- (1, "hello") :: (Int, String)
+answer_intcons = intcons 7 [] -- [7] :: [Int]
+
+type family F a
+type instance F Char = Bool
+
+g :: F a -> a
+g _ = undefined
+
+f :: Char
+f = g True
+
+answer = g @Char False
+
+mapSame :: forall b. (forall a. a -> a) -> [b] -> [b]
+mapSame _ [] = []
+mapSame fun (x:xs) = fun @b x : (mapSame @b fun xs)
+
+pair :: forall a. a-> (forall b. b -> (a, b))
+pair x y = (x, y)
+
+b = pair @Int 3 @Bool True
+c = mapSame id [1,2,3]
+d = pair 3 @Bool True
+
+pairnum :: forall a. Num a => forall b. b -> (a, b)
+pairnum = pair 3
+
+e = (pair 3 :: forall a. Num a => forall b. b -> (a, b)) @Int @Bool True
+h = pairnum @Int @Bool True
+
+data First (a :: * -> *) = F
+data Proxy (a :: k) = P -- This expands to P (kind variable) (type variable)
+data Three (a :: * -> k -> *) = T
+
+foo :: Proxy a -> Int
+foo _ = 0
+
+first :: First a -> Int
+first _ = 0
+
+fTest = first F
+fMaybe = first @Maybe F
+
+test = foo P
+bar = foo @Bool P -- should work
+
+too :: Three a -> Int
+too _ = 3
+
+threeBase = too T
+threeOk = too @Either T
+
+blah = Nothing @Int
+
+newtype N = MkN { unMkN :: forall a. Show a => a -> String }
+
+n = MkN show
+
+boo = unMkN n @Bool
+
+boo2 :: forall (a :: * -> *) . Proxy a -> Bool
+boo2 _ = False
+
+base = boo2 P
+bar'= boo2 @Maybe P -- should work
diff --git a/testsuite/tests/typecheck/should_compile/Vta2.hs b/testsuite/tests/typecheck/should_compile/Vta2.hs
new file mode 100644
index 0000000000..2851b06469
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/Vta2.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE RankNTypes, TypeApplications #-}
+
+
+module Vta2 where
+
+checkIf :: Bool -> (forall a. a -> a) -> (Bool, Int)
+checkIf _ = if True
+ then \f -> (f True, f 5)
+ else \f -> (f False, f @Int 3)
+
+checkCase :: Bool -> (forall a. a -> a) -> (Bool, Int)
+checkCase _ = case True of
+ True -> \f -> (f True, f 5)
+ False -> \f -> (f False, f @Int 3)
diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T
index a969a4c6ac..8002299fb1 100644
--- a/testsuite/tests/typecheck/should_compile/all.T
+++ b/testsuite/tests/typecheck/should_compile/all.T
@@ -471,6 +471,9 @@ test('T10428', normal, compile, [''])
test('RepArrow', normal, compile, [''])
test('T10562', normal, compile, [''])
test('T10564', normal, compile, [''])
+test('Vta1', normal, compile, [''])
+test('Vta2', normal, compile, [''])
+test('PushHRIf', normal, compile, [''])
test('T10632', normal, compile, [''])
test('T10642', normal, compile, [''])
test('T10744', normal, compile, [''])
diff --git a/testsuite/tests/typecheck/should_compile/holes.stderr b/testsuite/tests/typecheck/should_compile/holes.stderr
index 5cb341709e..8551f66c3b 100644
--- a/testsuite/tests/typecheck/should_compile/holes.stderr
+++ b/testsuite/tests/typecheck/should_compile/holes.stderr
@@ -1,33 +1,33 @@
-
-holes.hs:3:5: warning:
- Found hole: _ :: t
- Where: ‘t’ is a rigid type variable bound by
- the inferred type of f :: t at holes.hs:3:1
- In the expression: _
- In an equation for ‘f’: f = _
- Relevant bindings include f :: t (bound at holes.hs:3:1)
-
-holes.hs:6:7: warning:
- Found hole: _ :: Char
- In the expression: _
- In an equation for ‘g’: g x = _
- Relevant bindings include
- x :: Int (bound at holes.hs:6:3)
- g :: Int -> Char (bound at holes.hs:6:1)
-
-holes.hs:8:5: warning:
- Found hole: _ :: [Char]
- In the first argument of ‘(++)’, namely ‘_’
- In the expression: _ ++ "a"
- In an equation for ‘h’: h = _ ++ "a"
- Relevant bindings include h :: [Char] (bound at holes.hs:8:1)
-
-holes.hs:11:15: warning:
- Found hole: _ :: b0
- Where: ‘b0’ is an ambiguous type variable
- In the second argument of ‘const’, namely ‘_’
- In the expression: const y _
- In an equation for ‘z’: z y = const y _
- Relevant bindings include
- y :: [a] (bound at holes.hs:11:3)
- z :: [a] -> [a] (bound at holes.hs:11:1)
+
+holes.hs:3:5: warning:
+ • Found hole: _ :: t
+ Where: ‘t’ is a rigid type variable bound by
+ the inferred type of f :: t at holes.hs:3:1
+ • In the expression: _
+ In an equation for ‘f’: f = _
+ • Relevant bindings include f :: t (bound at holes.hs:3:1)
+
+holes.hs:6:7: warning:
+ • Found hole: _ :: Char
+ • In the expression: _
+ In an equation for ‘g’: g x = _
+ • Relevant bindings include
+ x :: Int (bound at holes.hs:6:3)
+ g :: Int -> Char (bound at holes.hs:6:1)
+
+holes.hs:8:5: warning:
+ • Found hole: _ :: [Char]
+ • In the first argument of ‘(++)’, namely ‘_’
+ In the expression: _ ++ "a"
+ In an equation for ‘h’: h = _ ++ "a"
+ • Relevant bindings include h :: [Char] (bound at holes.hs:8:1)
+
+holes.hs:11:15: warning:
+ • Found hole: _ :: b0
+ Where: ‘b0’ is an ambiguous type variable
+ • In the second argument of ‘const’, namely ‘_’
+ In the expression: const y _
+ In an equation for ‘z’: z y = const y _
+ • Relevant bindings include
+ y :: [a] (bound at holes.hs:11:3)
+ z :: [a] -> [a] (bound at holes.hs:11:1)
diff --git a/testsuite/tests/typecheck/should_compile/holes3.stderr b/testsuite/tests/typecheck/should_compile/holes3.stderr
index a6e7c6194e..2d1261b278 100644
--- a/testsuite/tests/typecheck/should_compile/holes3.stderr
+++ b/testsuite/tests/typecheck/should_compile/holes3.stderr
@@ -1,36 +1,36 @@
-
-holes3.hs:3:5: error:
- Found hole: _ :: t
- Where: ‘t’ is a rigid type variable bound by
- the inferred type of f :: t at holes3.hs:3:1
- In the expression: _
- In an equation for ‘f’: f = _
- Relevant bindings include f :: t (bound at holes3.hs:3:1)
-
-holes3.hs:6:7: error:
- Found hole: _gr :: Char
- Or perhaps ‘_gr’ is mis-spelled, or not in scope
- In the expression: _gr
- In an equation for ‘g’: g x = _gr
- Relevant bindings include
- x :: Int (bound at holes3.hs:6:3)
- g :: Int -> Char (bound at holes3.hs:6:1)
-
-holes3.hs:8:5: error:
- Found hole: _aa :: [Char]
- Or perhaps ‘_aa’ is mis-spelled, or not in scope
- In the first argument of ‘(++)’, namely ‘_aa’
- In the expression: _aa ++ "a"
- In an equation for ‘h’: h = _aa ++ "a"
- Relevant bindings include h :: [Char] (bound at holes3.hs:8:1)
-
-holes3.hs:11:15: error:
- Found hole: _x :: b0
- Where: ‘b0’ is an ambiguous type variable
- Or perhaps ‘_x’ is mis-spelled, or not in scope
- In the second argument of ‘const’, namely ‘_x’
- In the expression: const y _x
- In an equation for ‘z’: z y = const y _x
- Relevant bindings include
- y :: [a] (bound at holes3.hs:11:3)
- z :: [a] -> [a] (bound at holes3.hs:11:1)
+
+holes3.hs:3:5: error:
+ • Found hole: _ :: t
+ Where: ‘t’ is a rigid type variable bound by
+ the inferred type of f :: t at holes3.hs:3:1
+ • In the expression: _
+ In an equation for ‘f’: f = _
+ • Relevant bindings include f :: t (bound at holes3.hs:3:1)
+
+holes3.hs:6:7: error:
+ • Found hole: _gr :: Char
+ Or perhaps ‘_gr’ is mis-spelled, or not in scope
+ • In the expression: _gr
+ In an equation for ‘g’: g x = _gr
+ • Relevant bindings include
+ x :: Int (bound at holes3.hs:6:3)
+ g :: Int -> Char (bound at holes3.hs:6:1)
+
+holes3.hs:8:5: error:
+ • Found hole: _aa :: [Char]
+ Or perhaps ‘_aa’ is mis-spelled, or not in scope
+ • In the first argument of ‘(++)’, namely ‘_aa’
+ In the expression: _aa ++ "a"
+ In an equation for ‘h’: h = _aa ++ "a"
+ • Relevant bindings include h :: [Char] (bound at holes3.hs:8:1)
+
+holes3.hs:11:15: error:
+ • Found hole: _x :: b0
+ Where: ‘b0’ is an ambiguous type variable
+ Or perhaps ‘_x’ is mis-spelled, or not in scope
+ • In the second argument of ‘const’, namely ‘_x’
+ In the expression: const y _x
+ In an equation for ‘z’: z y = const y _x
+ • Relevant bindings include
+ y :: [a] (bound at holes3.hs:11:3)
+ z :: [a] -> [a] (bound at holes3.hs:11:1)
diff --git a/testsuite/tests/typecheck/should_compile/tc141.stderr b/testsuite/tests/typecheck/should_compile/tc141.stderr
index 96858b1d3c..e0de74c945 100644
--- a/testsuite/tests/typecheck/should_compile/tc141.stderr
+++ b/testsuite/tests/typecheck/should_compile/tc141.stderr
@@ -7,19 +7,20 @@ tc141.hs:11:12: error:
In a pattern binding: (p :: a, q :: a) = x
tc141.hs:11:31: error:
- • Couldn't match expected type ‘a2’ with actual type ‘a’
- because type variable ‘a2’ would escape its scope
+ • Couldn't match expected type ‘a1’ with actual type ‘a’
+ because type variable ‘a1’ would escape its scope
This (rigid, skolem) type variable is bound by
an expression type signature:
- a2
+ a1
at tc141.hs:11:31-34
• In the expression: q :: a
In the expression: (q :: a, p)
+ In the expression: let (p :: a, q :: a) = x in (q :: a, p)
• Relevant bindings include
p :: a (bound at tc141.hs:11:12)
q :: a (bound at tc141.hs:11:17)
x :: (a, a) (bound at tc141.hs:11:3)
- f :: (a, a) -> (a1, a) (bound at tc141.hs:11:1)
+ f :: (a, a) -> (t, a) (bound at tc141.hs:11:1)
tc141.hs:13:13: error:
• You cannot bind scoped type variable ‘a’
@@ -42,7 +43,12 @@ tc141.hs:15:18: error:
at tc141.hs:14:14-19
• In the expression: b
In an equation for ‘v’: v = b
+ In the expression:
+ let
+ v :: a
+ v = b
+ in v
• Relevant bindings include
v :: a1 (bound at tc141.hs:15:14)
b :: r1 (bound at tc141.hs:13:5)
- g :: r -> r1 -> a (bound at tc141.hs:13:1)
+ g :: r -> r1 -> forall a. a (bound at tc141.hs:13:1)
diff --git a/testsuite/tests/typecheck/should_compile/tc168.stderr b/testsuite/tests/typecheck/should_compile/tc168.stderr
index 7d992a48a0..16ba4b0446 100644
--- a/testsuite/tests/typecheck/should_compile/tc168.stderr
+++ b/testsuite/tests/typecheck/should_compile/tc168.stderr
@@ -1,12 +1,12 @@
-
-tc168.hs:17:1: error:
- Could not deduce (C a1 (a, b0))
- from the context: C a1 (a, b)
- bound by the inferred type for ‘g’:
- C a1 (a, b) => a1 -> a
- at tc168.hs:17:1-16
- The type variable ‘b0’ is ambiguous
- In the ambiguity check for the inferred type for ‘g’
- To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
- When checking the inferred type
- g :: forall a b a1. C a1 (a, b) => a1 -> a
+
+tc168.hs:17:1: error:
+ • Could not deduce (C a1 (a, b0))
+ from the context: C a1 (a, b)
+ bound by the inferred type for ‘g’:
+ C a1 (a, b) => a1 -> a
+ at tc168.hs:17:1-16
+ The type variable ‘b0’ is ambiguous
+ • In the ambiguity check for the inferred type for ‘g’
+ To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
+ When checking the inferred type
+ g :: forall a b a1. C a1 (a, b) => a1 -> a
diff --git a/testsuite/tests/typecheck/should_compile/tc211.stderr b/testsuite/tests/typecheck/should_compile/tc211.stderr
index d802dffe4e..89c82c4f9a 100644
--- a/testsuite/tests/typecheck/should_compile/tc211.stderr
+++ b/testsuite/tests/typecheck/should_compile/tc211.stderr
@@ -1,61 +1,20 @@
-tc211.hs:17:8: error:
- Couldn't match expected type ‘forall a. a -> a’
- with actual type ‘a2 -> a2’
- In the expression:
- (:) ::
- (forall a. a -> a) -> [forall a. a -> a] -> [forall a. a -> a]
- In the expression:
- ((:) ::
- (forall a. a -> a) -> [forall a. a -> a] -> [forall a. a -> a])
- (head foo) foo
-
-tc211.hs:18:22: error:
- Couldn't match type ‘forall a3. a3 -> a3’ with ‘a -> a’
- Expected type: [a -> a]
- Actual type: [forall a. a -> a]
- In the first argument of ‘head’, namely ‘foo’
- In the first argument of ‘(:) ::
- (forall a. a -> a)
- -> [forall a. a -> a] -> [forall a. a -> a]’, namely
- ‘(head foo)’
-
-tc211.hs:59:18: error:
- Couldn't match expected type ‘forall a. a -> a’
- with actual type ‘a1 -> a1’
- In the expression:
- Cons ::
- (forall a. a -> a)
- -> List (forall a. a -> a) -> List (forall a. a -> a)
- In an equation for ‘cons’:
- cons
- = Cons ::
- (forall a. a -> a)
- -> List (forall a. a -> a) -> List (forall a. a -> a)
-
-tc211.hs:65:8: error:
- Couldn't match expected type ‘forall a. a -> a’
- with actual type ‘a0 -> a0’
- In the expression:
- Cons ::
- (forall a. a -> a)
- -> List (forall a. a -> a) -> List (forall a. a -> a)
- In the expression:
- (Cons ::
- (forall a. a -> a)
- -> List (forall a. a -> a) -> List (forall a. a -> a))
- (\ x -> x) Nil
-
tc211.hs:73:9: error:
- Couldn't match type ‘forall a4. a4 -> a4’ with ‘a3 -> a3’
- Expected type: List (forall a. a -> a)
- -> (forall a. a -> a) -> a3 -> a3
- Actual type: List (a3 -> a3) -> (a3 -> a3) -> a3 -> a3
- In the expression:
- foo2 ::
- List (forall a. a -> a) -> (forall a. a -> a) -> (forall a. a -> a)
- In the expression:
- (foo2 ::
- List (forall a. a -> a)
- -> (forall a. a -> a) -> (forall a. a -> a))
- xs1 (\ x -> x)
+ • Couldn't match type ‘forall a2. a2 -> a2’ with ‘a1 -> a1’
+ Expected type: List (forall a. a -> a)
+ -> (forall a. a -> a) -> a1 -> a1
+ Actual type: List (a1 -> a1) -> (a1 -> a1) -> a1 -> a1
+ • In the expression:
+ foo2 ::
+ List (forall a. a -> a) -> (forall a. a -> a) -> (forall a. a -> a)
+ In the expression:
+ (foo2 ::
+ List (forall a. a -> a)
+ -> (forall a. a -> a) -> (forall a. a -> a))
+ xs1 (\ x -> x)
+ In an equation for ‘bar4’:
+ bar4
+ = (foo2 ::
+ List (forall a. a -> a)
+ -> (forall a. a -> a) -> (forall a. a -> a))
+ xs1 (\ x -> x)
diff --git a/testsuite/tests/typecheck/should_compile/tc243.stderr b/testsuite/tests/typecheck/should_compile/tc243.stderr
index 98e0f5ae1e..0219817408 100644
--- a/testsuite/tests/typecheck/should_compile/tc243.stderr
+++ b/testsuite/tests/typecheck/should_compile/tc243.stderr
@@ -1,3 +1,3 @@
-tc243.hs:10:1: Warning:
- Top-level binding with no type signature: (.+.) :: forall r. r
+tc243.hs:10:1: warning:
+ Top-level binding with no type signature: (.+.) :: forall a. a
diff --git a/testsuite/tests/typecheck/should_fail/CustomTypeErrors01.stderr b/testsuite/tests/typecheck/should_fail/CustomTypeErrors01.stderr
index d95de09530..18c45a12c0 100644
--- a/testsuite/tests/typecheck/should_fail/CustomTypeErrors01.stderr
+++ b/testsuite/tests/typecheck/should_fail/CustomTypeErrors01.stderr
@@ -1,5 +1,5 @@
-CustomTypeErrors01.hs:12:11: error:
- Values of type 'MyType' cannot be compared for equality.
- In the expression: x == MyType
- In an equation for ‘err’: err x = x == MyType
+CustomTypeErrors01.hs:12:9: error:
+ • Values of type 'MyType' cannot be compared for equality.
+ • In the expression: x == MyType
+ In an equation for ‘err’: err x = x == MyType
diff --git a/testsuite/tests/typecheck/should_fail/ExpandSynsFail2.stderr b/testsuite/tests/typecheck/should_fail/ExpandSynsFail2.stderr
index 6ded98e0bd..49e262cd3c 100644
--- a/testsuite/tests/typecheck/should_fail/ExpandSynsFail2.stderr
+++ b/testsuite/tests/typecheck/should_fail/ExpandSynsFail2.stderr
@@ -1,9 +1,12 @@
+
ExpandSynsFail2.hs:19:37: error:
- Couldn't match type ‘Int’ with ‘Bool’
- Expected type: ST s Foo
- Actual type: MyBarST s
- Type synonyms expanded:
- Expected type: ST s Int
- Actual type: ST s Bool
- In the first argument of ‘runST’, namely ‘barGen’
- In the second argument of ‘(==)’, namely ‘runST barGen’
+ • Couldn't match type ‘Int’ with ‘Bool’
+ Expected type: ST s Foo
+ Actual type: MyBarST s
+ Type synonyms expanded:
+ Expected type: ST s Int
+ Actual type: ST s Bool
+ • In the first argument of ‘runST’, namely ‘barGen’
+ In the second argument of ‘(==)’, namely ‘runST barGen’
+ In the first argument of ‘print’, namely
+ ‘(runST fooGen == runST barGen)’
diff --git a/testsuite/tests/typecheck/should_fail/T10495.stderr b/testsuite/tests/typecheck/should_fail/T10495.stderr
index ee2060017e..e09e60af23 100644
--- a/testsuite/tests/typecheck/should_fail/T10495.stderr
+++ b/testsuite/tests/typecheck/should_fail/T10495.stderr
@@ -1,7 +1,8 @@
-T10495.hs:5:7: error:
- Couldn't match representation of type ‘a0’ with that of ‘b0’
- arising from a use of ‘coerce’
- In the expression: coerce
- In an equation for ‘foo’: foo = coerce
- Relevant bindings include foo :: a0 -> b0 (bound at T10495.hs:5:1)
+T10495.hs:5:1: error:
+ • Couldn't match representation of type ‘a0’ with that of ‘b0’
+ arising from a use of ‘coerce’
+ • When instantiating ‘foo’, initially inferred to have
+ this overly-general type:
+ forall a b. Coercible a b => a -> b
+ NB: This instantiation can be caused by the monomorphism restriction.
diff --git a/testsuite/tests/typecheck/should_fail/T10971d.stderr b/testsuite/tests/typecheck/should_fail/T10971d.stderr
index 244fff7098..c5ad886683 100644
--- a/testsuite/tests/typecheck/should_fail/T10971d.stderr
+++ b/testsuite/tests/typecheck/should_fail/T10971d.stderr
@@ -1,17 +1,20 @@
T10971d.hs:4:14: error:
- Couldn't match expected type ‘[a0]’
- with actual type ‘Maybe Integer’
- In the first argument of ‘f’, namely ‘(Just 1)’
- In the second argument of ‘($)’, namely ‘f (Just 1)’
+ • Couldn't match expected type ‘[a0]’
+ with actual type ‘Maybe Integer’
+ • In the first argument of ‘f’, namely ‘(Just 1)’
+ In the second argument of ‘($)’, namely ‘f (Just 1)’
+ In a stmt of a 'do' block: print $ f (Just 1)
T10971d.hs:5:19: error:
- Couldn't match expected type ‘[Integer]’
- with actual type ‘Maybe Integer’
- In the second argument of ‘g’, namely ‘(Just 5)’
- In the second argument of ‘($)’, namely ‘g (+ 1) (Just 5)’
+ • Couldn't match expected type ‘[Integer]’
+ with actual type ‘Maybe Integer’
+ • In the second argument of ‘g’, namely ‘(Just 5)’
+ In the second argument of ‘($)’, namely ‘g (+ 1) (Just 5)’
+ In a stmt of a 'do' block: print $ g (+ 1) (Just 5)
T10971d.hs:6:23: error:
- Couldn't match expected type ‘[b0]’ with actual type ‘Maybe a1’
- In the second argument of ‘h’, namely ‘Nothing’
- In the second argument of ‘($)’, namely ‘h (const 5) Nothing’
+ • Couldn't match expected type ‘[b0]’ with actual type ‘Maybe a1’
+ • In the second argument of ‘h’, namely ‘Nothing’
+ In the second argument of ‘($)’, namely ‘h (const 5) Nothing’
+ In a stmt of a 'do' block: print $ h (const 5) Nothing
diff --git a/testsuite/tests/typecheck/should_fail/T11274.stderr b/testsuite/tests/typecheck/should_fail/T11274.stderr
index f73131704a..b6f1964c14 100644
--- a/testsuite/tests/typecheck/should_fail/T11274.stderr
+++ b/testsuite/tests/typecheck/should_fail/T11274.stderr
@@ -1,5 +1,5 @@
-T11274.hs:10:25: error:
+T11274.hs:10:23: error:
• No instance for (Eq Asd) arising from a use of ‘==’
• In the expression: x == y
In an equation for ‘missingInstance’: missingInstance x y = x == y
diff --git a/testsuite/tests/typecheck/should_fail/T1899.stderr b/testsuite/tests/typecheck/should_fail/T1899.stderr
index 8c2964cfc6..c4db8fe1e7 100644
--- a/testsuite/tests/typecheck/should_fail/T1899.stderr
+++ b/testsuite/tests/typecheck/should_fail/T1899.stderr
@@ -9,6 +9,7 @@ T1899.hs:14:36: error:
Actual type: [a]
• In the first argument of ‘Auxiliary’, namely ‘varSet’
In the first argument of ‘Prop’, namely ‘(Auxiliary varSet)’
+ In the expression: Prop (Auxiliary varSet)
• Relevant bindings include
varSet :: [a] (bound at T1899.hs:10:11)
transRHS :: [a] -> Int -> Constraint a (bound at T1899.hs:10:2)
diff --git a/testsuite/tests/typecheck/should_fail/T2414.stderr b/testsuite/tests/typecheck/should_fail/T2414.stderr
index 0f797da713..bbbf5fce6a 100644
--- a/testsuite/tests/typecheck/should_fail/T2414.stderr
+++ b/testsuite/tests/typecheck/should_fail/T2414.stderr
@@ -1,7 +1,8 @@
-T2414.hs:9:13:
- Occurs check: cannot construct the infinite type: b0 ~ (Bool, b0)
- Expected type: b0 -> Maybe (Bool, b0)
- Actual type: (Bool, b0) -> Maybe (Bool, b0)
- In the first argument of ‘unfoldr’, namely ‘Just’
- In the expression: unfoldr Just
+T2414.hs:9:13: error:
+ • Occurs check: cannot construct the infinite type: b0 ~ (Bool, b0)
+ Expected type: b0 -> Maybe (Bool, b0)
+ Actual type: (Bool, b0) -> Maybe (Bool, b0)
+ • In the first argument of ‘unfoldr’, namely ‘Just’
+ In the expression: unfoldr Just
+ In an equation for ‘f’: f = unfoldr Just
diff --git a/testsuite/tests/typecheck/should_fail/T2534.stderr b/testsuite/tests/typecheck/should_fail/T2534.stderr
index fe6abae7b8..4e469f3cfd 100644
--- a/testsuite/tests/typecheck/should_fail/T2534.stderr
+++ b/testsuite/tests/typecheck/should_fail/T2534.stderr
@@ -1,8 +1,9 @@
-T2534.hs:3:13:
- Couldn't match type ‘[b]’ with ‘a0 -> [b]’
- Expected type: [a0] -> [b] -> [b]
- Actual type: [a0] -> (a0 -> [b]) -> [b]
- In the first argument of ‘foldr’, namely ‘(>>=)’
- In the expression: foldr (>>=) [] []
- Relevant bindings include foo :: [b] (bound at T2534.hs:3:1)
+T2534.hs:3:13: error:
+ • Couldn't match type ‘[b]’ with ‘a0 -> [b]’
+ Expected type: [a0] -> [b] -> [b]
+ Actual type: [a0] -> (a0 -> [b]) -> [b]
+ • In the first argument of ‘foldr’, namely ‘(>>=)’
+ In the expression: foldr (>>=) [] []
+ In an equation for ‘foo’: foo = foldr (>>=) [] []
+ • Relevant bindings include foo :: [b] (bound at T2534.hs:3:1)
diff --git a/testsuite/tests/typecheck/should_fail/T2688.stderr b/testsuite/tests/typecheck/should_fail/T2688.stderr
index 1915c41812..2b2ca0d22a 100644
--- a/testsuite/tests/typecheck/should_fail/T2688.stderr
+++ b/testsuite/tests/typecheck/should_fail/T2688.stderr
@@ -1,13 +1,13 @@
-T2688.hs:8:22:
- Couldn't match expected type ‘v’ with actual type ‘s’
+T2688.hs:8:14: error:
+ • Couldn't match expected type ‘v’ with actual type ‘s’
‘s’ is a rigid type variable bound by
- the class declaration for ‘VectorSpace’ at T2688.hs:5:21
+ the class declaration for ‘VectorSpace’ at T2688.hs:5:21
‘v’ is a rigid type variable bound by
- the class declaration for ‘VectorSpace’ at T2688.hs:5:19
- In the second argument of ‘(/)’, namely ‘s’
- In the second argument of ‘(*^)’, namely ‘(1 / s)’
- Relevant bindings include
- s :: s (bound at T2688.hs:8:10)
- v :: v (bound at T2688.hs:8:5)
- (^/) :: v -> s -> v (bound at T2688.hs:8:5)
+ the class declaration for ‘VectorSpace’ at T2688.hs:5:19
+ • In the expression: v *^ (1 / s)
+ In an equation for ‘^/’: v ^/ s = v *^ (1 / s)
+ • Relevant bindings include
+ s :: s (bound at T2688.hs:8:10)
+ v :: v (bound at T2688.hs:8:5)
+ (^/) :: v -> s -> v (bound at T2688.hs:8:5)
diff --git a/testsuite/tests/typecheck/should_fail/T2846b.stderr b/testsuite/tests/typecheck/should_fail/T2846b.stderr
index 0323283477..371d0ce5ca 100644
--- a/testsuite/tests/typecheck/should_fail/T2846b.stderr
+++ b/testsuite/tests/typecheck/should_fail/T2846b.stderr
@@ -1,6 +1,6 @@
T2846b.hs:5:5: error:
- No instance for (Show (Num a0 => a0)) arising from a use of ‘show’
- (maybe you haven't applied a function to enough arguments?)
- In the expression: show ([1, 2, 3] :: [Num a => a])
- In an equation for ‘f’: f = show ([1, 2, 3] :: [Num a => a])
+ • No instance for (Show (forall a. [Num a => a]))
+ arising from a use of ‘show’
+ • In the expression: show ([1, 2, 3] :: [Num a => a])
+ In an equation for ‘f’: f = show ([1, 2, 3] :: [Num a => a])
diff --git a/testsuite/tests/typecheck/should_fail/T3102.stderr b/testsuite/tests/typecheck/should_fail/T3102.stderr
index 925e80f7fc..a5a410efeb 100644
--- a/testsuite/tests/typecheck/should_fail/T3102.stderr
+++ b/testsuite/tests/typecheck/should_fail/T3102.stderr
@@ -1,11 +1,12 @@
-
-T3102.hs:11:12: error:
- Couldn't match type ‘a’ with ‘(?p::Int) => a0’
- ‘a’ is a rigid type variable bound by
- a type expected by the context:
- forall a. a -> String
- at T3102.hs:11:10
- Expected type: a -> String
- Actual type: ((?p::Int) => a0) -> String
- In the first argument of ‘f’, namely ‘t’
- In the expression: f t
+
+T3102.hs:11:12: error:
+ • Couldn't match type ‘a’ with ‘(?p::Int) => a0’
+ ‘a’ is a rigid type variable bound by
+ a type expected by the context:
+ forall a. a -> String
+ at T3102.hs:11:10
+ Expected type: a -> String
+ Actual type: ((?p::Int) => a0) -> String
+ • In the first argument of ‘f’, namely ‘t’
+ In the expression: f t
+ In an equation for ‘result’: result = f t
diff --git a/testsuite/tests/typecheck/should_fail/T3613.stderr b/testsuite/tests/typecheck/should_fail/T3613.stderr
index f7fa6d4871..b7ffd671c8 100644
--- a/testsuite/tests/typecheck/should_fail/T3613.stderr
+++ b/testsuite/tests/typecheck/should_fail/T3613.stderr
@@ -1,14 +1,20 @@
-T3613.hs:14:20:
- Couldn't match type ‘IO’ with ‘Maybe’
- Expected type: Maybe ()
- Actual type: IO ()
- In the first argument of ‘(>>)’, namely ‘bar’
- In the first argument of ‘fooThen’, namely ‘(bar >> undefined)’
+T3613.hs:14:20: error:
+ • Couldn't match type ‘IO’ with ‘Maybe’
+ Expected type: Maybe b
+ Actual type: IO b
+ • In the first argument of ‘fooThen’, namely ‘(bar >> undefined)’
+ In the expression: fooThen (bar >> undefined)
+ In the expression:
+ let fooThen m = foo >> m in fooThen (bar >> undefined)
-T3613.hs:17:24:
- Couldn't match expected type ‘Maybe a0’ with actual type ‘IO ()’
- In a stmt of a 'do' block: bar
- In the first argument of ‘fooThen’, namely
- ‘(do { bar;
- undefined })’
+T3613.hs:17:24: error:
+ • Couldn't match expected type ‘Maybe a0’ with actual type ‘IO ()’
+ • In a stmt of a 'do' block: bar
+ In the first argument of ‘fooThen’, namely
+ ‘(do { bar;
+ undefined })’
+ In the expression:
+ fooThen
+ (do { bar;
+ undefined })
diff --git a/testsuite/tests/typecheck/should_fail/T3950.stderr b/testsuite/tests/typecheck/should_fail/T3950.stderr
index fab70fd01b..ae50a74f3c 100644
--- a/testsuite/tests/typecheck/should_fail/T3950.stderr
+++ b/testsuite/tests/typecheck/should_fail/T3950.stderr
@@ -1,12 +1,17 @@
-T3950.hs:15:13: error:
+T3950.hs:15:8: error:
• Couldn't match kind ‘* -> *’ with ‘*’
When matching types
w :: (* -> * -> *) -> *
Sealed :: (* -> *) -> *
- Expected type: w (Id p)
- Actual type: Sealed (Id p x0)
- • In the first argument of ‘Just’, namely ‘rp'’
- In the expression: Just rp'
+ Expected type: Maybe (w (Id p))
+ Actual type: Maybe (Sealed (Id p x0))
+ • In the expression: Just rp'
+ In an equation for ‘rp’:
+ rp _
+ = Just rp'
+ where
+ rp' :: Sealed (Id p x)
+ rp' = undefined
• Relevant bindings include
rp :: Bool -> Maybe (w (Id p)) (bound at T3950.hs:15:1)
diff --git a/testsuite/tests/typecheck/should_fail/T5095.stderr b/testsuite/tests/typecheck/should_fail/T5095.stderr
index cc338e7afa..c284cda9d0 100644
--- a/testsuite/tests/typecheck/should_fail/T5095.stderr
+++ b/testsuite/tests/typecheck/should_fail/T5095.stderr
@@ -1,5 +1,5 @@
-T5095.hs:9:11: error:
+T5095.hs:9:9: error:
• Overlapping instances for Eq a arising from a use of ‘==’
Matching instances:
instance [overlappable] Show a => Eq a -- Defined at T5095.hs:5:31
diff --git a/testsuite/tests/typecheck/should_fail/T5689.stderr b/testsuite/tests/typecheck/should_fail/T5689.stderr
index 6e3777d2ee..2c7eaa87d4 100644
--- a/testsuite/tests/typecheck/should_fail/T5689.stderr
+++ b/testsuite/tests/typecheck/should_fail/T5689.stderr
@@ -1,8 +1,10 @@
T5689.hs:10:36: error:
- Couldn't match expected type ‘Bool’ with actual type ‘t’
- In the expression: v
- In the expression: if v then False else True
- Relevant bindings include
- v :: t (bound at T5689.hs:10:28)
- r :: IORef (t -> t) (bound at T5689.hs:7:14)
+ • Couldn't match expected type ‘Bool’ with actual type ‘t’
+ • In the expression: v
+ In the expression: if v then False else True
+ In the second argument of ‘writeIORef’, namely
+ ‘(\ v -> if v then False else True)’
+ • Relevant bindings include
+ v :: t (bound at T5689.hs:10:28)
+ r :: IORef (t -> t) (bound at T5689.hs:7:14)
diff --git a/testsuite/tests/typecheck/should_fail/T5853.stderr b/testsuite/tests/typecheck/should_fail/T5853.stderr
index 33ae4e16ce..ab2ad30d6c 100644
--- a/testsuite/tests/typecheck/should_fail/T5853.stderr
+++ b/testsuite/tests/typecheck/should_fail/T5853.stderr
@@ -1,5 +1,5 @@
-T5853.hs:15:52: error:
+T5853.hs:15:46: error:
• Could not deduce: Subst t2 (Elem t1) ~ t1
arising from a use of ‘<$>’
from the context: (F t,
diff --git a/testsuite/tests/typecheck/should_fail/T6069.stderr b/testsuite/tests/typecheck/should_fail/T6069.stderr
index eff2e8b5cf..e1c2e5653f 100644
--- a/testsuite/tests/typecheck/should_fail/T6069.stderr
+++ b/testsuite/tests/typecheck/should_fail/T6069.stderr
@@ -1,21 +1,24 @@
-T6069.hs:13:15:
- Couldn't match type ‘ST s0 Int’ with ‘forall s. ST s a0’
- Expected type: ST s0 Int -> a0
- Actual type: (forall s. ST s a0) -> a0
- In the second argument of ‘(.)’, namely ‘runST’
- In the expression: print . runST
+T6069.hs:13:15: error:
+ • Couldn't match type ‘ST s0 Int’ with ‘forall s. ST s a0’
+ Expected type: ST s0 Int -> a0
+ Actual type: (forall s. ST s a0) -> a0
+ • In the second argument of ‘(.)’, namely ‘runST’
+ In the expression: print . runST
+ In the expression: (print . runST) fourty_two
-T6069.hs:14:15:
- Couldn't match type ‘ST s1 Int’ with ‘forall s. ST s a1’
- Expected type: ST s1 Int -> a1
- Actual type: (forall s. ST s a1) -> a1
- In the second argument of ‘(.)’, namely ‘runST’
- In the expression: (print . runST)
+T6069.hs:14:15: error:
+ • Couldn't match type ‘ST s1 Int’ with ‘forall s. ST s a1’
+ Expected type: ST s1 Int -> a1
+ Actual type: (forall s. ST s a1) -> a1
+ • In the second argument of ‘(.)’, namely ‘runST’
+ In the expression: (print . runST)
+ In the expression: (print . runST) $ fourty_two
-T6069.hs:15:16:
- Couldn't match type ‘ST s2 Int’ with ‘forall s. ST s a2’
- Expected type: ST s2 Int -> a2
- Actual type: (forall s. ST s a2) -> a2
- In the second argument of ‘(.)’, namely ‘runST’
- In the first argument of ‘($)’, namely ‘(print . runST)’
+T6069.hs:15:16: error:
+ • Couldn't match type ‘ST s2 Int’ with ‘forall s. ST s a2’
+ Expected type: ST s2 Int -> a2
+ Actual type: (forall s. ST s a2) -> a2
+ • In the second argument of ‘(.)’, namely ‘runST’
+ In the first argument of ‘($)’, namely ‘(print . runST)’
+ In the expression: (print . runST) $
diff --git a/testsuite/tests/typecheck/should_fail/T7264.stderr b/testsuite/tests/typecheck/should_fail/T7264.stderr
index 4b5b3557d9..b343d88cd1 100644
--- a/testsuite/tests/typecheck/should_fail/T7264.stderr
+++ b/testsuite/tests/typecheck/should_fail/T7264.stderr
@@ -1,12 +1,13 @@
-T7264.hs:13:19:
- Couldn't match type ‘a’ with ‘forall r. r -> String’
+T7264.hs:13:19: error:
+ • Couldn't match type ‘a’ with ‘forall r. r -> String’
‘a’ is a rigid type variable bound by
- the inferred type of mkFoo2 :: a -> Maybe Foo at T7264.hs:13:1
- Expected type: a -> Foo
- Actual type: (forall r. r -> String) -> Foo
- In the first argument of ‘mmap’, namely ‘Foo’
- In the expression: mmap Foo (Just val)
- Relevant bindings include
- val :: a (bound at T7264.hs:13:8)
- mkFoo2 :: a -> Maybe Foo (bound at T7264.hs:13:1)
+ the inferred type of mkFoo2 :: a -> Maybe Foo at T7264.hs:13:1
+ Expected type: a -> Foo
+ Actual type: (forall r. r -> String) -> Foo
+ • In the first argument of ‘mmap’, namely ‘Foo’
+ In the expression: mmap Foo (Just val)
+ In an equation for ‘mkFoo2’: mkFoo2 val = mmap Foo (Just val)
+ • Relevant bindings include
+ val :: a (bound at T7264.hs:13:8)
+ mkFoo2 :: a -> Maybe Foo (bound at T7264.hs:13:1)
diff --git a/testsuite/tests/typecheck/should_fail/T7368.stderr b/testsuite/tests/typecheck/should_fail/T7368.stderr
index 1c538ac7f9..f187aee61c 100644
--- a/testsuite/tests/typecheck/should_fail/T7368.stderr
+++ b/testsuite/tests/typecheck/should_fail/T7368.stderr
@@ -4,3 +4,4 @@ T7368.hs:3:10: error:
When matching the kind of ‘Maybe’
• In the first argument of ‘b’, namely ‘(l Nothing)’
In the expression: b (l Nothing)
+ In an equation for ‘f’: f = b (l Nothing)
diff --git a/testsuite/tests/typecheck/should_fail/T7453.stderr b/testsuite/tests/typecheck/should_fail/T7453.stderr
index efbc7497e5..47bfa78754 100644
--- a/testsuite/tests/typecheck/should_fail/T7453.stderr
+++ b/testsuite/tests/typecheck/should_fail/T7453.stderr
@@ -13,6 +13,14 @@ T7453.hs:9:15: error:
z = aux
where
aux = Id v
+ In an equation for ‘cast1’:
+ cast1 v
+ = runId z
+ where
+ z :: Id t
+ z = aux
+ where
+ aux = Id v
• Relevant bindings include
aux :: Id r (bound at T7453.hs:10:21)
z :: Id t (bound at T7453.hs:9:11)
@@ -33,6 +41,14 @@ T7453.hs:15:15: error:
z = aux
where
aux = const v
+ In an equation for ‘cast2’:
+ cast2 v
+ = z ()
+ where
+ z :: () -> t
+ z = aux
+ where
+ aux = const v
• Relevant bindings include
aux :: forall b. b -> r (bound at T7453.hs:16:21)
z :: () -> t1 (bound at T7453.hs:15:11)
@@ -51,8 +67,16 @@ T7453.hs:21:15: error:
z = v
where
aux = const v
+ In an equation for ‘cast3’:
+ cast3 v
+ = z
+ where
+ z :: t
+ z = v
+ where
+ aux = const v
• Relevant bindings include
aux :: forall b. b -> r (bound at T7453.hs:22:21)
z :: t1 (bound at T7453.hs:21:11)
v :: r (bound at T7453.hs:19:7)
- cast3 :: r -> t (bound at T7453.hs:19:1)
+ cast3 :: r -> forall t. t (bound at T7453.hs:19:1)
diff --git a/testsuite/tests/typecheck/should_fail/T7734.stderr b/testsuite/tests/typecheck/should_fail/T7734.stderr
index d4efb614df..53536d1a13 100644
--- a/testsuite/tests/typecheck/should_fail/T7734.stderr
+++ b/testsuite/tests/typecheck/should_fail/T7734.stderr
@@ -3,6 +3,7 @@ T7734.hs:4:13: error:
• Occurs check: cannot construct the infinite type: r2 ~ r2 -> r1
• In the first argument of ‘x’, namely ‘x’
In the expression: x x
+ In an equation for ‘f’: x `f` y = x x
• Relevant bindings include
x :: r2 -> r1 (bound at T7734.hs:4:1)
f :: (r2 -> r1) -> r -> r1 (bound at T7734.hs:4:1)
@@ -11,6 +12,7 @@ T7734.hs:5:13: error:
• Occurs check: cannot construct the infinite type: r2 ~ r2 -> r1
• In the first argument of ‘x’, namely ‘x’
In the expression: x x
+ In an equation for ‘&’: (&) x y = x x
• Relevant bindings include
x :: r2 -> r1 (bound at T7734.hs:5:5)
(&) :: (r2 -> r1) -> r -> r1 (bound at T7734.hs:5:1)
diff --git a/testsuite/tests/typecheck/should_fail/T7851.stderr b/testsuite/tests/typecheck/should_fail/T7851.stderr
index 64148511e7..14efa7c7c9 100644
--- a/testsuite/tests/typecheck/should_fail/T7851.stderr
+++ b/testsuite/tests/typecheck/should_fail/T7851.stderr
@@ -1,8 +1,13 @@
-T7851.hs:5:10:
- Couldn't match expected type ‘IO a0’ with actual type ‘a1 -> IO ()’
- Probable cause: ‘print’ is applied to too few arguments
- In a stmt of a 'do' block: print
- In the expression:
- do { print;
- print "Hello" }
+T7851.hs:5:10: error:
+ • Couldn't match expected type ‘IO a0’
+ with actual type ‘a1 -> IO ()’
+ • Probable cause: ‘print’ is applied to too few arguments
+ In a stmt of a 'do' block: print
+ In the expression:
+ do { print;
+ print "Hello" }
+ In an equation for ‘bar’:
+ bar
+ = do { print;
+ print "Hello" }
diff --git a/testsuite/tests/typecheck/should_fail/T8142.stderr b/testsuite/tests/typecheck/should_fail/T8142.stderr
index 9ae86c5524..09a2a9677d 100644
--- a/testsuite/tests/typecheck/should_fail/T8142.stderr
+++ b/testsuite/tests/typecheck/should_fail/T8142.stderr
@@ -1,25 +1,26 @@
T8142.hs:6:18: error:
- Couldn't match type ‘Nu g0’ with ‘Nu g’
- NB: ‘Nu’ is a type function, and may not be injective
- The type variable ‘g0’ is ambiguous
- Expected type: Nu ((,) t) -> Nu g
- Actual type: Nu ((,) t0) -> Nu g0
- In the ambiguity check for the inferred type for ‘h’
- To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
- When checking the inferred type
- h :: forall t (g :: * -> *). Nu ((,) t) -> Nu g
- In an equation for ‘tracer’:
- tracer
- = h
- where
- h = (\ (_, b) -> ((outI . fmap h) b)) . out
+ • Couldn't match type ‘Nu g0’ with ‘Nu g’
+ NB: ‘Nu’ is a type function, and may not be injective
+ The type variable ‘g0’ is ambiguous
+ Expected type: Nu ((,) t) -> Nu g
+ Actual type: Nu ((,) t0) -> Nu g0
+ • In the ambiguity check for the inferred type for ‘h’
+ To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
+ When checking the inferred type
+ h :: forall t (g :: * -> *). Nu ((,) t) -> Nu g
+ In an equation for ‘tracer’:
+ tracer
+ = h
+ where
+ h = (\ (_, b) -> ((outI . fmap h) b)) . out
T8142.hs:6:57: error:
- Couldn't match type ‘Nu ((,) t)’ with ‘g (Nu ((,) t))’
- Expected type: Nu ((,) t) -> (t, g (Nu ((,) t)))
- Actual type: Nu ((,) t) -> (t, Nu ((,) t))
- In the second argument of ‘(.)’, namely ‘out’
- In the expression: (\ (_, b) -> ((outI . fmap h) b)) . out
- Relevant bindings include
- h :: Nu ((,) t) -> Nu g (bound at T8142.hs:6:18)
+ • Couldn't match type ‘Nu ((,) t)’ with ‘g (Nu ((,) t))’
+ Expected type: Nu ((,) t) -> (t, g (Nu ((,) t)))
+ Actual type: Nu ((,) t) -> (t, Nu ((,) t))
+ • In the second argument of ‘(.)’, namely ‘out’
+ In the expression: (\ (_, b) -> ((outI . fmap h) b)) . out
+ In an equation for ‘h’: h = (\ (_, b) -> ((outI . fmap h) b)) . out
+ • Relevant bindings include
+ h :: Nu ((,) t) -> Nu g (bound at T8142.hs:6:18)
diff --git a/testsuite/tests/typecheck/should_fail/T8428.stderr b/testsuite/tests/typecheck/should_fail/T8428.stderr
index cb4724331c..97cd9f7806 100644
--- a/testsuite/tests/typecheck/should_fail/T8428.stderr
+++ b/testsuite/tests/typecheck/should_fail/T8428.stderr
@@ -1,10 +1,8 @@
-T8428.hs:11:19:
- Couldn't match type ‘(forall s. ST s) a’ with ‘forall s. ST s a’
- Expected type: IdentityT (forall s. ST s) a -> forall s. ST s a
- Actual type: IdentityT (forall s. ST s) a -> (forall s. ST s) a
- In the second argument of ‘(.)’, namely ‘runIdentityT’
- In the expression: runST . runIdentityT
- Relevant bindings include
- runIdST :: IdentityT (forall s. ST s) a -> a
- (bound at T8428.hs:11:1)
+T8428.hs:11:19: error:
+ • Couldn't match type ‘forall s1. ST s1’ with ‘ST s’
+ Expected type: IdentityT (forall s. ST s) a -> forall s. ST s a
+ Actual type: IdentityT (forall s. ST s) a -> (forall s. ST s) a
+ • In the second argument of ‘(.)’, namely ‘runIdentityT’
+ In the expression: runST . runIdentityT
+ In an equation for ‘runIdST’: runIdST = runST . runIdentityT
diff --git a/testsuite/tests/typecheck/should_fail/T8603.stderr b/testsuite/tests/typecheck/should_fail/T8603.stderr
index 5bfd397167..53d4e422cb 100644
--- a/testsuite/tests/typecheck/should_fail/T8603.stderr
+++ b/testsuite/tests/typecheck/should_fail/T8603.stderr
@@ -5,22 +5,15 @@ T8603.hs:13:10: error:
• In the instance declaration for ‘Monad RV’
T8603.hs:29:17: error:
- • Couldn't match kind ‘* -> *’ with ‘*’
- When matching the kind of ‘[[a0]]’
+ • Couldn't match type ‘RV a0’ with ‘StateT s RV t0’
+ Expected type: [Integer] -> StateT s RV t0
+ Actual type: (->) ((->) [a0]) (RV a0)
• The function ‘lift’ is applied to two arguments,
- but its type ‘[] [a0] (StateT s RV t0)
- -> (->) [[a0]] (StateT s RV t0)’
+ but its type ‘([a0] -> RV a0) -> (->) ((->) [a0]) (RV a0)’
has only one
In a stmt of a 'do' block: prize <- lift uniform [1, 2, 3]
In the expression:
do { prize <- lift uniform [1, 2, ....];
return False }
-
-T8603.hs:29:22: error:
- • Couldn't match type ‘RV a0’ with ‘StateT s RV t0’
- Expected type: [] [a0] (StateT s RV t0)
- Actual type: [a0] -> RV a0
- • In the first argument of ‘lift’, namely ‘uniform’
- In a stmt of a 'do' block: prize <- lift uniform [1, 2, 3]
• Relevant bindings include
testRVState1 :: RVState s Bool (bound at T8603.hs:28:1)
diff --git a/testsuite/tests/typecheck/should_fail/T9109.stderr b/testsuite/tests/typecheck/should_fail/T9109.stderr
index defd77572e..f13b0fc310 100644
--- a/testsuite/tests/typecheck/should_fail/T9109.stderr
+++ b/testsuite/tests/typecheck/should_fail/T9109.stderr
@@ -2,14 +2,13 @@
T9109.hs:8:13: error:
• Couldn't match expected type ‘r’ with actual type ‘Bool’
‘r’ is untouchable
- inside the constraints: r1 ~ Bool
+ inside the constraints: t ~ Bool
bound by a pattern with constructor: GBool :: G Bool,
in an equation for ‘foo’
at T9109.hs:8:5-9
‘r’ is a rigid type variable bound by
- the inferred type of foo :: G r1 -> r at T9109.hs:8:1
+ the inferred type of foo :: G t -> r at T9109.hs:8:1
Possible fix: add a type signature for ‘foo’
• In the expression: True
In an equation for ‘foo’: foo GBool = True
- • Relevant bindings include
- foo :: G r1 -> r (bound at T9109.hs:8:1)
+ • Relevant bindings include foo :: G t -> r (bound at T9109.hs:8:1)
diff --git a/testsuite/tests/typecheck/should_fail/T9774.stderr b/testsuite/tests/typecheck/should_fail/T9774.stderr
index d75942bc59..28b1b58c4c 100644
--- a/testsuite/tests/typecheck/should_fail/T9774.stderr
+++ b/testsuite/tests/typecheck/should_fail/T9774.stderr
@@ -1,8 +1,8 @@
-T9774.hs:5:29:
- Couldn't match type ‘Char’ with ‘[Char]’
- Expected type: String
- Actual type: Char
- In the second argument of ‘assert’, namely ‘'a'’
- In the first argument of ‘putStrLn’, namely ‘(assert True 'a')’
- In the expression: putStrLn (assert True 'a')
+T9774.hs:5:17: error:
+ • Couldn't match type ‘Char’ with ‘[Char]’
+ Expected type: String
+ Actual type: Char
+ • In the first argument of ‘putStrLn’, namely ‘(assert True 'a')’
+ In the expression: putStrLn (assert True 'a')
+ In an equation for ‘foo’: foo = putStrLn (assert True 'a')
diff --git a/testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr b/testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr
index 1767e8e976..32dac6a133 100644
--- a/testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr
+++ b/testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr
@@ -2,8 +2,7 @@
TcCoercibleFail.hs:11:8: error:
• Couldn't match representation of type ‘Int’ with that of ‘()’
arising from a use of ‘coerce’
- • In the expression: coerce
- In the expression: coerce $ one :: ()
+ • In the expression: coerce $ one :: ()
In an equation for ‘foo1’: foo1 = coerce $ one :: ()
TcCoercibleFail.hs:14:8: error:
@@ -12,8 +11,7 @@ TcCoercibleFail.hs:14:8: error:
arising from a use of ‘coerce’
NB: We cannot know what roles the parameters to ‘m’ have;
we must assume that the role is nominal
- • In the expression: coerce
- In the expression: coerce $ (return one :: m Int)
+ • In the expression: coerce $ (return one :: m Int)
In an equation for ‘foo2’: foo2 = coerce $ (return one :: m Int)
• Relevant bindings include
foo2 :: m Age (bound at TcCoercibleFail.hs:14:1)
@@ -21,8 +19,7 @@ TcCoercibleFail.hs:14:8: error:
TcCoercibleFail.hs:16:8: error:
• Couldn't match type ‘Int’ with ‘Age’
arising from a use of ‘coerce’
- • In the expression: coerce
- In the expression: coerce $ Map one () :: Map Age ()
+ • In the expression: coerce $ Map one () :: Map Age ()
In an equation for ‘foo3’: foo3 = coerce $ Map one () :: Map Age ()
TcCoercibleFail.hs:18:8: error:
@@ -31,8 +28,7 @@ TcCoercibleFail.hs:18:8: error:
arising from a use of ‘coerce’
The data constructor ‘Data.Ord.Down’
of newtype ‘Down’ is not in scope
- • In the expression: coerce
- In the expression: coerce $ one :: Down Int
+ • In the expression: coerce $ one :: Down Int
In an equation for ‘foo4’: foo4 = coerce $ one :: Down Int
TcCoercibleFail.hs:21:8: error:
diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr
index e41ec7443d..9b85edb110 100644
--- a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr
+++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr
@@ -1,6 +1,7 @@
-TcStaticPointersFail01.hs:8:13:
- Couldn't match expected type ‘Int’ with actual type ‘Int -> Int’
- Probable cause: ‘g’ is applied to too few arguments
- In the body of a static form: g
- In the expression: static g
+TcStaticPointersFail01.hs:8:13: error:
+ • Couldn't match expected type ‘Int’ with actual type ‘Int -> Int’
+ • Probable cause: ‘g’ is applied to too few arguments
+ In the body of a static form: g
+ In the expression: static g
+ In an equation for ‘f0’: f0 = static g
diff --git a/testsuite/tests/typecheck/should_fail/VtaFail.hs b/testsuite/tests/typecheck/should_fail/VtaFail.hs
new file mode 100644
index 0000000000..250f9e273e
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/VtaFail.hs
@@ -0,0 +1,57 @@
+{-# LANGUAGE TypeApplications, RankNTypes, PolyKinds #-}
+
+module VtaFail1 where
+
+pairup_nosig x y = (x, y)
+
+answer_nosig = pairup_nosig @Int @Bool 5 True
+
+addOne :: Num a => a -> a
+addOne x = x + 1
+
+answer_constraint_fail = addOne @Bool 5
+
+answer_lambda = (\x -> x) @Int 12
+
+pair :: forall a. a -> forall b. b -> (a, b)
+pair = (,)
+
+a = pair 3 @Int @Bool True
+
+data First (a :: * -> *) = F
+
+first :: First a -> Int
+first _ = 0
+
+fInt = first @Int F -- should fail
+
+data Proxy (a :: k) = P -- This expands to P (kind variable) (type variable)
+
+foo :: Proxy a -> Int
+foo _ = 0
+
+baz = foo @Bool (P :: Proxy Int) -- should fail
+
+data Three (a :: * -> k -> *) = T
+
+too :: Three a -> Int
+too _ = 3
+
+threeBad = too @Maybe T
+threeWorse = too @( -> ) (T :: Three Either)
+
+plus :: Int -> Int -> Int
+plus = (+)
+
+b = plus @Int 5 7
+c = plus @Rational 5 10
+d = (+) @Int @Int @Int 12 14
+
+
+e = show @Int @Float (read "5")
+f = show (read @Int @Bool @Float "3")
+
+silly :: a -> Bool
+silly _ = False
+
+g = silly @Maybe -- should fail
diff --git a/testsuite/tests/typecheck/should_fail/VtaFail.stderr b/testsuite/tests/typecheck/should_fail/VtaFail.stderr
new file mode 100644
index 0000000000..313d174b74
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/VtaFail.stderr
@@ -0,0 +1,94 @@
+
+VtaFail.hs:7:16: error:
+ • Cannot not apply expression of type ‘t1 -> t0 -> (t1, t0)’
+ to a visible type argument ‘Int’
+ • In the expression: pairup_nosig @Int @Bool 5 True
+ In an equation for ‘answer_nosig’:
+ answer_nosig = pairup_nosig @Int @Bool 5 True
+
+VtaFail.hs:12:26: error:
+ • No instance for (Num Bool) arising from a use of ‘addOne’
+ • In the expression: addOne @Bool 5
+ In an equation for ‘answer_constraint_fail’:
+ answer_constraint_fail = addOne @Bool 5
+
+VtaFail.hs:14:17: error:
+ • Cannot not apply expression of type ‘r0 -> r0’
+ to a visible type argument ‘Int’
+ • In the expression: (\ x -> x) @Int 12
+ In an equation for ‘answer_lambda’:
+ answer_lambda = (\ x -> x) @Int 12
+
+VtaFail.hs:19:5: error:
+ • Cannot not apply expression of type ‘Int -> (a0, Int)’
+ to a visible type argument ‘Bool’
+ • In the expression: pair 3 @Int @Bool True
+ In an equation for ‘a’: a = pair 3 @Int @Bool True
+
+VtaFail.hs:26:15: error:
+ • Expected kind ‘* -> *’, but ‘Int’ has kind ‘*’
+ • In the type ‘Int’
+ In the expression: first @Int F
+ In an equation for ‘fInt’: fInt = first @Int F
+
+VtaFail.hs:33:18: error:
+ • Couldn't match type ‘Int’ with ‘Bool’
+ Expected type: Proxy Bool
+ Actual type: Proxy Int
+ • In the second argument of ‘foo’, namely ‘(P :: Proxy Int)’
+ In the expression: foo @Bool (P :: Proxy Int)
+ In an equation for ‘baz’: baz = foo @Bool (P :: Proxy Int)
+
+VtaFail.hs:40:17: error:
+ • Expected kind ‘* -> k0 -> *’, but ‘Maybe’ has kind ‘* -> *’
+ • In the type ‘Maybe’
+ In the expression: too @Maybe T
+ In an equation for ‘threeBad’: threeBad = too @Maybe T
+
+VtaFail.hs:41:27: error:
+ • Couldn't match type ‘Either’ with ‘(->)’
+ Expected type: Three (->)
+ Actual type: Three Either
+ • In the second argument of ‘too’, namely ‘(T :: Three Either)’
+ In the expression: too @(->) (T :: Three Either)
+ In an equation for ‘threeWorse’:
+ threeWorse = too @(->) (T :: Three Either)
+
+VtaFail.hs:46:5: error:
+ • Cannot not apply expression of type ‘Int -> Int -> Int’
+ to a visible type argument ‘Int’
+ • In the expression: plus @Int 5 7
+ In an equation for ‘b’: b = plus @Int 5 7
+
+VtaFail.hs:47:5: error:
+ • Cannot not apply expression of type ‘Int -> Int -> Int’
+ to a visible type argument ‘Rational’
+ • In the expression: plus @Rational 5 10
+ In an equation for ‘c’: c = plus @Rational 5 10
+
+VtaFail.hs:48:5: error:
+ • Cannot not apply expression of type ‘Int -> Int -> Int’
+ to a visible type argument ‘Int’
+ • In the expression: (+) @Int @Int @Int 12 14
+ In an equation for ‘d’: d = (+) @Int @Int @Int 12 14
+
+VtaFail.hs:51:5: error:
+ • Cannot not apply expression of type ‘Int -> String’
+ to a visible type argument ‘Float’
+ • In the expression: show @Int @Float (read "5")
+ In an equation for ‘e’: e = show @Int @Float (read "5")
+
+VtaFail.hs:52:11: error:
+ • Cannot not apply expression of type ‘String -> Int’
+ to a visible type argument ‘Bool’
+ • In the first argument of ‘show’, namely
+ ‘(read @Int @Bool @Float "3")’
+ In the expression: show (read @Int @Bool @Float "3")
+ In an equation for ‘f’: f = show (read @Int @Bool @Float "3")
+
+VtaFail.hs:57:12: error:
+ • Expecting one more argument to ‘Maybe’
+ Expected a type, but ‘Maybe’ has kind ‘* -> *’
+ • In the type ‘Maybe’
+ In the expression: silly @Maybe
+ In an equation for ‘g’: g = silly @Maybe
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 8d8d4306e7..aa43cce226 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -147,7 +147,7 @@ test('tcfail160', normal, compile_fail, [''])
test('tcfail161', normal, compile_fail, [''])
test('tcfail162', normal, compile_fail, [''])
test('tcfail164', normal, compile_fail, [''])
-test('tcfail165', normal, compile_fail, [''])
+test('tcfail165', normal, compile, [''])
test('tcfail166', normal, compile_fail, [''])
test('tcfail167', normal, compile_fail, [''])
test('tcfail168', normal, compile_fail, [''])
@@ -379,6 +379,7 @@ test('T10351', normal, compile_fail, [''])
test('T10534', extra_clean(['T10534a.hi', 'T10534a.o']),
multimod_compile_fail, ['T10534', '-v0'])
test('T10495', normal, compile_fail, [''])
+test('VtaFail', normal, compile_fail, [''])
test('ExpandSynsFail1', normal, compile_fail, ['-fprint-expanded-synonyms'])
test('ExpandSynsFail2', normal, compile_fail, ['-fprint-expanded-synonyms'])
diff --git a/testsuite/tests/typecheck/should_fail/mc19.stderr b/testsuite/tests/typecheck/should_fail/mc19.stderr
index 8cdd4f456b..5f004dc4a8 100644
--- a/testsuite/tests/typecheck/should_fail/mc19.stderr
+++ b/testsuite/tests/typecheck/should_fail/mc19.stderr
@@ -1,11 +1,12 @@
-
-mc19.hs:10:31: error:
- Couldn't match type ‘a’ with ‘[a]’
- ‘a’ is a rigid type variable bound by
- a type expected by the context:
- forall a. [a] -> [a]
- at mc19.hs:10:10
- Expected type: [a] -> [a]
- Actual type: [a] -> [[a]]
- In the expression: inits
- In a stmt of a monad comprehension: then inits
+
+mc19.hs:10:31: error:
+ • Couldn't match type ‘a’ with ‘[a]’
+ ‘a’ is a rigid type variable bound by
+ a type expected by the context:
+ forall a. [a] -> [a]
+ at mc19.hs:10:10
+ Expected type: [a] -> [a]
+ Actual type: [a] -> [[a]]
+ • In the expression: inits
+ In a stmt of a monad comprehension: then inits
+ In the expression: [x | x <- [3, 2, 1], then inits]
diff --git a/testsuite/tests/typecheck/should_fail/mc21.stderr b/testsuite/tests/typecheck/should_fail/mc21.stderr
index 3017d2221c..74a13b14bc 100644
--- a/testsuite/tests/typecheck/should_fail/mc21.stderr
+++ b/testsuite/tests/typecheck/should_fail/mc21.stderr
@@ -1,11 +1,13 @@
-
-mc21.hs:12:26: error:
- Couldn't match type ‘a’ with ‘[a]’
- ‘a’ is a rigid type variable bound by
- a type expected by the context:
- forall a. [a] -> [[a]]
- at mc21.hs:11:9
- Expected type: [a] -> [[a]]
- Actual type: [[a]] -> [[a]]
- In the expression: take 5
- In a stmt of a monad comprehension: then group using take 5
+
+mc21.hs:12:26: error:
+ • Couldn't match type ‘a’ with ‘[a]’
+ ‘a’ is a rigid type variable bound by
+ a type expected by the context:
+ forall a. [a] -> [[a]]
+ at mc21.hs:11:9
+ Expected type: [a] -> [[a]]
+ Actual type: [[a]] -> [[a]]
+ • In the expression: take 5
+ In a stmt of a monad comprehension: then group using take 5
+ In the expression:
+ [GHC.List.length x | x <- [Gnorf, Brain], then group using take 5]
diff --git a/testsuite/tests/typecheck/should_fail/mc22.stderr b/testsuite/tests/typecheck/should_fail/mc22.stderr
index 1c6dc386dd..5e369d7ffe 100644
--- a/testsuite/tests/typecheck/should_fail/mc22.stderr
+++ b/testsuite/tests/typecheck/should_fail/mc22.stderr
@@ -1,24 +1,27 @@
-
-mc22.hs:9:9: error:
- No instance for (Functor t) arising from a use of ‘fmap’
- Possible fix:
- add (Functor t) to the context of
- a type expected by the context:
- (a -> b) -> t a -> t b
- or the inferred type of foo :: [t [Char]]
- In the expression: fmap
- In a stmt of a monad comprehension: then group using take 5
- In the expression:
- [x + 1 | x <- ["Hello", "World"], then group using take 5]
-
-mc22.hs:10:26: error:
- Couldn't match type ‘a’ with ‘t a’
- ‘a’ is a rigid type variable bound by
- a type expected by the context:
- forall a. [a] -> [t a]
- at mc22.hs:9:9
- Expected type: [a] -> [t a]
- Actual type: [t a] -> [t a]
- In the expression: take 5
- In a stmt of a monad comprehension: then group using take 5
- Relevant bindings include foo :: [t [Char]] (bound at mc22.hs:8:1)
+
+mc22.hs:9:9: error:
+ • No instance for (Functor t) arising from a use of ‘fmap’
+ Possible fix:
+ add (Functor t) to the context of
+ a type expected by the context:
+ (a -> b) -> t a -> t b
+ or the inferred type of foo :: [t [Char]]
+ • In the expression: fmap
+ In a stmt of a monad comprehension: then group using take 5
+ In the expression:
+ [x + 1 | x <- ["Hello", "World"], then group using take 5]
+
+mc22.hs:10:26: error:
+ • Couldn't match type ‘a’ with ‘t a’
+ ‘a’ is a rigid type variable bound by
+ a type expected by the context:
+ forall a. [a] -> [t a]
+ at mc22.hs:9:9
+ Expected type: [a] -> [t a]
+ Actual type: [t a] -> [t a]
+ • In the expression: take 5
+ In a stmt of a monad comprehension: then group using take 5
+ In the expression:
+ [x + 1 | x <- ["Hello", "World"], then group using take 5]
+ • Relevant bindings include
+ foo :: [t [Char]] (bound at mc22.hs:8:1)
diff --git a/testsuite/tests/typecheck/should_fail/mc23.stderr b/testsuite/tests/typecheck/should_fail/mc23.stderr
index 945d1a6db8..2f3ae27a98 100644
--- a/testsuite/tests/typecheck/should_fail/mc23.stderr
+++ b/testsuite/tests/typecheck/should_fail/mc23.stderr
@@ -1,9 +1,10 @@
-mc23.hs:9:29:
- Couldn't match type ‘[a0]’ with ‘[a] -> m a’
- Expected type: (a -> b) -> [a] -> m a
- Actual type: [a0] -> [a0]
- Possible cause: ‘take’ is applied to too many arguments
- In the expression: take 5
- In a stmt of a monad comprehension: then take 5 by x
- Relevant bindings include z :: m b (bound at mc23.hs:9:1)
+mc23.hs:9:29: error:
+ • Couldn't match type ‘[a0]’ with ‘[a] -> m a’
+ Expected type: (a -> b) -> [a] -> m a
+ Actual type: [a0] -> [a0]
+ • Possible cause: ‘take’ is applied to too many arguments
+ In the expression: take 5
+ In a stmt of a monad comprehension: then take 5 by x
+ In the expression: [x | x <- [1 .. 10], then take 5 by x]
+ • Relevant bindings include z :: m b (bound at mc23.hs:9:1)
diff --git a/testsuite/tests/typecheck/should_fail/mc24.stderr b/testsuite/tests/typecheck/should_fail/mc24.stderr
index b14fd81162..7f016283b1 100644
--- a/testsuite/tests/typecheck/should_fail/mc24.stderr
+++ b/testsuite/tests/typecheck/should_fail/mc24.stderr
@@ -1,9 +1,11 @@
-mc24.hs:10:31:
- Couldn't match type ‘[a0]’ with ‘[a] -> m [a]’
- Expected type: (a -> Integer) -> [a] -> m [a]
- Actual type: [a0] -> [a0]
- Possible cause: ‘take’ is applied to too many arguments
- In the expression: take 2
- In a stmt of a monad comprehension: then group by x using take 2
- Relevant bindings include foo :: m Int (bound at mc24.hs:8:1)
+mc24.hs:10:31: error:
+ • Couldn't match type ‘[a0]’ with ‘[a] -> m [a]’
+ Expected type: (a -> Integer) -> [a] -> m [a]
+ Actual type: [a0] -> [a0]
+ • Possible cause: ‘take’ is applied to too many arguments
+ In the expression: take 2
+ In a stmt of a monad comprehension: then group by x using take 2
+ In the expression:
+ [GHC.List.length x | x <- [1 .. 10], then group by x using take 2]
+ • Relevant bindings include foo :: m Int (bound at mc24.hs:8:1)
diff --git a/testsuite/tests/typecheck/should_fail/mc25.stderr b/testsuite/tests/typecheck/should_fail/mc25.stderr
index 0989dbcf70..406f89e719 100644
--- a/testsuite/tests/typecheck/should_fail/mc25.stderr
+++ b/testsuite/tests/typecheck/should_fail/mc25.stderr
@@ -1,18 +1,20 @@
mc25.hs:9:10: error:
- No instance for (Functor t1) arising from a use of ‘fmap’
- Possible fix:
- add (Functor t1) to the context of
- a type expected by the context: (a -> b) -> t1 a -> t1 b
- or the inferred type of z :: [t1 t]
- In the expression: fmap
- In a stmt of a monad comprehension: then group by x using take
- In the expression: [x | x <- [1 .. 10], then group by x using take]
+ • No instance for (Functor t1) arising from a use of ‘fmap’
+ Possible fix:
+ add (Functor t1) to the context of
+ a type expected by the context:
+ (a -> b) -> t1 a -> t1 b
+ or the inferred type of z :: [t1 t]
+ • In the expression: fmap
+ In a stmt of a monad comprehension: then group by x using take
+ In the expression: [x | x <- [1 .. 10], then group by x using take]
mc25.hs:9:46: error:
- Couldn't match type ‘a -> t’ with ‘Int’
- Expected type: (a -> t) -> [a] -> [t1 a]
- Actual type: Int -> [t1 a] -> [t1 a]
- In the expression: take
- In a stmt of a monad comprehension: then group by x using take
- Relevant bindings include z :: [t1 t] (bound at mc25.hs:9:1)
+ • Couldn't match type ‘a -> t’ with ‘Int’
+ Expected type: (a -> t) -> [a] -> [t1 a]
+ Actual type: Int -> [t1 a] -> [t1 a]
+ • In the expression: take
+ In a stmt of a monad comprehension: then group by x using take
+ In the expression: [x | x <- [1 .. 10], then group by x using take]
+ • Relevant bindings include z :: [t1 t] (bound at mc25.hs:9:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail001.stderr b/testsuite/tests/typecheck/should_fail/tcfail001.stderr
index b30d995455..0b0a799c04 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail001.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail001.stderr
@@ -1,7 +1,8 @@
-tcfail001.hs:9:2:
- Couldn't match expected type ‘[t0] -> [t1]’ with actual type ‘[a]’
- The equation(s) for ‘op’ have one argument,
- but its type ‘[a]’ has none
- In the instance declaration for ‘A [a]’
- Relevant bindings include op :: [a] (bound at tcfail001.hs:9:2)
+tcfail001.hs:9:2: error:
+ • Couldn't match expected type ‘[a]’
+ with actual type ‘[t0] -> [t1]’
+ • The equation(s) for ‘op’ have one argument,
+ but its type ‘[a]’ has none
+ In the instance declaration for ‘A [a]’
+ • Relevant bindings include op :: [a] (bound at tcfail001.hs:9:2)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail002.stderr b/testsuite/tests/typecheck/should_fail/tcfail002.stderr
index 285b6bf577..6755636682 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail002.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail002.stderr
@@ -1,8 +1,8 @@
tcfail002.hs:4:7: error:
- • Occurs check: cannot construct the infinite type: r ~ [r]
+ • Occurs check: cannot construct the infinite type: t ~ [t]
• In the expression: z
In an equation for ‘c’: c z = z
• Relevant bindings include
- z :: [r] (bound at tcfail002.hs:4:3)
- c :: [r] -> r (bound at tcfail002.hs:3:1)
+ z :: [t] (bound at tcfail002.hs:4:3)
+ c :: [t] -> t (bound at tcfail002.hs:3:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail004.stderr b/testsuite/tests/typecheck/should_fail/tcfail004.stderr
index 2294a6166f..c575129cf5 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail004.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail004.stderr
@@ -1,9 +1,9 @@
tcfail004.hs:3:9: error:
- • Couldn't match expected type ‘(r, r1)’
+ • Couldn't match expected type ‘(t, t1)’
with actual type ‘(Integer, Integer, Integer)’
• In the expression: (1, 2, 3)
In a pattern binding: (f, g) = (1, 2, 3)
• Relevant bindings include
- f :: r (bound at tcfail004.hs:3:2)
- g :: r1 (bound at tcfail004.hs:3:4)
+ f :: t (bound at tcfail004.hs:3:2)
+ g :: t1 (bound at tcfail004.hs:3:4)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail005.stderr b/testsuite/tests/typecheck/should_fail/tcfail005.stderr
index 4c585af3da..77437cf583 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail005.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail005.stderr
@@ -1,9 +1,9 @@
tcfail005.hs:3:9: error:
- • Couldn't match expected type ‘[r]’
+ • Couldn't match expected type ‘[t]’
with actual type ‘(Integer, Char)’
• In the expression: (1, 'a')
In a pattern binding: (h : i) = (1, 'a')
• Relevant bindings include
- h :: r (bound at tcfail005.hs:3:2)
- i :: [r] (bound at tcfail005.hs:3:4)
+ h :: t (bound at tcfail005.hs:3:2)
+ i :: [t] (bound at tcfail005.hs:3:4)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail007.stderr b/testsuite/tests/typecheck/should_fail/tcfail007.stderr
index 5ea9792256..4c1652fe50 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail007.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail007.stderr
@@ -1,8 +1,8 @@
-tcfail007.hs:3:15:
- No instance for (Num Bool) arising from a use of ‘+’
- In the expression: x + 1
- In an equation for ‘n’:
- n x
- | True = x + 1
- | False = True
+tcfail007.hs:3:14: error:
+ • No instance for (Num Bool) arising from a use of ‘+’
+ • In the expression: x + 1
+ In an equation for ‘n’:
+ n x
+ | True = x + 1
+ | False = True
diff --git a/testsuite/tests/typecheck/should_fail/tcfail010.stderr b/testsuite/tests/typecheck/should_fail/tcfail010.stderr
index 92ee3d8f8e..c22a05e777 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail010.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail010.stderr
@@ -1,6 +1,6 @@
-tcfail010.hs:3:17:
- No instance for (Num [r0]) arising from a use of ‘+’
- In the expression: z + 2
- In the expression: \ (y : z) -> z + 2
- In an equation for ‘q’: q = \ (y : z) -> z + 2
+tcfail010.hs:3:16: error:
+ • No instance for (Num [t0]) arising from a use of ‘+’
+ • In the expression: z + 2
+ In the expression: \ (y : z) -> z + 2
+ In an equation for ‘q’: q = \ (y : z) -> z + 2
diff --git a/testsuite/tests/typecheck/should_fail/tcfail013.stderr b/testsuite/tests/typecheck/should_fail/tcfail013.stderr
index 332f10e729..ff7702213c 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail013.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail013.stderr
@@ -1,7 +1,7 @@
tcfail013.hs:4:3: error:
- • Couldn't match expected type ‘[r]’ with actual type ‘Bool’
+ • Couldn't match expected type ‘[t1]’ with actual type ‘Bool’
• In the pattern: True
In an equation for ‘f’: f True = 2
• Relevant bindings include
- f :: [r] -> a (bound at tcfail013.hs:3:1)
+ f :: [t1] -> t (bound at tcfail013.hs:3:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail014.stderr b/testsuite/tests/typecheck/should_fail/tcfail014.stderr
index 92307b3830..6b88e835ed 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail014.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail014.stderr
@@ -3,6 +3,7 @@ tcfail014.hs:5:33: error:
• Occurs check: cannot construct the infinite type: r8 ~ r8 -> r7
• In the first argument of ‘z’, namely ‘z’
In the expression: z z
+ In an equation for ‘h’: h z = z z
• Relevant bindings include
z :: r8 -> r7 (bound at tcfail014.hs:5:27)
h :: (r8 -> r7) -> r7 (bound at tcfail014.hs:5:25)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail016.stderr b/testsuite/tests/typecheck/should_fail/tcfail016.stderr
index 59c8fa4e3d..cb1fa945e7 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail016.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail016.stderr
@@ -1,22 +1,24 @@
-tcfail016.hs:9:20:
- Couldn't match type ‘(t, Expr t)’ with ‘Expr t’
- Expected type: Expr t
- Actual type: AnnExpr t
- In the first argument of ‘g’, namely ‘e1’
- In the first argument of ‘(++)’, namely ‘(g e1)’
- Relevant bindings include
- e2 :: AnnExpr t (bound at tcfail016.hs:9:11)
- e1 :: AnnExpr t (bound at tcfail016.hs:9:8)
- g :: Expr t -> [[Char]] (bound at tcfail016.hs:8:1)
+tcfail016.hs:9:20: error:
+ • Couldn't match type ‘(t, Expr t)’ with ‘Expr t’
+ Expected type: Expr t
+ Actual type: AnnExpr t
+ • In the first argument of ‘g’, namely ‘e1’
+ In the first argument of ‘(++)’, namely ‘(g e1)’
+ In the expression: (g e1) ++ (g e2)
+ • Relevant bindings include
+ e2 :: AnnExpr t (bound at tcfail016.hs:9:11)
+ e1 :: AnnExpr t (bound at tcfail016.hs:9:8)
+ g :: Expr t -> [[Char]] (bound at tcfail016.hs:8:1)
-tcfail016.hs:9:28:
- Couldn't match type ‘(t, Expr t)’ with ‘Expr t’
- Expected type: Expr t
- Actual type: AnnExpr t
- In the first argument of ‘g’, namely ‘e2’
- In the second argument of ‘(++)’, namely ‘(g e2)’
- Relevant bindings include
- e2 :: AnnExpr t (bound at tcfail016.hs:9:11)
- e1 :: AnnExpr t (bound at tcfail016.hs:9:8)
- g :: Expr t -> [[Char]] (bound at tcfail016.hs:8:1)
+tcfail016.hs:9:28: error:
+ • Couldn't match type ‘(t, Expr t)’ with ‘Expr t’
+ Expected type: Expr t
+ Actual type: AnnExpr t
+ • In the first argument of ‘g’, namely ‘e2’
+ In the second argument of ‘(++)’, namely ‘(g e2)’
+ In the expression: (g e1) ++ (g e2)
+ • Relevant bindings include
+ e2 :: AnnExpr t (bound at tcfail016.hs:9:11)
+ e1 :: AnnExpr t (bound at tcfail016.hs:9:8)
+ g :: Expr t -> [[Char]] (bound at tcfail016.hs:8:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail018.stderr b/testsuite/tests/typecheck/should_fail/tcfail018.stderr
index 88c08a8a8b..57060a87db 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail018.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail018.stderr
@@ -1,5 +1,5 @@
-tcfail018.hs:5:10:
- No instance for (Num [r0]) arising from the literal ‘1’
- In the expression: 1
- In a pattern binding: (a : []) = 1
+tcfail018.hs:5:10: error:
+ • No instance for (Num [t0]) arising from the literal ‘1’
+ • In the expression: 1
+ In a pattern binding: (a : []) = 1
diff --git a/testsuite/tests/typecheck/should_fail/tcfail029.stderr b/testsuite/tests/typecheck/should_fail/tcfail029.stderr
index 5b794458e8..c31c5869b9 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail029.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail029.stderr
@@ -1,5 +1,5 @@
-tcfail029.hs:6:9:
- No instance for (Ord Foo) arising from a use of ‘>’
- In the expression: x > Bar
- In an equation for ‘f’: f x = x > Bar
+tcfail029.hs:6:7: error:
+ • No instance for (Ord Foo) arising from a use of ‘>’
+ • In the expression: x > Bar
+ In an equation for ‘f’: f x = x > Bar
diff --git a/testsuite/tests/typecheck/should_fail/tcfail032.stderr b/testsuite/tests/typecheck/should_fail/tcfail032.stderr
index 05d33a5e05..79ec408274 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail032.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail032.stderr
@@ -10,4 +10,4 @@ tcfail032.hs:14:8: error:
In an equation for ‘f’: f x = (x :: (Eq a) => a -> Int)
• Relevant bindings include
x :: r (bound at tcfail032.hs:14:3)
- f :: r -> a -> Int (bound at tcfail032.hs:14:1)
+ f :: r -> forall a. Eq a => a -> Int (bound at tcfail032.hs:14:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail033.stderr b/testsuite/tests/typecheck/should_fail/tcfail033.stderr
index fd2887de60..94e998f05f 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail033.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail033.stderr
@@ -1,9 +1,10 @@
-tcfail033.hs:4:12:
- Occurs check: cannot construct the infinite type: t ~ (t, t1)
- In the expression: x
- In the expression: [x | (x, y) <- buglet]
- Relevant bindings include
- y :: t1 (bound at tcfail033.hs:4:19)
- x :: t (bound at tcfail033.hs:4:17)
- buglet :: [(t, t1)] (bound at tcfail033.hs:4:1)
+tcfail033.hs:4:12: error:
+ • Occurs check: cannot construct the infinite type: t ~ (t, t1)
+ • In the expression: x
+ In the expression: [x | (x, y) <- buglet]
+ In an equation for ‘buglet’: buglet = [x | (x, y) <- buglet]
+ • Relevant bindings include
+ y :: t1 (bound at tcfail033.hs:4:19)
+ x :: t (bound at tcfail033.hs:4:17)
+ buglet :: [(t, t1)] (bound at tcfail033.hs:4:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail034.stderr b/testsuite/tests/typecheck/should_fail/tcfail034.stderr
index 1a8d6d7802..baf68da924 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail034.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail034.stderr
@@ -1,14 +1,14 @@
-
-tcfail034.hs:17:13: error:
- Could not deduce (Integral a) arising from a use of ‘mod’
- from the context: (Num a, Eq a)
- bound by the type signature for:
- test :: (Num a, Eq a) => a -> Bool
- at tcfail034.hs:16:1-32
- Possible fix:
- add (Integral a) to the context of
- the type signature for:
- test :: (Num a, Eq a) => a -> Bool
- In the first argument of ‘(==)’, namely ‘(x `mod` 3)’
- In the expression: (x `mod` 3) == 0
- In an equation for ‘test’: test x = (x `mod` 3) == 0
+
+tcfail034.hs:17:11: error:
+ • Could not deduce (Integral a) arising from a use of ‘mod’
+ from the context: (Num a, Eq a)
+ bound by the type signature for:
+ test :: (Num a, Eq a) => a -> Bool
+ at tcfail034.hs:16:1-32
+ Possible fix:
+ add (Integral a) to the context of
+ the type signature for:
+ test :: (Num a, Eq a) => a -> Bool
+ • In the first argument of ‘(==)’, namely ‘(x `mod` 3)’
+ In the expression: (x `mod` 3) == 0
+ In an equation for ‘test’: test x = (x `mod` 3) == 0
diff --git a/testsuite/tests/typecheck/should_fail/tcfail065.stderr b/testsuite/tests/typecheck/should_fail/tcfail065.stderr
index 65befaf29e..369b0807d7 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail065.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail065.stderr
@@ -1,14 +1,17 @@
-tcfail065.hs:29:20: error:
- • Couldn't match expected type ‘x’ with actual type ‘x1’
+tcfail065.hs:29:18: error:
+ • Couldn't match type ‘x1’ with ‘x’
‘x1’ is a rigid type variable bound by
the type signature for:
setX :: forall x1. x1 -> X x -> X x
at tcfail065.hs:29:3
‘x’ is a rigid type variable bound by
the instance declaration at tcfail065.hs:28:10
- • In the first argument of ‘X’, namely ‘x’
- In the expression: X x
+ Expected type: X x
+ Actual type: X x1
+ • In the expression: X x
+ In an equation for ‘setX’: setX x (X _) = X x
+ In the instance declaration for ‘HasX (X x)’
• Relevant bindings include
x :: x1 (bound at tcfail065.hs:29:8)
setX :: x1 -> X x -> X x (bound at tcfail065.hs:29:3)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail068.stderr b/testsuite/tests/typecheck/should_fail/tcfail068.stderr
index 5ca47f52ed..eb42f9a33b 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail068.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail068.stderr
@@ -16,11 +16,13 @@ tcfail068.hs:14:9: error:
• In the first argument of ‘runST’, namely
‘(newSTArray ((1, 1), n) x)’
In the expression: runST (newSTArray ((1, 1), n) x)
+ In an equation for ‘itgen’:
+ itgen n x = runST (newSTArray ((1, 1), n) x)
• Relevant bindings include
itgen :: (Int, Int) -> a -> IndTree s a
(bound at tcfail068.hs:12:1)
-tcfail068.hs:19:21: error:
+tcfail068.hs:19:9: error:
• Couldn't match type ‘s’ with ‘s1’
‘s’ is a rigid type variable bound by
the type signature for:
@@ -32,10 +34,20 @@ tcfail068.hs:19:21: error:
a type expected by the context:
forall s1. GHC.ST.ST s1 (IndTree s a)
at tcfail068.hs:18:9
- Expected type: STArray s1 (Int, Int) a
- Actual type: IndTree s a
- • In the first argument of ‘readSTArray’, namely ‘arr’
- In the first argument of ‘(>>=)’, namely ‘readSTArray arr i’
+ Expected type: GHC.ST.ST s1 (IndTree s a)
+ Actual type: GHC.ST.ST s (IndTree s a)
+ • In the first argument of ‘runST’, namely
+ ‘(readSTArray arr i
+ >>= \ val -> writeSTArray arr i (f val) >> return arr)’
+ In the expression:
+ runST
+ (readSTArray arr i
+ >>= \ val -> writeSTArray arr i (f val) >> return arr)
+ In an equation for ‘itiap’:
+ itiap i f arr
+ = runST
+ (readSTArray arr i
+ >>= \ val -> writeSTArray arr i (f val) >> return arr)
• Relevant bindings include
arr :: IndTree s a (bound at tcfail068.hs:17:11)
itiap :: (Int, Int) -> (a -> a) -> IndTree s a -> IndTree s a
@@ -57,6 +69,17 @@ tcfail068.hs:24:36: error:
Actual type: GHC.ST.ST s (IndTree s a)
• In the first argument of ‘runST’, namely ‘(itrap' i k)’
In the expression: runST (itrap' i k)
+ In an equation for ‘itrap’:
+ itrap ((i, k), (j, l)) f arr
+ = runST (itrap' i k)
+ where
+ itrap' i k
+ = if k > l then return arr else (itrapsnd i k >> itrap' i (k + 1))
+ itrapsnd i k
+ = if i > j then
+ return arr
+ else
+ (readSTArray arr (i, k) >>= \ val -> ...)
• Relevant bindings include
itrap' :: Int -> Int -> GHC.ST.ST s (IndTree s a)
(bound at tcfail068.hs:26:9)
@@ -89,6 +112,20 @@ tcfail068.hs:36:46: error:
Actual type: GHC.ST.ST s (c, IndTree s b)
• In the first argument of ‘runST’, namely ‘(itrapstate' i k s)’
In the expression: runST (itrapstate' i k s)
+ In an equation for ‘itrapstate’:
+ itrapstate ((i, k), (j, l)) f c d s arr
+ = runST (itrapstate' i k s)
+ where
+ itrapstate' i k s
+ = if k > l then
+ return (s, arr)
+ else
+ (itrapstatesnd i k s >>= \ (s, arr) -> ...)
+ itrapstatesnd i k s
+ = if i > j then
+ return (s, arr)
+ else
+ (readSTArray arr (i, k) >>= \ val -> ...)
• Relevant bindings include
itrapstate' :: Int -> Int -> c -> GHC.ST.ST s (c, IndTree s b)
(bound at tcfail068.hs:38:9)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail076.stderr b/testsuite/tests/typecheck/should_fail/tcfail076.stderr
index 8283ef0458..242c62235e 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail076.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail076.stderr
@@ -13,6 +13,7 @@ tcfail076.hs:18:82: error:
Actual type: m res
• In the expression: cont a
In the first argument of ‘KContT’, namely ‘(\ cont' -> cont a)’
+ In the expression: KContT (\ cont' -> cont a)
• Relevant bindings include
cont' :: b -> m res1 (bound at tcfail076.hs:18:73)
cont :: a -> m res (bound at tcfail076.hs:18:37)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail099.stderr b/testsuite/tests/typecheck/should_fail/tcfail099.stderr
index 687fafb6da..3ba8165766 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail099.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail099.stderr
@@ -8,6 +8,7 @@ tcfail099.hs:9:20: error:
at tcfail099.hs:9:7-9
• In the first argument of ‘f’, namely ‘arg’
In the expression: f arg
+ In an equation for ‘call’: call (C f) arg = f arg
• Relevant bindings include
arg :: r (bound at tcfail099.hs:9:12)
f :: a -> Int (bound at tcfail099.hs:9:9)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail103.stderr b/testsuite/tests/typecheck/should_fail/tcfail103.stderr
index 627ef1158c..2d76dc588a 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail103.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail103.stderr
@@ -1,19 +1,24 @@
-
-tcfail103.hs:15:23: error:
- Couldn't match type ‘t’ with ‘s’
- ‘t’ is a rigid type variable bound by
- the type signature for:
- f :: forall t. ST t Int
- at tcfail103.hs:10:5
- ‘s’ is a rigid type variable bound by
- the type signature for:
- g :: forall s. ST s Int
- at tcfail103.hs:13:14
- Expected type: STRef s Int
- Actual type: STRef t Int
- In the first argument of ‘readSTRef’, namely ‘v’
- In the expression: readSTRef v
- Relevant bindings include
- g :: ST s Int (bound at tcfail103.hs:15:9)
- v :: STRef t Int (bound at tcfail103.hs:12:5)
- f :: ST t Int (bound at tcfail103.hs:11:1)
+
+tcfail103.hs:15:13: error:
+ • Couldn't match type ‘t’ with ‘s’
+ ‘t’ is a rigid type variable bound by
+ the type signature for:
+ f :: forall t. ST t Int
+ at tcfail103.hs:10:5
+ ‘s’ is a rigid type variable bound by
+ the type signature for:
+ g :: forall s. ST s Int
+ at tcfail103.hs:13:14
+ Expected type: ST s Int
+ Actual type: ST t Int
+ • In the expression: readSTRef v
+ In an equation for ‘g’: g = readSTRef v
+ In the expression:
+ do { v <- newSTRef 5;
+ let g :: ST s Int
+ g = readSTRef v;
+ g }
+ • Relevant bindings include
+ g :: ST s Int (bound at tcfail103.hs:15:9)
+ v :: STRef t Int (bound at tcfail103.hs:12:5)
+ f :: ST t Int (bound at tcfail103.hs:11:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail104.stderr b/testsuite/tests/typecheck/should_fail/tcfail104.stderr
index cb14d9af26..b6c21e5e82 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail104.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail104.stderr
@@ -1,12 +1,16 @@
-tcfail104.hs:16:19:
- Couldn't match expected type ‘Char -> Char’
- with actual type ‘forall a. a -> a’
- In the expression: x
- In the expression: (\ x -> x)
+tcfail104.hs:14:15: error:
+ • Couldn't match expected type ‘forall a. a -> a’
+ with actual type ‘Char -> Char’
+ • When checking that the pattern signature: forall a. a -> a
+ fits the type of its context: Char -> Char
+ In the pattern: x :: forall a. a -> a
+ In the expression: (\ (x :: forall a. a -> a) -> x)
-tcfail104.hs:22:39:
- Couldn't match expected type ‘forall a. a -> a’
- with actual type ‘a0 -> a0’
- In the expression: x
- In the expression: (\ (x :: forall a. a -> a) -> x)
+tcfail104.hs:22:15: error:
+ • Couldn't match expected type ‘forall a. a -> a’
+ with actual type ‘Char -> Char’
+ • When checking that the pattern signature: forall a. a -> a
+ fits the type of its context: Char -> Char
+ In the pattern: x :: forall a. a -> a
+ In the expression: (\ (x :: forall a. a -> a) -> x)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail131.stderr b/testsuite/tests/typecheck/should_fail/tcfail131.stderr
index 03bdc72eff..2ae70a0928 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail131.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail131.stderr
@@ -1,11 +1,12 @@
-tcfail131.hs:7:9: error:
- • Couldn't match expected type ‘b’ with actual type ‘Integer’
+tcfail131.hs:7:11: error:
+ • Couldn't match expected type ‘Integer’ with actual type ‘b’
‘b’ is a rigid type variable bound by
the type signature for:
g :: forall b. Num b => b -> b
at tcfail131.hs:6:8
- • In the expression: f x x
+ • In the first argument of ‘f’, namely ‘x’
+ In the expression: f x x
In an equation for ‘g’: g x = f x x
• Relevant bindings include
x :: b (bound at tcfail131.hs:7:5)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail133.stderr b/testsuite/tests/typecheck/should_fail/tcfail133.stderr
index ac85d0be71..a178f02801 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail133.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail133.stderr
@@ -14,8 +14,7 @@ tcfail133.hs:68:7: error:
...plus 25 others
...plus three instance involving out-of-scope typess
(use -fprint-potential-instances to see them all)
- • In the expression: show
- In the expression: show $ add (One :@ Zero) (One :@ One)
+ • In the expression: show $ add (One :@ Zero) (One :@ One)
In an equation for ‘foo’:
foo = show $ add (One :@ Zero) (One :@ One)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail140.stderr b/testsuite/tests/typecheck/should_fail/tcfail140.stderr
index 41268ec6df..b3bf602200 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail140.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail140.stderr
@@ -19,14 +19,14 @@ tcfail140.hs:12:10: error:
rot :: r -> t (bound at tcfail140.hs:12:1)
tcfail140.hs:14:15: error:
- • Couldn't match expected type ‘a -> b’ with actual type ‘Int’
+ • Couldn't match expected type ‘t -> b’ with actual type ‘Int’
• The operator ‘f’ takes two arguments,
but its type ‘Int -> Int’ has only one
In the first argument of ‘map’, namely ‘(3 `f`)’
In the expression: map (3 `f`) xs
• Relevant bindings include
- xs :: [a] (bound at tcfail140.hs:14:5)
- bot :: [a] -> [b] (bound at tcfail140.hs:14:1)
+ xs :: [t] (bound at tcfail140.hs:14:5)
+ bot :: [t] -> [b] (bound at tcfail140.hs:14:1)
tcfail140.hs:16:8: error:
• The constructor ‘Just’ should have 1 argument, but has been given none
@@ -35,6 +35,6 @@ tcfail140.hs:16:8: error:
In the expression: ((\ Just x -> x) :: Maybe a -> a) (Just 1)
tcfail140.hs:19:1: error:
- • Couldn't match expected type ‘t0 -> Bool’ with actual type ‘Int’
+ • Couldn't match expected type ‘Int’ with actual type ‘t0 -> Bool’
• The equation(s) for ‘g’ have two arguments,
but its type ‘Int -> Int’ has only one
diff --git a/testsuite/tests/typecheck/should_fail/tcfail143.stderr b/testsuite/tests/typecheck/should_fail/tcfail143.stderr
index 14c73d98da..b94266978d 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail143.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail143.stderr
@@ -1,8 +1,8 @@
-tcfail143.hs:29:9: error:
- Couldn't match type ‘S Z’ with ‘Z’
- arising from a functional dependency between:
- constraint ‘MinMax (S Z) Z Z Z’ arising from a use of ‘extend’
- instance ‘MinMax a Z Z a’ at tcfail143.hs:11:10-23
- In the expression: n1 `extend` n0
- In an equation for ‘t2’: t2 = n1 `extend` n0
+tcfail143.hs:29:6: error:
+ • Couldn't match type ‘S Z’ with ‘Z’
+ arising from a functional dependency between:
+ constraint ‘MinMax (S Z) Z Z Z’ arising from a use of ‘extend’
+ instance ‘MinMax a Z Z a’ at tcfail143.hs:11:10-23
+ • In the expression: n1 `extend` n0
+ In an equation for ‘t2’: t2 = n1 `extend` n0
diff --git a/testsuite/tests/typecheck/should_fail/tcfail153.stderr b/testsuite/tests/typecheck/should_fail/tcfail153.stderr
index 8034a804fc..5f4ec3e013 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail153.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail153.stderr
@@ -1,18 +1,17 @@
-
-tcfail153.hs:6:7: error:
- Couldn't match type ‘a’ with ‘Bool’
- ‘a’ is a rigid type variable bound by
- the type signature for:
- f :: forall a. a -> [a]
- at tcfail153.hs:5:6
- Expected type: [a]
- Actual type: [Bool]
- In the expression: g x
- In an equation for ‘f’:
- f x
- = g x
- where
- g y = if y then [] else [...]
- Relevant bindings include
- x :: a (bound at tcfail153.hs:6:3)
- f :: a -> [a] (bound at tcfail153.hs:6:1)
+
+tcfail153.hs:6:9: error:
+ • Couldn't match expected type ‘Bool’ with actual type ‘a’
+ ‘a’ is a rigid type variable bound by
+ the type signature for:
+ f :: forall a. a -> [a]
+ at tcfail153.hs:5:6
+ • In the first argument of ‘g’, namely ‘x’
+ In the expression: g x
+ In an equation for ‘f’:
+ f x
+ = g x
+ where
+ g y = if y then [] else [...]
+ • Relevant bindings include
+ x :: a (bound at tcfail153.hs:6:3)
+ f :: a -> [a] (bound at tcfail153.hs:6:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail165.hs b/testsuite/tests/typecheck/should_fail/tcfail165.hs
index c23a7f39b4..8b4cabdc8e 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail165.hs
+++ b/testsuite/tests/typecheck/should_fail/tcfail165.hs
@@ -11,6 +11,7 @@ import Control.Concurrent
--
-- In GHC 7.0 it fails again! (and rightly so)
+-- With the Visible Type Application patch, this succeeds again.
+
foo = do var <- newEmptyMVar :: IO (MVar (forall a. Show a => a -> String))
putMVar var (show :: forall b. Show b => b -> String)
-
diff --git a/testsuite/tests/typecheck/should_fail/tcfail165.stderr b/testsuite/tests/typecheck/should_fail/tcfail165.stderr
deleted file mode 100644
index 2b8b434385..0000000000
--- a/testsuite/tests/typecheck/should_fail/tcfail165.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-
-tcfail165.hs:15:23:
- Couldn't match expected type ‘forall a. Show a => a -> String’
- with actual type ‘b0 -> String’
- In the second argument of ‘putMVar’, namely
- ‘(show :: forall b. Show b => b -> String)’
- In a stmt of a 'do' block:
- putMVar var (show :: forall b. Show b => b -> String)
- In the expression:
- do { var <- newEmptyMVar ::
- IO (MVar (forall a. Show a => a -> String));
- putMVar var (show :: forall b. Show b => b -> String) }
diff --git a/testsuite/tests/typecheck/should_fail/tcfail168.stderr b/testsuite/tests/typecheck/should_fail/tcfail168.stderr
index e8c6c313e1..5f4656b13f 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail168.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail168.stderr
@@ -1,12 +1,18 @@
-tcfail168.hs:7:11:
- Couldn't match expected type ‘IO a0’
- with actual type ‘Char -> IO ()’
- Probable cause: ‘putChar’ is applied to too few arguments
- In a stmt of a 'do' block: putChar
- In the expression:
- do { putChar;
- putChar 'a';
- putChar 'a';
- putChar 'a';
- .... }
+tcfail168.hs:7:11: error:
+ • Couldn't match expected type ‘IO a0’
+ with actual type ‘Char -> IO ()’
+ • Probable cause: ‘putChar’ is applied to too few arguments
+ In a stmt of a 'do' block: putChar
+ In the expression:
+ do { putChar;
+ putChar 'a';
+ putChar 'a';
+ putChar 'a';
+ .... }
+ In an equation for ‘foo’:
+ foo
+ = do { putChar;
+ putChar 'a';
+ putChar 'a';
+ .... }
diff --git a/testsuite/tests/typecheck/should_fail/tcfail174.hs b/testsuite/tests/typecheck/should_fail/tcfail174.hs
index 47c63d7248..41fc18fc66 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail174.hs
+++ b/testsuite/tests/typecheck/should_fail/tcfail174.hs
@@ -7,6 +7,7 @@ data Capture a = Base a
g :: Capture (forall a . a -> a)
g = Base id -- Fails; need a rigid signature on 'id'
+ -- Actually, succeeds now, with visible type application
-- This function should definitely be rejected, with or without type signature
@@ -14,4 +15,3 @@ h1 = Capture g
h2 :: Capture b
h2 = Capture g
-
diff --git a/testsuite/tests/typecheck/should_fail/tcfail174.stderr b/testsuite/tests/typecheck/should_fail/tcfail174.stderr
index fec5748461..e7ad3ca813 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail174.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail174.stderr
@@ -1,35 +1,30 @@
-
-tcfail174.hs:9:10: error:
- Couldn't match expected type ‘forall a. a -> a’
- with actual type ‘a0 -> a0’
- In the first argument of ‘Base’, namely ‘id’
- In the expression: Base id
-
-tcfail174.hs:13:14: error:
- Couldn't match type ‘a’ with ‘a1’
- because type variable ‘a1’ would escape its scope
- This (rigid, skolem) type variable is bound by
- the type forall a2. a2 -> a2
- at tcfail174.hs:13:1-14
- Expected type: Capture (forall x. x -> a)
- Actual type: Capture (forall a. a -> a)
- In the first argument of ‘Capture’, namely ‘g’
- In the expression: Capture g
- Relevant bindings include
- h1 :: Capture a (bound at tcfail174.hs:13:1)
-
-tcfail174.hs:16:14: error:
- Couldn't match type ‘a’ with ‘b’
- ‘a’ is a rigid type variable bound by
- the type forall a1. a1 -> a1
- at tcfail174.hs:1:1
- ‘b’ is a rigid type variable bound by
- the type signature for:
- h2 :: forall b. Capture b
- at tcfail174.hs:15:7
- Expected type: Capture (forall x. x -> b)
- Actual type: Capture (forall a. a -> a)
- In the first argument of ‘Capture’, namely ‘g’
- In the expression: Capture g
- Relevant bindings include
- h2 :: Capture b (bound at tcfail174.hs:16:1)
+
+tcfail174.hs:14:14: error:
+ • Couldn't match type ‘a’ with ‘a1’
+ because type variable ‘a1’ would escape its scope
+ This (rigid, skolem) type variable is bound by
+ the type forall a2. a2 -> a2
+ at tcfail174.hs:14:1-14
+ Expected type: Capture (forall x. x -> a)
+ Actual type: Capture (forall a. a -> a)
+ • In the first argument of ‘Capture’, namely ‘g’
+ In the expression: Capture g
+ In an equation for ‘h1’: h1 = Capture g
+ • Relevant bindings include
+ h1 :: Capture a (bound at tcfail174.hs:14:1)
+
+tcfail174.hs:17:14: error:
+ • Couldn't match type ‘a’ with ‘b’
+ ‘a’ is a rigid type variable bound by
+ the type forall a1. a1 -> a1 at tcfail174.hs:1:1
+ ‘b’ is a rigid type variable bound by
+ the type signature for:
+ h2 :: forall b. Capture b
+ at tcfail174.hs:16:7
+ Expected type: Capture (forall x. x -> b)
+ Actual type: Capture (forall a. a -> a)
+ • In the first argument of ‘Capture’, namely ‘g’
+ In the expression: Capture g
+ In an equation for ‘h2’: h2 = Capture g
+ • Relevant bindings include
+ h2 :: Capture b (bound at tcfail174.hs:17:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail175.stderr b/testsuite/tests/typecheck/should_fail/tcfail175.stderr
index 82da98bc0c..c421684b8d 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail175.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail175.stderr
@@ -1,7 +1,7 @@
tcfail175.hs:11:1: error:
- • Couldn't match expected type ‘String -> String -> String’
- with actual type ‘a’
+ • Couldn't match expected type ‘a’
+ with actual type ‘String -> String -> String’
‘a’ is a rigid type variable bound by
the type signature for:
evalRHS :: forall a. Int -> a
diff --git a/testsuite/tests/typecheck/should_fail/tcfail178.stderr b/testsuite/tests/typecheck/should_fail/tcfail178.stderr
index 472e133098..98df425424 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail178.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail178.stderr
@@ -1,14 +1,16 @@
-tcfail178.hs:15:7:
- Couldn't match type ‘()’ with ‘[a]’
- Expected type: Bool -> [a]
- Actual type: Bool -> ()
- In the first argument of ‘a’, namely ‘y’
- In the expression: a y
- Relevant bindings include c :: [a] (bound at tcfail178.hs:15:1)
+tcfail178.hs:15:7: error:
+ • Couldn't match type ‘()’ with ‘[a]’
+ Expected type: Bool -> [a]
+ Actual type: Bool -> ()
+ • In the first argument of ‘a’, namely ‘y’
+ In the expression: a y
+ In an equation for ‘c’: c = a y
+ • Relevant bindings include c :: [a] (bound at tcfail178.hs:15:1)
-tcfail178.hs:18:7:
- Couldn't match expected type ‘Bool -> [a]’ with actual type ‘()’
- In the first argument of ‘a’, namely ‘()’
- In the expression: a ()
- Relevant bindings include d :: [a] (bound at tcfail178.hs:18:1)
+tcfail178.hs:18:7: error:
+ • Couldn't match expected type ‘Bool -> [a]’ with actual type ‘()’
+ • In the first argument of ‘a’, namely ‘()’
+ In the expression: a ()
+ In an equation for ‘d’: d = a ()
+ • Relevant bindings include d :: [a] (bound at tcfail178.hs:18:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail179.stderr b/testsuite/tests/typecheck/should_fail/tcfail179.stderr
index a50e75e6be..2a0a5bf614 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail179.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail179.stderr
@@ -1,6 +1,6 @@
-tcfail179.hs:14:39: error:
- • Couldn't match expected type ‘s’ with actual type ‘x’
+tcfail179.hs:14:41: error:
+ • Couldn't match type ‘x’ with ‘s’
‘x’ is a rigid type variable bound by
a pattern with constructor:
T :: forall s x. (s -> (x -> s) -> (x, s, Int)) -> T s,
@@ -10,10 +10,13 @@ tcfail179.hs:14:39: error:
the type signature for:
run :: forall s. T s -> Int
at tcfail179.hs:12:8
- • In the first argument of ‘g’, namely ‘x’
+ Expected type: x -> s
+ Actual type: s -> s
+ • In the second argument of ‘g’, namely ‘id’
In the expression: g x id
+ In a pattern binding: (x, _, b) = g x id
• Relevant bindings include
- x :: x (bound at tcfail179.hs:14:26)
+ x :: s (bound at tcfail179.hs:14:26)
g :: s -> (x -> s) -> (x, s, Int) (bound at tcfail179.hs:14:16)
ts :: T s (bound at tcfail179.hs:13:5)
run :: T s -> Int (bound at tcfail179.hs:13:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail181.stderr b/testsuite/tests/typecheck/should_fail/tcfail181.stderr
index 18309c10d1..6cf22a9f61 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail181.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail181.stderr
@@ -1,16 +1,17 @@
tcfail181.hs:17:9: error:
- Could not deduce (Monad m0) arising from a use of ‘foo’
- from the context: Monad m
- bound by the inferred type of
- wog :: Monad m => r -> Something (m Bool) e
- at tcfail181.hs:17:1-30
- The type variable ‘m0’ is ambiguous
- These potential instances exist:
- instance Monad IO -- Defined in ‘GHC.Base’
- instance Monad Maybe -- Defined in ‘GHC.Base’
- instance Monad ((->) r) -- Defined in ‘GHC.Base’
- ...plus two others
- (use -fprint-potential-instances to see them all)
- In the expression: foo {bar = return True}
- In an equation for ‘wog’: wog x = foo {bar = return True}
+ • Could not deduce (Monad m0) arising from a use of ‘foo’
+ from the context: Monad m
+ bound by the inferred type of
+ wog :: Monad m => r -> Something (m Bool) e
+ at tcfail181.hs:17:1-30
+ The type variable ‘m0’ is ambiguous
+ These potential instances exist:
+ instance Monad IO -- Defined in ‘GHC.Base’
+ instance Monad Maybe -- Defined in ‘GHC.Base’
+ instance Monad ((->) r) -- Defined in ‘GHC.Base’
+ ...plus two others
+ (use -fprint-potential-instances to see them all)
+ • In the expression: foo
+ In the expression: foo {bar = return True}
+ In an equation for ‘wog’: wog x = foo {bar = return True}
diff --git a/testsuite/tests/typecheck/should_fail/tcfail185.stderr b/testsuite/tests/typecheck/should_fail/tcfail185.stderr
index 785b5d6dd0..f8c3c6cd99 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail185.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail185.stderr
@@ -1,11 +1,17 @@
-tcfail185.hs:7:46:
- Couldn't match expected type ‘Int -> Int’ with actual type ‘Bool’
- In the expression: x
- In the expression:
- let
- y1 = y
- y2 = y1
- y3 = y2
- ....
- in x
+tcfail185.hs:7:46: error:
+ • Couldn't match expected type ‘Int -> Int’ with actual type ‘Bool’
+ • In the expression: x
+ In the expression:
+ let
+ y1 = y
+ y2 = y1
+ y3 = y2
+ ....
+ in x
+ In the expression:
+ \ x y
+ -> let
+ y1 = ...
+ ....
+ in x
diff --git a/testsuite/tests/typecheck/should_fail/tcfail189.stderr b/testsuite/tests/typecheck/should_fail/tcfail189.stderr
index 380b014947..f23243bdd0 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail189.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail189.stderr
@@ -1,8 +1,10 @@
-tcfail189.hs:10:31:
- Couldn't match type ‘[a0]’ with ‘[a] -> [[a]]’
- Expected type: (a -> Integer) -> [a] -> [[a]]
- Actual type: [a0] -> [a0]
- Possible cause: ‘take’ is applied to too many arguments
- In the expression: take 2
- In a stmt of a list comprehension: then group by x using take 2
+tcfail189.hs:10:31: error:
+ • Couldn't match type ‘[a0]’ with ‘[a] -> [[a]]’
+ Expected type: (a -> Integer) -> [a] -> [[a]]
+ Actual type: [a0] -> [a0]
+ • Possible cause: ‘take’ is applied to too many arguments
+ In the expression: take 2
+ In a stmt of a list comprehension: then group by x using take 2
+ In the expression:
+ [length x | x <- [1 .. 10], then group by x using take 2]
diff --git a/testsuite/tests/typecheck/should_fail/tcfail191.stderr b/testsuite/tests/typecheck/should_fail/tcfail191.stderr
index bd1b04ca80..6b338eb5ed 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail191.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail191.stderr
@@ -1,11 +1,13 @@
-
-tcfail191.hs:11:26: error:
- Couldn't match type ‘a’ with ‘[a]’
- ‘a’ is a rigid type variable bound by
- a type expected by the context:
- forall a. [a] -> [[a]]
- at tcfail191.hs:10:9
- Expected type: [a] -> [[a]]
- Actual type: [[a]] -> [[a]]
- In the expression: take 5
- In a stmt of a list comprehension: then group using take 5
+
+tcfail191.hs:11:26: error:
+ • Couldn't match type ‘a’ with ‘[a]’
+ ‘a’ is a rigid type variable bound by
+ a type expected by the context:
+ forall a. [a] -> [[a]]
+ at tcfail191.hs:10:9
+ Expected type: [a] -> [[a]]
+ Actual type: [[a]] -> [[a]]
+ • In the expression: take 5
+ In a stmt of a list comprehension: then group using take 5
+ In the expression:
+ [() | x <- [Gnorf, Brain], then group using take 5]
diff --git a/testsuite/tests/typecheck/should_fail/tcfail193.stderr b/testsuite/tests/typecheck/should_fail/tcfail193.stderr
index bd8ef5348a..4a96fa4aef 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail193.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail193.stderr
@@ -1,11 +1,12 @@
-
-tcfail193.hs:10:31: error:
- Couldn't match type ‘a’ with ‘[a]’
- ‘a’ is a rigid type variable bound by
- a type expected by the context:
- forall a. [a] -> [a]
- at tcfail193.hs:10:10
- Expected type: [a] -> [a]
- Actual type: [a] -> [[a]]
- In the expression: inits
- In a stmt of a list comprehension: then inits
+
+tcfail193.hs:10:31: error:
+ • Couldn't match type ‘a’ with ‘[a]’
+ ‘a’ is a rigid type variable bound by
+ a type expected by the context:
+ forall a. [a] -> [a]
+ at tcfail193.hs:10:10
+ Expected type: [a] -> [a]
+ Actual type: [a] -> [[a]]
+ • In the expression: inits
+ In a stmt of a list comprehension: then inits
+ In the expression: [x | x <- [3, 2, 1], then inits]
diff --git a/testsuite/tests/typecheck/should_fail/tcfail198.stderr b/testsuite/tests/typecheck/should_fail/tcfail198.stderr
index 58cf260593..88469939f3 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail198.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail198.stderr
@@ -1,13 +1,15 @@
-
-tcfail198.hs:6:36: error:
- Couldn't match expected type ‘a2’ with actual type ‘a1’
- because type variable ‘a2’ would escape its scope
- This (rigid, skolem) type variable is bound by
- an expression type signature: a2
- at tcfail198.hs:6:36-41
- In the expression: x :: a
- In the second argument of ‘(++)’, namely ‘[x :: a]’
- Relevant bindings include
- xs :: [a1] (bound at tcfail198.hs:6:21)
- x :: a1 (bound at tcfail198.hs:6:19)
- f3 :: [a1] -> [a1] (bound at tcfail198.hs:6:6)
+
+tcfail198.hs:6:36: error:
+ • Couldn't match expected type ‘a2’ with actual type ‘a1’
+ because type variable ‘a2’ would escape its scope
+ This (rigid, skolem) type variable is bound by
+ an expression type signature:
+ a2
+ at tcfail198.hs:6:36-41
+ • In the expression: x :: a
+ In the second argument of ‘(++)’, namely ‘[x :: a]’
+ In the expression: xs ++ [x :: a]
+ • Relevant bindings include
+ xs :: [a1] (bound at tcfail198.hs:6:21)
+ x :: a1 (bound at tcfail198.hs:6:19)
+ f3 :: [a1] -> [a1] (bound at tcfail198.hs:6:6)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail201.stderr b/testsuite/tests/typecheck/should_fail/tcfail201.stderr
index c19aa0c274..9aef660dbd 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail201.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail201.stderr
@@ -1,14 +1,17 @@
-tcfail201.hs:17:58: error:
- • Couldn't match expected type ‘a’ with actual type ‘HsDoc id0’
+tcfail201.hs:17:56: error:
+ • Couldn't match type ‘a’ with ‘HsDoc id0’
‘a’ is a rigid type variable bound by
the type signature for:
gfoldl' :: forall (c :: * -> *) a.
(forall a1 b. c (a1 -> b) -> a1 -> c b)
-> (forall g. g -> c g) -> a -> c a
at tcfail201.hs:15:12
- • In the first argument of ‘z’, namely ‘DocEmpty’
- In the expression: z DocEmpty
+ Expected type: c a
+ Actual type: c (HsDoc id0)
+ • In the expression: z DocEmpty
+ In a case alternative: DocEmpty -> z DocEmpty
+ In the expression: case hsDoc of { DocEmpty -> z DocEmpty }
• Relevant bindings include
hsDoc :: a (bound at tcfail201.hs:16:13)
gfoldl' :: (forall a1 b. c (a1 -> b) -> a1 -> c b)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail204.stderr b/testsuite/tests/typecheck/should_fail/tcfail204.stderr
index b6ef584387..f4b6ec791b 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail204.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail204.stderr
@@ -4,7 +4,7 @@ tcfail204.hs:10:15: warning:
(Fractional a0)
arising from the literal ‘6.3’ at tcfail204.hs:10:15-17
(RealFrac a0)
- arising from a use of ‘ceiling’ at tcfail204.hs:10:7-13
+ arising from a use of ‘ceiling’ at tcfail204.hs:10:7-17
• In the first argument of ‘ceiling’, namely ‘6.3’
In the expression: ceiling 6.3
In an equation for ‘foo’: foo = ceiling 6.3
diff --git a/testsuite/tests/typecheck/should_fail/tcfail206.stderr b/testsuite/tests/typecheck/should_fail/tcfail206.stderr
index 687619c9eb..e60856aaf9 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail206.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail206.stderr
@@ -1,55 +1,55 @@
-
-tcfail206.hs:5:5: error:
- Couldn't match type ‘Bool’ with ‘Int’
- Expected type: Bool -> (Int, Bool)
- Actual type: Bool -> (Bool, Bool)
- In the expression: (, True)
- In an equation for ‘a’: a = (, True)
-
-tcfail206.hs:8:5: error:
- Couldn't match type ‘(Integer, Int)’ with ‘Bool -> (Int, Bool)’
- Expected type: Int -> Bool -> (Int, Bool)
- Actual type: Int -> (Integer, Int)
- In the expression: (1,)
- In an equation for ‘b’: b = (1,)
-
-tcfail206.hs:11:5: error:
- Couldn't match type ‘a’ with ‘Bool’
- ‘a’ is a rigid type variable bound by
- the type signature for:
- c :: forall a. a -> (a, Bool)
- at tcfail206.hs:10:6
- Expected type: a -> (a, Bool)
- Actual type: a -> (a, a)
- In the expression: (True || False,)
- In an equation for ‘c’: c = (True || False,)
- Relevant bindings include
- c :: a -> (a, Bool) (bound at tcfail206.hs:11:1)
-
-tcfail206.hs:14:5: error:
- Couldn't match type ‘Bool’ with ‘Int’
- Expected type: Bool -> (# Int, Bool #)
- Actual type: Bool -> (# Bool, Bool #)
- In the expression: (# , True #)
- In an equation for ‘d’: d = (# , True #)
-
-tcfail206.hs:17:5: error:
- Couldn't match type ‘(# Integer, Int #)’
- with ‘Bool -> (# Int, Bool #)’
- Expected type: Int -> Bool -> (# Int, Bool #)
- Actual type: Int -> (# Integer, Int #)
- In the expression: (# 1, #)
- In an equation for ‘e’: e = (# 1, #)
-
-tcfail206.hs:20:5: error:
- Couldn't match type ‘a’ with ‘Bool’
- ‘a’ is a rigid type variable bound by
- the type signature for:
- f :: forall a. a -> (# a, Bool #)
- at tcfail206.hs:19:6
- Expected type: a -> (# a, Bool #)
- Actual type: a -> (# a, a #)
- In the expression: (# True || False, #)
- In an equation for ‘f’: f = (# True || False, #)
- Relevant bindings include
- f :: a -> (# a, Bool #) (bound at tcfail206.hs:20:1)
+
+tcfail206.hs:5:5: error:
+ • Couldn't match type ‘Bool’ with ‘Int’
+ Expected type: Bool -> (Int, Bool)
+ Actual type: Int -> (Int, Bool)
+ • In the expression: (, True)
+ In an equation for ‘a’: a = (, True)
+
+tcfail206.hs:8:5: error:
+ • Couldn't match type ‘(Integer, Int)’ with ‘Bool -> (Int, Bool)’
+ Expected type: Int -> Bool -> (Int, Bool)
+ Actual type: Int -> (Integer, Int)
+ • In the expression: (1,)
+ In an equation for ‘b’: b = (1,)
+
+tcfail206.hs:11:5: error:
+ • Couldn't match type ‘a’ with ‘Bool’
+ ‘a’ is a rigid type variable bound by
+ the type signature for:
+ c :: forall a. a -> (a, Bool)
+ at tcfail206.hs:10:6
+ Expected type: a -> (a, Bool)
+ Actual type: Bool -> (a, Bool)
+ • In the expression: (True || False,)
+ In an equation for ‘c’: c = (True || False,)
+ • Relevant bindings include
+ c :: a -> (a, Bool) (bound at tcfail206.hs:11:1)
+
+tcfail206.hs:14:5: error:
+ • Couldn't match type ‘Bool’ with ‘Int’
+ Expected type: Bool -> (# Int, Bool #)
+ Actual type: Int -> (# Int, Bool #)
+ • In the expression: (# , True #)
+ In an equation for ‘d’: d = (# , True #)
+
+tcfail206.hs:17:5: error:
+ • Couldn't match type ‘(# Integer, Int #)’
+ with ‘Bool -> (# Int, Bool #)’
+ Expected type: Int -> Bool -> (# Int, Bool #)
+ Actual type: Int -> (# Integer, Int #)
+ • In the expression: (# 1, #)
+ In an equation for ‘e’: e = (# 1, #)
+
+tcfail206.hs:20:5: error:
+ • Couldn't match type ‘a’ with ‘Bool’
+ ‘a’ is a rigid type variable bound by
+ the type signature for:
+ f :: forall a. a -> (# a, Bool #)
+ at tcfail206.hs:19:6
+ Expected type: a -> (# a, Bool #)
+ Actual type: Bool -> (# a, Bool #)
+ • In the expression: (# True || False, #)
+ In an equation for ‘f’: f = (# True || False, #)
+ • Relevant bindings include
+ f :: a -> (# a, Bool #) (bound at tcfail206.hs:20:1)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail208.stderr b/testsuite/tests/typecheck/should_fail/tcfail208.stderr
index dd290d942c..45642a7548 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail208.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail208.stderr
@@ -1,9 +1,9 @@
-
-tcfail208.hs:4:19: error:
- Could not deduce (Eq (m a)) arising from a use of ‘==’
- from the context: (Monad m, Eq a)
- bound by the type signature for:
- f :: (Monad m, Eq a) => a -> m a -> Bool
- at tcfail208.hs:3:1-40
- In the expression: (return x == y)
- In an equation for ‘f’: f x y = (return x == y)
+
+tcfail208.hs:4:10: error:
+ • Could not deduce (Eq (m a)) arising from a use of ‘==’
+ from the context: (Monad m, Eq a)
+ bound by the type signature for:
+ f :: (Monad m, Eq a) => a -> m a -> Bool
+ at tcfail208.hs:3:1-40
+ • In the expression: (return x == y)
+ In an equation for ‘f’: f x y = (return x == y)
diff --git a/testsuite/tests/typecheck/should_run/all.T b/testsuite/tests/typecheck/should_run/all.T
index 138ac58ecc..031dad6321 100755
--- a/testsuite/tests/typecheck/should_run/all.T
+++ b/testsuite/tests/typecheck/should_run/all.T
@@ -50,7 +50,7 @@ test('tcrun031', normal, compile_and_run, [''])
test('tcrun032', normal, compile_and_run, [''])
test('tcrun033', normal, compile_and_run, [''])
test('tcrun034', normal, compile_and_run, [''])
-test('tcrun035', normal, compile_fail, [''])
+test('tcrun035', normal, compile_and_run, [''])
test('tcrun036', normal, compile_and_run, [''])
test('tcrun037', normal, compile_and_run, [''])
diff --git a/testsuite/tests/typecheck/should_run/tcrun035.stderr b/testsuite/tests/typecheck/should_run/tcrun035.stderr
deleted file mode 100644
index c72ef618ab..0000000000
--- a/testsuite/tests/typecheck/should_run/tcrun035.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-
-tcrun035.hs:13:7:
- Couldn't match type ‘IO a’
- with ‘forall (m :: * -> *). Monad m => m a’
- Expected type: (forall (m :: * -> *). Monad m => m a) -> IO a
- Actual type: IO a -> IO a
- In the expression: id . id
- In an equation for ‘foo’: foo = id . id
- Relevant bindings include
- foo :: (forall (m :: * -> *). Monad m => m a) -> IO a
- (bound at tcrun035.hs:13:1)
diff --git a/testsuite/tests/warnings/should_compile/PluralS.stderr b/testsuite/tests/warnings/should_compile/PluralS.stderr
index c013e7b73d..1c975abdb2 100644
--- a/testsuite/tests/warnings/should_compile/PluralS.stderr
+++ b/testsuite/tests/warnings/should_compile/PluralS.stderr
@@ -9,7 +9,7 @@ PluralS.hs:15:17: warning:
PluralS.hs:17:29: warning:
• Defaulting the following constraints to type ‘Integer’
(Num a0) arising from the literal ‘123’ at PluralS.hs:17:29-31
- (Show a0) arising from a use of ‘show’ at PluralS.hs:17:24-27
+ (Show a0) arising from a use of ‘show’ at PluralS.hs:17:24-31
• In the first argument of ‘show’, namely ‘123’
In the expression: show 123
In an equation for ‘defaultingNumAndShow’:
diff --git a/testsuite/tests/warnings/should_compile/T11077.stderr b/testsuite/tests/warnings/should_compile/T11077.stderr
index b2cfa61546..84034f8c65 100644
--- a/testsuite/tests/warnings/should_compile/T11077.stderr
+++ b/testsuite/tests/warnings/should_compile/T11077.stderr
@@ -1,3 +1,3 @@
T11077.hs:3:1: warning:
- Top-level binding with no type signature: foo :: forall r. r
+ Top-level binding with no type signature: foo :: forall a. a