1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -fno-warn-orphans #-} -- instance Diagnostic TcRnMessage
{-# LANGUAGE RecordWildCards #-}
module GHC.Tc.Errors.Ppr (
formatLevPolyErr
, pprLevityPolyInType
) where
import GHC.Prelude
import GHC.Core.Class (Class(..))
import GHC.Core.TyCo.Ppr (pprKind, pprParendType, pprType, pprWithTYPE)
import GHC.Core.Type
import GHC.Data.Bag
import GHC.Tc.Errors.Types
import GHC.Tc.Types.Rank (Rank(..))
import GHC.Tc.Utils.TcType (tcSplitForAllTyVars)
import GHC.Types.Error
import GHC.Types.Name (pprPrefixName)
import GHC.Types.Name.Reader (pprNameProvenance)
import GHC.Types.SrcLoc (GenLocated(..))
import GHC.Types.Name.Occurrence (occName)
import GHC.Types.Var.Env (emptyTidyEnv)
import GHC.Driver.Flags
import GHC.Hs
import GHC.Utils.Outputable
import GHC.Unit.State (pprWithUnitState, UnitState)
import qualified GHC.LanguageExtensions as LangExt
import qualified Data.List.NonEmpty as NE
instance Diagnostic TcRnMessage where
diagnosticMessage = \case
TcRnUnknownMessage m
-> diagnosticMessage m
TcLevityPolyInType ty prov (ErrInfo extra supplementary)
-> mkDecorated [pprLevityPolyInType ty prov, extra, supplementary]
TcRnMessageWithInfo unit_state msg_with_info
-> case msg_with_info of
TcRnMessageDetailed err_info msg
-> messageWithInfoDiagnosticMessage unit_state err_info (diagnosticMessage msg)
TcRnImplicitLift id_or_name ErrInfo{..}
-> mkDecorated $
( text "The variable" <+> quotes (ppr id_or_name) <+>
text "is implicitly lifted in the TH quotation"
) : [errInfoContext, errInfoSupplementary]
TcRnUnusedPatternBinds bind
-> mkDecorated [hang (text "This pattern-binding binds no variables:") 2 (ppr bind)]
TcRnDodgyImports name
-> mkDecorated [dodgy_msg (text "import") name (dodgy_msg_insert name :: IE GhcPs)]
TcRnDodgyExports name
-> mkDecorated [dodgy_msg (text "export") name (dodgy_msg_insert name :: IE GhcRn)]
TcRnMissingImportList ie
-> mkDecorated [ text "The import item" <+> quotes (ppr ie) <+>
text "does not have an explicit import list"
]
TcRnUnsafeDueToPlugin
-> mkDecorated [text "Use of plugins makes the module unsafe"]
TcRnModMissingRealSrcSpan mod
-> mkDecorated [text "Module does not have a RealSrcSpan:" <+> ppr mod]
TcRnIdNotExportedFromModuleSig name mod
-> mkDecorated [ text "The identifier" <+> ppr (occName name) <+>
text "does not exist in the signature for" <+> ppr mod
]
TcRnIdNotExportedFromLocalSig name
-> mkDecorated [ text "The identifier" <+> ppr (occName name) <+>
text "does not exist in the local signature."
]
TcRnShadowedName occ provenance
-> let shadowed_locs = case provenance of
ShadowedNameProvenanceLocal n -> [text "bound at" <+> ppr n]
ShadowedNameProvenanceGlobal gres -> map pprNameProvenance gres
in mkSimpleDecorated $
sep [text "This binding for" <+> quotes (ppr occ)
<+> text "shadows the existing binding" <> plural shadowed_locs,
nest 2 (vcat shadowed_locs)]
TcRnDuplicateWarningDecls d rdr_name
-> mkSimpleDecorated $
vcat [text "Multiple warning declarations for" <+> quotes (ppr rdr_name),
text "also at " <+> ppr (getLocA d)]
TcRnSimplifierTooManyIterations limit wc
-> mkSimpleDecorated $
hang (text "solveWanteds: too many iterations"
<+> parens (text "limit =" <+> ppr limit))
2 (text "Unsolved:" <+> ppr wc)
TcRnIllegalPatSynDecl rdrname
-> mkSimpleDecorated $
hang (text "Illegal pattern synonym declaration for" <+> quotes (ppr rdrname))
2 (text "Pattern synonym declarations are only valid at top level")
TcRnLinearPatSyn ty
-> mkSimpleDecorated $
hang (text "Pattern synonyms do not support linear fields (GHC #18806):") 2 (ppr ty)
TcRnEmptyRecordUpdate
-> mkSimpleDecorated $ text "Empty record update"
TcRnIllegalFieldPunning fld
-> mkSimpleDecorated $ text "Illegal use of punning for field" <+> quotes (ppr fld)
TcRnIllegalWildcardsInRecord fld_part
-> mkSimpleDecorated $ text "Illegal `..' in record" <+> pprRecordFieldPart fld_part
TcRnDuplicateFieldName fld_part dups
-> mkSimpleDecorated $
hsep [text "duplicate field name",
quotes (ppr (NE.head dups)),
text "in record", pprRecordFieldPart fld_part]
TcRnIllegalViewPattern pat
-> mkSimpleDecorated $ vcat [text "Illegal view pattern: " <+> ppr pat]
TcRnCharLiteralOutOfRange c
-> mkSimpleDecorated $ text "character literal out of range: '\\" <> char c <> char '\''
TcRnIllegalWildcardsInConstructor con
-> mkSimpleDecorated $
vcat [ text "Illegal `..' notation for constructor" <+> quotes (ppr con)
, nest 2 (text "The constructor has no labelled fields") ]
TcRnIgnoringAnnotations anns
-> mkSimpleDecorated $
text "Ignoring ANN annotation" <> plural anns <> comma
<+> text "because this is a stage-1 compiler without -fexternal-interpreter or doesn't support GHCi"
TcRnAnnotationInSafeHaskell
-> mkSimpleDecorated $
vcat [ text "Annotations are not compatible with Safe Haskell."
, text "See https://gitlab.haskell.org/ghc/ghc/issues/10826" ]
TcRnInvalidTypeApplication fun_ty hs_ty
-> mkSimpleDecorated $
text "Cannot apply expression of type" <+> quotes (ppr fun_ty) $$
text "to a visible type argument" <+> quotes (ppr hs_ty)
TcRnTagToEnumMissingValArg
-> mkSimpleDecorated $
text "tagToEnum# must appear applied to one value argument"
TcRnTagToEnumUnspecifiedResTy ty
-> mkSimpleDecorated $
hang (text "Bad call to tagToEnum# at type" <+> ppr ty)
2 (vcat [ text "Specify the type by giving a type signature"
, text "e.g. (tagToEnum# x) :: Bool" ])
TcRnTagToEnumResTyNotAnEnum ty
-> mkSimpleDecorated $
hang (text "Bad call to tagToEnum# at type" <+> ppr ty)
2 (text "Result type must be an enumeration type")
TcRnArrowIfThenElsePredDependsOnResultTy
-> mkSimpleDecorated $
text "Predicate type of `ifThenElse' depends on result type"
TcRnArrowCommandExpected cmd
-> mkSimpleDecorated $
vcat [text "The expression", nest 2 (ppr cmd),
text "was found where an arrow command was expected"]
TcRnIllegalHsBootFileDecl
-> mkSimpleDecorated $
text "Illegal declarations in an hs-boot file"
TcRnRecursivePatternSynonym binds
-> mkSimpleDecorated $
hang (text "Recursive pattern synonym definition with following bindings:")
2 (vcat $ map pprLBind . bagToList $ binds)
where
pprLoc loc = parens (text "defined at" <+> ppr loc)
pprLBind :: GenLocated (SrcSpanAnn' a) (HsBindLR GhcRn idR) -> SDoc
pprLBind (L loc bind) = pprWithCommas ppr (collectHsBindBinders CollNoDictBinders bind)
<+> pprLoc (locA loc)
TcRnPartialTypeSigTyVarMismatch n1 n2 fn_name hs_ty
-> mkSimpleDecorated $
hang (text "Couldn't match" <+> quotes (ppr n1)
<+> text "with" <+> quotes (ppr n2))
2 (hang (text "both bound by the partial type signature:")
2 (ppr fn_name <+> dcolon <+> ppr hs_ty))
TcRnPartialTypeSigBadQuantifier n fn_name hs_ty
-> mkSimpleDecorated $
hang (text "Can't quantify over" <+> quotes (ppr n))
2 (hang (text "bound by the partial type signature:")
2 (ppr fn_name <+> dcolon <+> ppr hs_ty))
TcRnPolymorphicBinderMissingSig n ty
-> mkSimpleDecorated $
sep [ text "Polymorphic local binding with no type signature:"
, nest 2 $ pprPrefixName n <+> dcolon <+> ppr ty ]
TcRnOverloadedSig sig
-> mkSimpleDecorated $
hang (text "Overloaded signature conflicts with monomorphism restriction")
2 (ppr sig)
TcRnTupleConstraintInst _
-> mkSimpleDecorated $ text "You can't specify an instance for a tuple constraint"
TcRnAbstractClassInst clas
-> mkSimpleDecorated $
text "Cannot define instance for abstract class" <+>
quotes (ppr (className clas))
TcRnNoClassInstHead tau
-> mkSimpleDecorated $
hang (text "Instance head is not headed by a class:") 2 (pprType tau)
TcRnUserTypeError ty
-> mkSimpleDecorated (pprUserTypeErrorTy ty)
TcRnConstraintInKind ty
-> mkSimpleDecorated $
text "Illegal constraint in a kind:" <+> pprType ty
TcRnUnboxedTupleTypeFuncArg ty
-> mkSimpleDecorated $
sep [ text "Illegal unboxed tuple type as function argument:"
, pprType ty ]
TcRnLinearFuncInKind ty
-> mkSimpleDecorated $
text "Illegal linear function in a kind:" <+> pprType ty
TcRnForAllEscapeError ty kind
-> mkSimpleDecorated $ vcat
[ hang (text "Quantified type's kind mentions quantified type variable")
2 (text "type:" <+> quotes (ppr ty))
, hang (text "where the body of the forall has this kind:")
2 (quotes (pprKind kind)) ]
TcRnVDQInTermType ty
-> mkSimpleDecorated $ vcat
[ hang (text "Illegal visible, dependent quantification" <+>
text "in the type of a term:")
2 (pprType ty)
, text "(GHC does not yet support this)" ]
TcRnIllegalEqualConstraints ty
-> mkSimpleDecorated $
text "Illegal equational constraint" <+> pprType ty
TcRnBadQuantPredHead ty
-> mkSimpleDecorated $
hang (text "Quantified predicate must have a class or type variable head:")
2 (pprType ty)
TcRnIllegalTupleConstraint ty
-> mkSimpleDecorated $
text "Illegal tuple constraint:" <+> pprType ty
TcRnNonTypeVarArgInConstraint ty
-> mkSimpleDecorated $
hang (text "Non type-variable argument")
2 (text "in the constraint:" <+> pprType ty)
TcRnIllegalImplicitParam ty
-> mkSimpleDecorated $
text "Illegal implicit parameter" <+> quotes (pprType ty)
TcRnIllegalConstraintSynonymOfKind kind
-> mkSimpleDecorated $
text "Illegal constraint synonym of kind:" <+> quotes (pprKind kind)
TcRnIllegalClassInst tcf
-> mkSimpleDecorated $
vcat [ text "Illegal instance for a" <+> ppr tcf
, text "A class instance must be for a class" ]
TcRnOversaturatedVisibleKindArg ty
-> mkSimpleDecorated $
text "Illegal oversaturated visible kind argument:" <+>
quotes (char '@' <> pprParendType ty)
TcRnBadAssociatedType clas tc
-> mkSimpleDecorated $
hsep [ text "Class", quotes (ppr clas)
, text "does not have an associated type", quotes (ppr tc) ]
TcRnForAllRankErr rank ty
-> let herald = case tcSplitForAllTyVars ty of
([], _) -> text "Illegal qualified type:"
_ -> text "Illegal polymorphic type:"
extra = case rank of
MonoTypeConstraint -> text "A constraint must be a monotype"
_ -> empty
in mkSimpleDecorated $ vcat [hang herald 2 (pprType ty), extra]
diagnosticReason = \case
TcRnUnknownMessage m
-> diagnosticReason m
TcLevityPolyInType{}
-> ErrorWithoutFlag
TcRnMessageWithInfo _ msg_with_info
-> case msg_with_info of
TcRnMessageDetailed _ m -> diagnosticReason m
TcRnImplicitLift{}
-> WarningWithFlag Opt_WarnImplicitLift
TcRnUnusedPatternBinds{}
-> WarningWithFlag Opt_WarnUnusedPatternBinds
TcRnDodgyImports{}
-> WarningWithFlag Opt_WarnDodgyImports
TcRnDodgyExports{}
-> WarningWithFlag Opt_WarnDodgyExports
TcRnMissingImportList{}
-> WarningWithFlag Opt_WarnMissingImportList
TcRnUnsafeDueToPlugin{}
-> WarningWithoutFlag
TcRnModMissingRealSrcSpan{}
-> ErrorWithoutFlag
TcRnIdNotExportedFromModuleSig{}
-> ErrorWithoutFlag
TcRnIdNotExportedFromLocalSig{}
-> ErrorWithoutFlag
TcRnShadowedName{}
-> WarningWithFlag Opt_WarnNameShadowing
TcRnDuplicateWarningDecls{}
-> ErrorWithoutFlag
TcRnSimplifierTooManyIterations{}
-> ErrorWithoutFlag
TcRnIllegalPatSynDecl{}
-> ErrorWithoutFlag
TcRnLinearPatSyn{}
-> ErrorWithoutFlag
TcRnEmptyRecordUpdate
-> ErrorWithoutFlag
TcRnIllegalFieldPunning{}
-> ErrorWithoutFlag
TcRnIllegalWildcardsInRecord{}
-> ErrorWithoutFlag
TcRnDuplicateFieldName{}
-> ErrorWithoutFlag
TcRnIllegalViewPattern{}
-> ErrorWithoutFlag
TcRnCharLiteralOutOfRange{}
-> ErrorWithoutFlag
TcRnIllegalWildcardsInConstructor{}
-> ErrorWithoutFlag
TcRnIgnoringAnnotations{}
-> WarningWithoutFlag
TcRnAnnotationInSafeHaskell
-> ErrorWithoutFlag
TcRnInvalidTypeApplication{}
-> ErrorWithoutFlag
TcRnTagToEnumMissingValArg
-> ErrorWithoutFlag
TcRnTagToEnumUnspecifiedResTy{}
-> ErrorWithoutFlag
TcRnTagToEnumResTyNotAnEnum{}
-> ErrorWithoutFlag
TcRnArrowIfThenElsePredDependsOnResultTy
-> ErrorWithoutFlag
TcRnArrowCommandExpected{}
-> ErrorWithoutFlag
TcRnIllegalHsBootFileDecl
-> ErrorWithoutFlag
TcRnRecursivePatternSynonym{}
-> ErrorWithoutFlag
TcRnPartialTypeSigTyVarMismatch{}
-> ErrorWithoutFlag
TcRnPartialTypeSigBadQuantifier{}
-> ErrorWithoutFlag
TcRnPolymorphicBinderMissingSig{}
-> WarningWithFlag Opt_WarnMissingLocalSignatures
TcRnOverloadedSig{}
-> ErrorWithoutFlag
TcRnTupleConstraintInst{}
-> ErrorWithoutFlag
TcRnAbstractClassInst{}
-> ErrorWithoutFlag
TcRnNoClassInstHead{}
-> ErrorWithoutFlag
TcRnUserTypeError{}
-> ErrorWithoutFlag
TcRnConstraintInKind{}
-> ErrorWithoutFlag
TcRnUnboxedTupleTypeFuncArg{}
-> ErrorWithoutFlag
TcRnLinearFuncInKind{}
-> ErrorWithoutFlag
TcRnForAllEscapeError{}
-> ErrorWithoutFlag
TcRnVDQInTermType{}
-> ErrorWithoutFlag
TcRnIllegalEqualConstraints{}
-> ErrorWithoutFlag
TcRnBadQuantPredHead{}
-> ErrorWithoutFlag
TcRnIllegalTupleConstraint{}
-> ErrorWithoutFlag
TcRnNonTypeVarArgInConstraint{}
-> ErrorWithoutFlag
TcRnIllegalImplicitParam{}
-> ErrorWithoutFlag
TcRnIllegalConstraintSynonymOfKind{}
-> ErrorWithoutFlag
TcRnIllegalClassInst{}
-> ErrorWithoutFlag
TcRnOversaturatedVisibleKindArg{}
-> ErrorWithoutFlag
TcRnBadAssociatedType{}
-> ErrorWithoutFlag
TcRnForAllRankErr{}
-> ErrorWithoutFlag
diagnosticHints = \case
TcRnUnknownMessage m
-> diagnosticHints m
TcLevityPolyInType{}
-> noHints
TcRnMessageWithInfo _ msg_with_info
-> case msg_with_info of
TcRnMessageDetailed _ m -> diagnosticHints m
TcRnImplicitLift{}
-> noHints
TcRnUnusedPatternBinds{}
-> noHints
TcRnDodgyImports{}
-> noHints
TcRnDodgyExports{}
-> noHints
TcRnMissingImportList{}
-> noHints
TcRnUnsafeDueToPlugin{}
-> noHints
TcRnModMissingRealSrcSpan{}
-> noHints
TcRnIdNotExportedFromModuleSig name mod
-> [SuggestAddToHSigExportList name $ Just mod]
TcRnIdNotExportedFromLocalSig name
-> [SuggestAddToHSigExportList name Nothing]
TcRnShadowedName{}
-> noHints
TcRnDuplicateWarningDecls{}
-> noHints
TcRnSimplifierTooManyIterations{}
-> [SuggestIncreaseSimplifierIterations]
TcRnIllegalPatSynDecl{}
-> noHints
TcRnLinearPatSyn{}
-> noHints
TcRnEmptyRecordUpdate{}
-> noHints
TcRnIllegalFieldPunning{}
-> [suggestExtension LangExt.NamedFieldPuns]
TcRnIllegalWildcardsInRecord{}
-> [suggestExtension LangExt.RecordWildCards]
TcRnDuplicateFieldName{}
-> noHints
TcRnIllegalViewPattern{}
-> [suggestExtension LangExt.ViewPatterns]
TcRnCharLiteralOutOfRange{}
-> noHints
TcRnIllegalWildcardsInConstructor{}
-> noHints
TcRnIgnoringAnnotations{}
-> noHints
TcRnAnnotationInSafeHaskell
-> noHints
TcRnInvalidTypeApplication{}
-> noHints
TcRnTagToEnumMissingValArg
-> noHints
TcRnTagToEnumUnspecifiedResTy{}
-> noHints
TcRnTagToEnumResTyNotAnEnum{}
-> noHints
TcRnArrowIfThenElsePredDependsOnResultTy
-> noHints
TcRnArrowCommandExpected{}
-> noHints
TcRnIllegalHsBootFileDecl
-> noHints
TcRnRecursivePatternSynonym{}
-> noHints
TcRnPartialTypeSigTyVarMismatch{}
-> noHints
TcRnPartialTypeSigBadQuantifier{}
-> noHints
TcRnPolymorphicBinderMissingSig{}
-> noHints
TcRnOverloadedSig{}
-> noHints
TcRnTupleConstraintInst{}
-> noHints
TcRnAbstractClassInst{}
-> noHints
TcRnNoClassInstHead{}
-> noHints
TcRnUserTypeError{}
-> noHints
TcRnConstraintInKind{}
-> noHints
TcRnUnboxedTupleTypeFuncArg{}
-> [suggestExtension LangExt.UnboxedTuples]
TcRnLinearFuncInKind{}
-> noHints
TcRnForAllEscapeError{}
-> noHints
TcRnVDQInTermType{}
-> noHints
TcRnIllegalEqualConstraints{}
-> [suggestAnyExtension [LangExt.GADTs, LangExt.TypeFamilies]]
TcRnBadQuantPredHead{}
-> noHints
TcRnIllegalTupleConstraint{}
-> [suggestExtension LangExt.ConstraintKinds]
TcRnNonTypeVarArgInConstraint{}
-> [suggestExtension LangExt.FlexibleContexts]
TcRnIllegalImplicitParam{}
-> noHints
TcRnIllegalConstraintSynonymOfKind{}
-> [suggestExtension LangExt.ConstraintKinds]
TcRnIllegalClassInst{}
-> noHints
TcRnOversaturatedVisibleKindArg{}
-> noHints
TcRnBadAssociatedType{}
-> noHints
TcRnForAllRankErr rank _
-> case rank of
LimitedRank{} -> [suggestExtension LangExt.RankNTypes]
MonoTypeRankZero -> [suggestExtension LangExt.RankNTypes]
MonoTypeTyConArg -> [suggestExtension LangExt.ImpredicativeTypes]
MonoTypeSynArg -> [suggestExtension LangExt.LiberalTypeSynonyms]
MonoTypeConstraint -> [suggestExtension LangExt.QuantifiedConstraints]
_ -> noHints
messageWithInfoDiagnosticMessage :: UnitState
-> ErrInfo
-> DecoratedSDoc
-> DecoratedSDoc
messageWithInfoDiagnosticMessage unit_state ErrInfo{..} important =
let err_info' = map (pprWithUnitState unit_state) [errInfoContext, errInfoSupplementary]
in (mapDecoratedSDoc (pprWithUnitState unit_state) important) `unionDecoratedSDoc`
mkDecorated err_info'
dodgy_msg :: (Outputable a, Outputable b) => SDoc -> a -> b -> SDoc
dodgy_msg kind tc ie
= sep [ text "The" <+> kind <+> text "item"
<+> quotes (ppr ie)
<+> text "suggests that",
quotes (ppr tc) <+> text "has (in-scope) constructors or class methods,",
text "but it has none" ]
dodgy_msg_insert :: forall p . IdP (GhcPass p) -> IE (GhcPass p)
dodgy_msg_insert tc = IEThingAll noAnn ii
where
ii :: LIEWrappedName (IdP (GhcPass p))
ii = noLocA (IEName $ noLocA tc)
formatLevPolyErr :: Type -- representation-polymorphic type
-> SDoc
formatLevPolyErr ty
= hang (text "A representation-polymorphic type is not allowed here:")
2 (vcat [ text "Type:" <+> pprWithTYPE tidy_ty
, text "Kind:" <+> pprWithTYPE tidy_ki ])
where
(tidy_env, tidy_ty) = tidyOpenType emptyTidyEnv ty
tidy_ki = tidyType tidy_env (tcTypeKind ty)
pprLevityPolyInType :: Type -> LevityCheckProvenance -> SDoc
pprLevityPolyInType ty prov =
let extra = case prov of
LevityCheckInBinder v
-> text "In the type of binder" <+> quotes (ppr v)
LevityCheckInVarType
-> text "When trying to create a variable of type:" <+> ppr ty
LevityCheckInWildcardPattern
-> text "In a wildcard pattern"
LevityCheckInUnboxedTuplePattern p
-> text "In the type of an element of an unboxed tuple pattern:" $$ ppr p
LevityCheckPatSynSig
-> empty
LevityCheckCmdStmt
-> empty -- I (Richard E, Dec '16) have no idea what to say here
LevityCheckMkCmdEnv id_var
-> text "In the result of the function" <+> quotes (ppr id_var)
LevityCheckDoCmd do_block
-> text "In the do-command:" <+> ppr do_block
LevityCheckDesugaringCmd cmd
-> text "When desugaring the command:" <+> ppr cmd
LevityCheckInCmd body
-> text "In the command:" <+> ppr body
LevityCheckInFunUse using
-> text "In the result of a" <+> quotes (text "using") <+> text "function:" <+> ppr using
LevityCheckInValidDataCon
-> empty
LevityCheckInValidClass
-> empty
in formatLevPolyErr ty $$ extra
pprRecordFieldPart :: RecordFieldPart -> SDoc
pprRecordFieldPart = \case
RecordFieldConstructor{} -> text "construction"
RecordFieldPattern{} -> text "pattern"
RecordFieldUpdate -> text "update"
|