| ... |
... |
@@ -9,9 +9,8 @@ module GHC.Tc.Types.Origin ( |
|
9
|
9
|
|
|
10
|
10
|
-- * CtOrigin
|
|
11
|
11
|
CtOrigin(..), exprCtOrigin, lexprCtOrigin, matchesCtOrigin, grhssCtOrigin,
|
|
12
|
|
- srcCodeOriginCtOrigin,
|
|
|
12
|
+ srcCodeOriginCtOrigin, errCtxtCtOrigin,
|
|
13
|
13
|
invisibleOrigin_maybe, isVisibleOrigin, toInvisibleOrigin,
|
|
14
|
|
- updatePositionCtOrigin,
|
|
15
|
14
|
pprCtOrigin, pprCtOriginBriefly, isGivenOrigin,
|
|
16
|
15
|
defaultReprEqOrigins, isWantedSuperclassOrigin,
|
|
17
|
16
|
ClsInstOrQC(..), NakedScFlag(..), NonLinearPatternReason(..),
|
| ... |
... |
@@ -37,7 +36,7 @@ module GHC.Tc.Types.Origin ( |
|
37
|
36
|
FRRArrowContext(..), pprFRRArrowContext,
|
|
38
|
37
|
|
|
39
|
38
|
-- ** ExpectedFunTy FixedRuntimeRepOrigin
|
|
40
|
|
- pprExpectedFunTyHerald,
|
|
|
39
|
+ ExpectedFunTyCtxt(..), pprExpectedFunTyCtxt, pprExpectedFunTyHerald,
|
|
41
|
40
|
|
|
42
|
41
|
-- * InstanceWhat
|
|
43
|
42
|
InstanceWhat(..), SafeOverlapping
|
| ... |
... |
@@ -512,72 +511,6 @@ data CtOrigin |
|
512
|
511
|
| AmbiguityCheckOrigin UserTypeCtxt
|
|
513
|
512
|
| ImplicitLiftOrigin HsImplicitLiftSplice
|
|
514
|
513
|
|
|
515
|
|
- | ExpansionOrigin ErrCtxtMsg -- This is due to an expansion of the original thing given by the ErrCtxtMsg
|
|
516
|
|
-
|
|
517
|
|
- | ExpectedTySyntax !CtOrigin (HsExpr GhcRn)
|
|
518
|
|
-
|
|
519
|
|
- -- | A rebindable syntax operator is expected to have a function type.
|
|
520
|
|
- --
|
|
521
|
|
- -- Test cases for representation-polymorphism checks:
|
|
522
|
|
- -- RepPolyDoBind, RepPolyDoBody{1,2}, RepPolyMc{Bind,Body,Guard}, RepPolyNPlusK
|
|
523
|
|
- | forall (p :: Pass)
|
|
524
|
|
- . (OutputableBndrId p)
|
|
525
|
|
- => ExpectedFunTySyntaxOp Int
|
|
526
|
|
- !CtOrigin !(HsExpr (GhcPass p))
|
|
527
|
|
- -- ^ rebindable syntax operator
|
|
528
|
|
-
|
|
529
|
|
- -- | A view pattern must have a function type.
|
|
530
|
|
- --
|
|
531
|
|
- -- Test cases for representation-polymorphism checks:
|
|
532
|
|
- -- RepPolyBinder
|
|
533
|
|
- | ExpectedFunTyViewPat Int
|
|
534
|
|
- !(HsExpr GhcRn)
|
|
535
|
|
- -- ^ function used in the view pattern
|
|
536
|
|
-
|
|
537
|
|
- -- | Need to be able to extract an argument type from a function type.
|
|
538
|
|
- --
|
|
539
|
|
- -- Test cases for representation-polymorphism checks:
|
|
540
|
|
- -- RepPolyApp
|
|
541
|
|
- | forall (p :: Pass)
|
|
542
|
|
- . Outputable (HsExpr (GhcPass p)) => ExpectedFunTyArg
|
|
543
|
|
- !TypedThing
|
|
544
|
|
- -- ^ function
|
|
545
|
|
- !(HsExpr (GhcPass p))
|
|
546
|
|
- -- ^ argument
|
|
547
|
|
-
|
|
548
|
|
- -- | Ensure that a function defined by equations indeed has a function type
|
|
549
|
|
- -- with the appropriate number of arguments.
|
|
550
|
|
- --
|
|
551
|
|
- -- Test cases for representation-polymorphism checks:
|
|
552
|
|
- -- RepPolyBinder, RepPolyRecordPattern, RepPolyWildcardPattern
|
|
553
|
|
- | ExpectedFunTyMatches Int
|
|
554
|
|
- !TypedThing
|
|
555
|
|
- -- ^ name of the function
|
|
556
|
|
- !(MatchGroup GhcRn (LHsExpr GhcRn))
|
|
557
|
|
- -- ^ equations
|
|
558
|
|
-
|
|
559
|
|
- -- | Ensure that a lambda abstraction has a function type.
|
|
560
|
|
- --
|
|
561
|
|
- -- Test cases for representation-polymorphism checks:
|
|
562
|
|
- -- RepPolyLambda, RepPolyMatch
|
|
563
|
|
- | ExpectedFunTyLam HsLamVariant
|
|
564
|
|
- !(HsExpr GhcRn)
|
|
565
|
|
- -- ^ the entire lambda-case expression
|
|
566
|
|
-
|
|
567
|
|
- -- | A partial application of the constructor of a representation-polymorphic
|
|
568
|
|
- -- unlifted newtype in which the argument type does not have a fixed
|
|
569
|
|
- -- runtime representation.
|
|
570
|
|
- --
|
|
571
|
|
- -- Test cases: UnliftedNewtypesLevityBinder, UnliftedNewtypesCoerceFail.
|
|
572
|
|
- | FRRRepPolyUnliftedNewtype !DataCon
|
|
573
|
|
-
|
|
574
|
|
-
|
|
575
|
|
-updatePositionCtOrigin :: Int -> CtOrigin -> CtOrigin
|
|
576
|
|
-updatePositionCtOrigin i (ExpectedFunTySyntaxOp _ c e) = ExpectedFunTySyntaxOp i c e
|
|
577
|
|
-updatePositionCtOrigin i (ExpectedFunTyViewPat _ e) = ExpectedFunTyViewPat i e
|
|
578
|
|
-updatePositionCtOrigin i (ExpectedFunTyMatches _ t e) = ExpectedFunTyMatches i t e
|
|
579
|
|
-updatePositionCtOrigin _ c = c
|
|
580
|
|
-
|
|
581
|
514
|
|
|
582
|
515
|
data NonLinearPatternReason
|
|
583
|
516
|
= LazyPatternReason
|
| ... |
... |
@@ -680,18 +613,18 @@ exprCtOrigin (HsTypedBracket {}) = Shouldn'tHappenOrigin "TH typed bracket" |
|
680
|
613
|
exprCtOrigin (HsUntypedBracket {}) = Shouldn'tHappenOrigin "TH untyped bracket"
|
|
681
|
614
|
exprCtOrigin (HsTypedSplice {}) = Shouldn'tHappenOrigin "TH typed splice"
|
|
682
|
615
|
exprCtOrigin (HsUntypedSplice {}) = Shouldn'tHappenOrigin "TH untyped splice"
|
|
683
|
|
-exprCtOrigin (HsProc {}) = Shouldn'tHappenOrigin "proc"
|
|
684
|
|
-exprCtOrigin (HsStatic {}) = Shouldn'tHappenOrigin "static expression"
|
|
685
|
|
-exprCtOrigin (HsEmbTy {}) = Shouldn'tHappenOrigin "type expression"
|
|
686
|
|
-exprCtOrigin (HsHole _) = Shouldn'tHappenOrigin "hole expression"
|
|
687
|
|
-exprCtOrigin (HsForAll {}) = Shouldn'tHappenOrigin "forall telescope" -- See Note [Types in terms]
|
|
688
|
|
-exprCtOrigin (HsQual {}) = Shouldn'tHappenOrigin "constraint context" -- See Note [Types in terms]
|
|
689
|
|
-exprCtOrigin (HsFunArr {}) = Shouldn'tHappenOrigin "function arrow" -- See Note [Types in terms]
|
|
690
|
|
-exprCtOrigin e@(ExplicitList {}) = ExpansionOrigin (ExprCtxt e)
|
|
691
|
|
-exprCtOrigin e@(HsIf {}) = ExpansionOrigin (ExprCtxt e)
|
|
692
|
|
-exprCtOrigin e@(HsProjection _ _) = ExpansionOrigin (ExprCtxt e)
|
|
693
|
|
-exprCtOrigin e@(RecordUpd{}) = ExpansionOrigin (ExprCtxt e)
|
|
694
|
|
-exprCtOrigin e@(HsGetField{}) = ExpansionOrigin (ExprCtxt e)
|
|
|
616
|
+exprCtOrigin (HsProc {}) = Shouldn'tHappenOrigin "proc"
|
|
|
617
|
+exprCtOrigin (HsStatic {}) = Shouldn'tHappenOrigin "static expression"
|
|
|
618
|
+exprCtOrigin (HsEmbTy {}) = Shouldn'tHappenOrigin "type expression"
|
|
|
619
|
+exprCtOrigin (HsHole _) = Shouldn'tHappenOrigin "hole expression"
|
|
|
620
|
+exprCtOrigin (HsForAll {}) = Shouldn'tHappenOrigin "forall telescope" -- See Note [Types in terms]
|
|
|
621
|
+exprCtOrigin (HsQual {}) = Shouldn'tHappenOrigin "constraint context" -- See Note [Types in terms]
|
|
|
622
|
+exprCtOrigin (HsFunArr {}) = Shouldn'tHappenOrigin "function arrow" -- See Note [Types in terms]
|
|
|
623
|
+exprCtOrigin (ExplicitList {}) = ListOrigin
|
|
|
624
|
+exprCtOrigin (HsIf {}) = IfThenElseOrigin
|
|
|
625
|
+exprCtOrigin (HsProjection _ p) = RecordFieldProjectionOrigin (FieldLabelStrings $ fmap noLocA p)
|
|
|
626
|
+exprCtOrigin (RecordUpd _ _ flds) = RecordUpdOrigin flds
|
|
|
627
|
+exprCtOrigin (HsGetField _ _ f) = GetFieldOrigin (fmap field_label $ dfoLabel (unLoc f))
|
|
695
|
628
|
exprCtOrigin (XExpr (ExpandedThingRn o _)) = errCtxtCtOrigin o
|
|
696
|
629
|
exprCtOrigin (XExpr (HsRecSelRn f)) = OccurrenceOfRecSel $ L (getLoc $ foLabel f) (foExt f)
|
|
697
|
630
|
|
| ... |
... |
@@ -736,31 +669,6 @@ pprCtOrigin :: CtOrigin -> SDoc |
|
736
|
669
|
pprCtOrigin (GivenOrigin sk)
|
|
737
|
670
|
= ctoHerald <+> ppr sk
|
|
738
|
671
|
|
|
739
|
|
-pprCtOrigin (ExpansionOrigin o)
|
|
740
|
|
- = ctoHerald <+> what
|
|
741
|
|
- where
|
|
742
|
|
- what :: SDoc
|
|
743
|
|
- what = case o of
|
|
744
|
|
- StmtErrCtxt{} ->
|
|
745
|
|
- text "a do statement"
|
|
746
|
|
- DoStmtErrCtxt{} ->
|
|
747
|
|
- text "a do statement"
|
|
748
|
|
- StmtErrCtxtPat _ _ p ->
|
|
749
|
|
- text "a do statement" $$
|
|
750
|
|
- text "with the failable pattern" <+> quotes (ppr p)
|
|
751
|
|
- ExprCtxt (HsGetField _ _ (L _ f)) ->
|
|
752
|
|
- hsep [text "selecting the field", quotes (ppr f)]
|
|
753
|
|
- ExprCtxt (HsOverLabel _ l) ->
|
|
754
|
|
- hsep [text "the overloaded label" , quotes (char '#' <> ppr l)]
|
|
755
|
|
- ExprCtxt (RecordUpd{}) -> text "a record update"
|
|
756
|
|
- ExprCtxt (ExplicitList{}) -> text "an overloaded list"
|
|
757
|
|
- ExprCtxt (HsIf{}) -> text "an if-then-else expression"
|
|
758
|
|
- ExprCtxt (HsProjection _ p) -> text "the record selector" <+>
|
|
759
|
|
- quotes (ppr ((FieldLabelStrings $ fmap noLocA p)))
|
|
760
|
|
- ExprCtxt e -> text "the expression" <+> (ppr e)
|
|
761
|
|
- RecordUpdCtxt{} -> text "a record update"
|
|
762
|
|
- _ -> text "shouldn't happen ExpansionOrigin pprCtOrigin"
|
|
763
|
|
-
|
|
764
|
672
|
pprCtOrigin (GivenSCOrigin sk d blk)
|
|
765
|
673
|
= vcat [ ctoHerald <+> pprSkolInfo sk
|
|
766
|
674
|
, whenPprDebug (braces (text "given-sc:" <+> ppr d <> comma <> ppr blk)) ]
|
| ... |
... |
@@ -867,46 +775,9 @@ pprCtOrigin (NonLinearPatternOrigin reason pat) |
|
867
|
775
|
= hang (ctoHerald <+> text "a non-linear pattern" <+> quotes (ppr pat))
|
|
868
|
776
|
2 (pprNonLinearPatternReason reason)
|
|
869
|
777
|
|
|
870
|
|
-pprCtOrigin (ExpectedTySyntax orig arg)
|
|
871
|
|
- = vcat [ text "The expression" <+> quotes (ppr arg)
|
|
872
|
|
- , nest 2 (ppr orig) ]
|
|
873
|
|
-
|
|
874
|
|
-pprCtOrigin (ExpectedFunTySyntaxOp i orig op) =
|
|
875
|
|
- vcat [ sep [ the_arg_of i
|
|
876
|
|
- , text "the rebindable syntax operator"
|
|
877
|
|
- , quotes (ppr op) ]
|
|
878
|
|
- , nest 2 (ppr orig) ]
|
|
879
|
|
-
|
|
880
|
|
-pprCtOrigin (ExpectedFunTyViewPat i expr) =
|
|
881
|
|
- vcat [ the_arg_of i <+> text "the view pattern"
|
|
882
|
|
- , nest 2 (ppr expr) ]
|
|
883
|
|
-pprCtOrigin (ExpectedFunTyArg fun arg) =
|
|
884
|
|
- sep [ text "The argument"
|
|
885
|
|
- , quotes (ppr arg)
|
|
886
|
|
- , text "of"
|
|
887
|
|
- , quotes (ppr fun) ]
|
|
888
|
|
-pprCtOrigin (ExpectedFunTyMatches i fun (MG { mg_alts = L _ alts }))
|
|
889
|
|
- | null alts
|
|
890
|
|
- = the_arg_of i <+> quotes (ppr fun)
|
|
891
|
|
- | otherwise
|
|
892
|
|
- = text "The" <+> speakNth i <+> text "pattern in the equation" <> plural alts
|
|
893
|
|
- <+> text "for" <+> quotes (ppr fun)
|
|
894
|
|
-pprCtOrigin (ExpectedFunTyLam lam_variant _) = binder_of $ lamCaseKeyword lam_variant
|
|
895
|
|
-pprCtOrigin (FRRRepPolyUnliftedNewtype dc) =
|
|
896
|
|
- vcat [ text "Unsaturated use of a representation-polymorphic unlifted newtype."
|
|
897
|
|
- , text "The argument of the newtype constructor" <+> quotes (ppr dc) ]
|
|
898
|
|
-
|
|
899
|
778
|
pprCtOrigin simple_origin
|
|
900
|
779
|
= ctoHerald <+> pprCtOriginBriefly simple_origin
|
|
901
|
780
|
|
|
902
|
|
-the_arg_of :: Int -> SDoc
|
|
903
|
|
-the_arg_of i = text "The" <+> speakNth i <+> text "argument of"
|
|
904
|
|
-
|
|
905
|
|
-binder_of :: SDoc -> SDoc
|
|
906
|
|
-binder_of what = text "The binder of the" <+> what <+> text "expression"
|
|
907
|
|
-
|
|
908
|
|
-
|
|
909
|
|
-
|
|
910
|
781
|
-- | Print CtOrigin briefly, with a one-liner
|
|
911
|
782
|
pprCtOriginBriefly :: CtOrigin -> SDoc
|
|
912
|
783
|
pprCtOriginBriefly = ppr_br -- ppr_br is a local function with a short name!
|
| ... |
... |
@@ -979,22 +850,6 @@ ppr_br (InstanceSigOrigin {}) = text "a type signature in an instance" |
|
979
|
850
|
ppr_br (AmbiguityCheckOrigin {}) = text "a type ambiguity check"
|
|
980
|
851
|
ppr_br (ImpedanceMatching {}) = text "combining required constraints"
|
|
981
|
852
|
ppr_br (NonLinearPatternOrigin _ pat) = hsep [text "a non-linear pattern" <+> quotes (ppr pat)]
|
|
982
|
|
-ppr_br (ExpansionOrigin (ExprCtxt (HsOverLabel _ l))) = hsep [text "the overloaded label", quotes (char '#' <> ppr l)]
|
|
983
|
|
-ppr_br (ExpansionOrigin (ExprCtxt (RecordUpd{}))) = text "a record update"
|
|
984
|
|
-ppr_br (ExpansionOrigin (ExprCtxt (ExplicitList{}))) = text "an overloaded list"
|
|
985
|
|
-ppr_br (ExpansionOrigin (ExprCtxt (HsIf{}))) = text "an if-then-else expression"
|
|
986
|
|
-ppr_br (ExpansionOrigin (ExprCtxt e)) = text "an expression" <+> ppr e
|
|
987
|
|
-ppr_br (ExpansionOrigin (StmtErrCtxt{})) = text "a do statement"
|
|
988
|
|
-ppr_br (ExpansionOrigin (StmtErrCtxtPat{})) = text "a do statement"
|
|
989
|
|
-ppr_br (ExpansionOrigin{}) = text "shouldn't happen ExpansionOrigin ppr_br"
|
|
990
|
|
-ppr_br (ExpectedTySyntax o _) = ppr_br o
|
|
991
|
|
-ppr_br (ExpectedFunTySyntaxOp{}) = text "a rebindable syntax operator"
|
|
992
|
|
-ppr_br (ExpectedFunTyViewPat{}) = text "a view pattern"
|
|
993
|
|
-ppr_br (ExpectedFunTyArg{}) = text "a funtion head"
|
|
994
|
|
-ppr_br (ExpectedFunTyMatches{}) = text "a match statement"
|
|
995
|
|
-ppr_br (ExpectedFunTyLam{}) = text "a lambda expression"
|
|
996
|
|
-ppr_br (FRRRepPolyUnliftedNewtype{}) = text "a unlifted newtype"
|
|
997
|
|
-
|
|
998
|
853
|
|
|
999
|
854
|
pprNonLinearPatternReason :: HasDebugCallStack => NonLinearPatternReason -> SDoc
|
|
1000
|
855
|
pprNonLinearPatternReason LazyPatternReason = parens (text "non-variable lazy pattern aren't linear")
|
| ... |
... |
@@ -1225,9 +1080,9 @@ data FixedRuntimeRepContext |
|
1225
|
1080
|
-- | A representation-polymorphism check arising from a call
|
|
1226
|
1081
|
-- to 'matchExpectedFunTys' or 'matchActualFunTy'.
|
|
1227
|
1082
|
--
|
|
1228
|
|
- -- See 'ExpectedFunTyOrigin' for more details.
|
|
|
1083
|
+ -- See 'ExpectedFunTyCtxt' for more details.
|
|
1229
|
1084
|
| FRRExpectedFunTy
|
|
1230
|
|
- !CtOrigin
|
|
|
1085
|
+ !ExpectedFunTyCtxt
|
|
1231
|
1086
|
!Int
|
|
1232
|
1087
|
-- ^ argument position (1-indexed)
|
|
1233
|
1088
|
|
| ... |
... |
@@ -1314,7 +1169,7 @@ pprFixedRuntimeRepContext FRRBindStmtGuard |
|
1314
|
1169
|
pprFixedRuntimeRepContext (FRRArrow arrowContext)
|
|
1315
|
1170
|
= pprFRRArrowContext arrowContext
|
|
1316
|
1171
|
pprFixedRuntimeRepContext (FRRExpectedFunTy funTyOrig _)
|
|
1317
|
|
- = pprCtOrigin funTyOrig
|
|
|
1172
|
+ = pprExpectedFunTyHerald funTyOrig
|
|
1318
|
1173
|
pprFixedRuntimeRepContext (FRRDeepSubsumption is_exp pos mb_fun)
|
|
1319
|
1174
|
= hsep [ text "The", what, text "type of the"
|
|
1320
|
1175
|
, ppr (Argument pos)
|
| ... |
... |
@@ -1540,15 +1395,136 @@ instance Outputable FRRArrowContext where |
|
1540
|
1395
|
ppr = pprFRRArrowContext
|
|
1541
|
1396
|
|
|
1542
|
1397
|
|
|
1543
|
|
-pprExpectedFunTyHerald :: CtOrigin -> SDoc
|
|
|
1398
|
+{- *********************************************************************
|
|
|
1399
|
+* *
|
|
|
1400
|
+ FixedRuntimeRep: ExpectedFunTy origin
|
|
|
1401
|
+* *
|
|
|
1402
|
+********************************************************************* -}
|
|
|
1403
|
+
|
|
|
1404
|
+-- | In what context are we calling 'matchExpectedFunTys'
|
|
|
1405
|
+-- or 'matchActualFunTy'?
|
|
|
1406
|
+--
|
|
|
1407
|
+-- Used for two things:
|
|
|
1408
|
+--
|
|
|
1409
|
+-- 1. Reporting error messages which explain that a function has been
|
|
|
1410
|
+-- given an unexpected number of arguments.
|
|
|
1411
|
+-- Uses 'pprExpectedFunTyHerald'.
|
|
|
1412
|
+-- See Note [Herald for matchExpectedFunTys] in GHC.Tc.Utils.Unify.
|
|
|
1413
|
+--
|
|
|
1414
|
+-- 2. Reporting representation-polymorphism errors when a function argument
|
|
|
1415
|
+-- doesn't have a fixed RuntimeRep as per Note [Fixed RuntimeRep]
|
|
|
1416
|
+-- in GHC.Tc.Utils.Concrete.
|
|
|
1417
|
+-- Uses 'pprExpectedFunTyCtxt'.
|
|
|
1418
|
+-- See 'FixedRuntimeRepContext' for the situations in which
|
|
|
1419
|
+-- representation-polymorphism checks are performed.
|
|
|
1420
|
+data ExpectedFunTyCtxt
|
|
|
1421
|
+
|
|
|
1422
|
+ -- | A rebindable syntax operator is expected to have a function type.
|
|
|
1423
|
+ --
|
|
|
1424
|
+ -- Test cases for representation-polymorphism checks:
|
|
|
1425
|
+ -- RepPolyDoBind, RepPolyDoBody{1,2}, RepPolyMc{Bind,Body,Guard}, RepPolyNPlusK
|
|
|
1426
|
+ = forall (p :: Pass)
|
|
|
1427
|
+ . (OutputableBndrId p)
|
|
|
1428
|
+ => ExpectedFunTySyntaxOp !CtOrigin !(HsExpr (GhcPass p))
|
|
|
1429
|
+ -- ^ rebindable syntax operator
|
|
|
1430
|
+
|
|
|
1431
|
+ -- |
|
|
|
1432
|
+ | ExpectedTySyntax !CtOrigin !(HsExpr GhcRn)
|
|
|
1433
|
+
|
|
|
1434
|
+ -- | A view pattern must have a function type.
|
|
|
1435
|
+ --
|
|
|
1436
|
+ -- Test cases for representation-polymorphism checks:
|
|
|
1437
|
+ -- RepPolyBinder
|
|
|
1438
|
+ | ExpectedFunTyViewPat
|
|
|
1439
|
+ !(HsExpr GhcRn)
|
|
|
1440
|
+ -- ^ function used in the view pattern
|
|
|
1441
|
+
|
|
|
1442
|
+ -- | Need to be able to extract an argument type from a function type.
|
|
|
1443
|
+ --
|
|
|
1444
|
+ -- Test cases for representation-polymorphism checks:
|
|
|
1445
|
+ -- RepPolyApp
|
|
|
1446
|
+ | forall (p :: Pass)
|
|
|
1447
|
+ . Outputable (HsExpr (GhcPass p)) => ExpectedFunTyArg
|
|
|
1448
|
+ !TypedThing
|
|
|
1449
|
+ -- ^ function
|
|
|
1450
|
+ !(HsExpr (GhcPass p))
|
|
|
1451
|
+ -- ^ argument
|
|
|
1452
|
+
|
|
|
1453
|
+ -- | Ensure that a function defined by equations indeed has a function type
|
|
|
1454
|
+ -- with the appropriate number of arguments.
|
|
|
1455
|
+ --
|
|
|
1456
|
+ -- Test cases for representation-polymorphism checks:
|
|
|
1457
|
+ -- RepPolyBinder, RepPolyRecordPattern, RepPolyWildcardPattern
|
|
|
1458
|
+ | ExpectedFunTyMatches
|
|
|
1459
|
+ !TypedThing
|
|
|
1460
|
+ -- ^ name of the function
|
|
|
1461
|
+ !(MatchGroup GhcRn (LHsExpr GhcRn))
|
|
|
1462
|
+ -- ^ equations
|
|
|
1463
|
+
|
|
|
1464
|
+ -- | Ensure that a lambda abstraction has a function type.
|
|
|
1465
|
+ --
|
|
|
1466
|
+ -- Test cases for representation-polymorphism checks:
|
|
|
1467
|
+ -- RepPolyLambda, RepPolyMatch
|
|
|
1468
|
+ | ExpectedFunTyLam HsLamVariant
|
|
|
1469
|
+ !(HsExpr GhcRn)
|
|
|
1470
|
+ -- ^ the entire lambda-case expression
|
|
|
1471
|
+
|
|
|
1472
|
+ -- | A partial application of the constructor of a representation-polymorphic
|
|
|
1473
|
+ -- unlifted newtype in which the argument type does not have a fixed
|
|
|
1474
|
+ -- runtime representation.
|
|
|
1475
|
+ --
|
|
|
1476
|
+ -- Test cases: UnliftedNewtypesLevityBinder, UnliftedNewtypesCoerceFail.
|
|
|
1477
|
+ | FRRRepPolyUnliftedNewtype !DataCon
|
|
|
1478
|
+
|
|
|
1479
|
+pprExpectedFunTyCtxt :: ExpectedFunTyCtxt
|
|
|
1480
|
+ -> Int -- ^ argument position (starting at 1)
|
|
|
1481
|
+ -> SDoc
|
|
|
1482
|
+pprExpectedFunTyCtxt funTy_origin i =
|
|
|
1483
|
+ case funTy_origin of
|
|
|
1484
|
+ ExpectedFunTySyntaxOp orig op ->
|
|
|
1485
|
+ vcat [ sep [ the_arg_of
|
|
|
1486
|
+ , text "the rebindable syntax operator"
|
|
|
1487
|
+ , quotes (ppr op) ]
|
|
|
1488
|
+ , nest 2 (ppr orig) ]
|
|
|
1489
|
+ ExpectedTySyntax orig arg ->
|
|
|
1490
|
+ vcat [ text "the expression" <+> quotes (ppr arg)
|
|
|
1491
|
+ , nest 2 (ppr orig) ]
|
|
|
1492
|
+ ExpectedFunTyViewPat expr ->
|
|
|
1493
|
+ vcat [ the_arg_of <+> text "the view pattern"
|
|
|
1494
|
+ , nest 2 (ppr expr) ]
|
|
|
1495
|
+ ExpectedFunTyArg fun arg ->
|
|
|
1496
|
+ sep [ text "The argument"
|
|
|
1497
|
+ , quotes (ppr arg)
|
|
|
1498
|
+ , text "of"
|
|
|
1499
|
+ , quotes (ppr fun) ]
|
|
|
1500
|
+ ExpectedFunTyMatches fun (MG { mg_alts = L _ alts })
|
|
|
1501
|
+ | null alts
|
|
|
1502
|
+ -> the_arg_of <+> quotes (ppr fun)
|
|
|
1503
|
+ | otherwise
|
|
|
1504
|
+ -> text "The" <+> speakNth i <+> text "pattern in the equation" <> plural alts
|
|
|
1505
|
+ <+> text "for" <+> quotes (ppr fun)
|
|
|
1506
|
+ ExpectedFunTyLam lam_variant _ -> binder_of $ lamCaseKeyword lam_variant
|
|
|
1507
|
+ FRRRepPolyUnliftedNewtype dc ->
|
|
|
1508
|
+ vcat [ text "Unsaturated use of a representation-polymorphic unlifted newtype."
|
|
|
1509
|
+ , text "The argument of the newtype constructor" <+> quotes (ppr dc) ]
|
|
|
1510
|
+ where
|
|
|
1511
|
+ the_arg_of :: SDoc
|
|
|
1512
|
+ the_arg_of = text "The" <+> speakNth i <+> text "argument of"
|
|
|
1513
|
+
|
|
|
1514
|
+ binder_of :: SDoc -> SDoc
|
|
|
1515
|
+ binder_of what = text "The binder of the" <+> what <+> text "expression"
|
|
|
1516
|
+
|
|
|
1517
|
+pprExpectedFunTyHerald :: ExpectedFunTyCtxt -> SDoc
|
|
1544
|
1518
|
pprExpectedFunTyHerald (ExpectedFunTySyntaxOp {})
|
|
1545
|
1519
|
= text "This rebindable syntax expects a function with"
|
|
|
1520
|
+pprExpectedFunTyHerald (ExpectedTySyntax orig _)
|
|
|
1521
|
+ = pprCtOriginBriefly orig
|
|
1546
|
1522
|
pprExpectedFunTyHerald (ExpectedFunTyViewPat {})
|
|
1547
|
1523
|
= text "A view pattern expression expects"
|
|
1548
|
1524
|
pprExpectedFunTyHerald (ExpectedFunTyArg fun _)
|
|
1549
|
1525
|
= sep [ text "The function" <+> quotes (ppr fun)
|
|
1550
|
1526
|
, text "is applied to" ]
|
|
1551
|
|
-pprExpectedFunTyHerald (ExpectedFunTyMatches _ fun (MG { mg_alts = L _ alts }))
|
|
|
1527
|
+pprExpectedFunTyHerald (ExpectedFunTyMatches fun (MG { mg_alts = L _ alts }))
|
|
1552
|
1528
|
= text "The equation" <> plural alts <+> text "for" <+> quotes (ppr fun) <+> hasOrHave alts
|
|
1553
|
1529
|
pprExpectedFunTyHerald (ExpectedFunTyLam lam_variant expr)
|
|
1554
|
1530
|
= sep [ text "The" <+> lamCaseKeyword lam_variant <+> text "expression"
|
| ... |
... |
@@ -1557,7 +1533,6 @@ pprExpectedFunTyHerald (ExpectedFunTyLam lam_variant expr) |
|
1557
|
1533
|
, text "has" ]
|
|
1558
|
1534
|
pprExpectedFunTyHerald (FRRRepPolyUnliftedNewtype dc)
|
|
1559
|
1535
|
= text "The unlifted newtype" <+> quotes (ppr dc) <+> text "expects"
|
|
1560
|
|
-pprExpectedFunTyHerald orig = ppr (Shouldn'tHappenOrigin "pprExpectedFunTyHerald") <+> ppr orig
|
|
1561
|
1536
|
|
|
1562
|
1537
|
{- *******************************************************************
|
|
1563
|
1538
|
* *
|