@@ -903,7 +903,17 @@ infer typer = loop
903
903
return (VRecord (Dhall.Map. union xRs' xLs'))
904
904
905
905
RecordCompletion l r -> do
906
- loop ctx (Annot (Prefer (Field l " default" ) r) (Field l " Type" ))
906
+ _L' <- loop ctx l
907
+
908
+ case _L' of
909
+ VRecord xLs'
910
+ | not (Dhall.Map. member " default" xLs')
911
+ -> die (InvalidRecordCompletion " default" l)
912
+ | not (Dhall.Map. member " Type" xLs')
913
+ -> die (InvalidRecordCompletion " Type" l)
914
+ | otherwise
915
+ -> loop ctx (Annot (Prefer (Field l " default" ) r) (Field l " Type" ))
916
+ _ -> die (CompletionSchemaMustBeARecord l (quote names _L'))
907
917
908
918
Merge t u mT₁ -> do
909
919
_T' <- loop ctx t
@@ -940,7 +950,8 @@ infer typer = loop
940
950
941
951
if Data.Set. null diffU
942
952
then return ()
943
- else die (MissingHandler diffU)
953
+ else let (exemplar,rest) = Data.Set. deleteFindMin diffU
954
+ in die (MissingHandler exemplar rest)
944
955
945
956
let match _y _T₀' Nothing =
946
957
return _T₀'
@@ -1290,6 +1301,8 @@ data TypeMessage s a
1290
1301
| AlternativeAnnotationMismatch Text (Expr s a ) Const Text (Expr s a ) Const
1291
1302
| ListAppendMismatch (Expr s a ) (Expr s a )
1292
1303
| MustCombineARecord Char (Expr s a ) (Expr s a )
1304
+ | InvalidRecordCompletion Text (Expr s a )
1305
+ | CompletionSchemaMustBeARecord (Expr s a ) (Expr s a )
1293
1306
| CombineTypesRequiresRecordType (Expr s a ) (Expr s a )
1294
1307
| RecordTypeMismatch Const Const (Expr s a ) (Expr s a )
1295
1308
| FieldCollision Text
@@ -1302,7 +1315,7 @@ data TypeMessage s a
1302
1315
| MapTypeMismatch (Expr s a ) (Expr s a )
1303
1316
| MissingToMapType
1304
1317
| UnusedHandler (Set Text )
1305
- | MissingHandler (Set Text )
1318
+ | MissingHandler Text (Set Text )
1306
1319
| HandlerInputTypeMismatch Text (Expr s a ) (Expr s a )
1307
1320
| DisallowedHandlerType Text (Expr s a ) (Expr s a ) Text
1308
1321
| HandlerOutputTypeMismatch Text (Expr s a ) Text (Expr s a )
@@ -2028,7 +2041,9 @@ prettyTypeMessage Untyped = ErrorMessages {..}
2028
2041
2029
2042
prettyTypeMessage (InvalidPredicate expr0 expr1) = ErrorMessages {.. }
2030
2043
where
2031
- short = " Invalid predicate for ❰if❱"
2044
+ short = " Invalid predicate for ❰if❱: "
2045
+ <> " \n "
2046
+ <> Dhall.Diff. doc (Dhall.Diff. diffNormalized Bool expr1)
2032
2047
2033
2048
long =
2034
2049
" Explanation: Every ❰if❱ expression begins with a predicate which must have type \n \
@@ -2677,6 +2692,55 @@ prettyTypeMessage (ListAppendMismatch expr0 expr1) = ErrorMessages {..}
2677
2692
txt0 = insert expr0
2678
2693
txt1 = insert expr1
2679
2694
2695
+ prettyTypeMessage (CompletionSchemaMustBeARecord expr0 expr1) = ErrorMessages {.. }
2696
+ where
2697
+ short = " The completion schema must be a record"
2698
+
2699
+ long =
2700
+ " Explanation: You can complete records using the ❰::❱ operator: \n \
2701
+ \ \n \
2702
+ \ ┌─────────────────────────────────────────────────────────────────────────┐ \n \
2703
+ \ │ {Type = {foo : Bool, bar : Natural}, default = {bar = 2}::{foo = True}} │ \n \
2704
+ \ └─────────────────────────────────────────────────────────────────────────┘ \n \
2705
+ \ \n \
2706
+ \... The left-hand side of :: must be a record with 'Type' and 'default' keys \n \
2707
+ \ \n \
2708
+ \You tried to record complete the following value: \n \
2709
+ \ \n \
2710
+ \" <> txt0 <> " \n \
2711
+ \ \n \
2712
+ \... which is not a record. It is: \n \
2713
+ \ \n \
2714
+ \" <> txt1 <> " \n "
2715
+ where
2716
+ txt0 = insert expr0
2717
+ txt1 = insert expr1
2718
+
2719
+ prettyTypeMessage (InvalidRecordCompletion fieldName expr0) = ErrorMessages {.. }
2720
+ where
2721
+ short = " Completion schema is missing a field: " <> pretty fieldName
2722
+
2723
+ long =
2724
+ " Explanation: You can complete records using the ❰::❱ operator like this:\n \
2725
+ \ \n \
2726
+ \ ┌─────────────────────────────────────────────────────────────────────────┐ \n \
2727
+ \ │ {Type = {foo : Bool, bar : Natural}, default = {bar = 2}::{foo = True}} │ \n \
2728
+ \ └─────────────────────────────────────────────────────────────────────────┘ \n \
2729
+ \ \n \
2730
+ \... but you need to have both Type and default fields in the completion schema \n \
2731
+ \ (the record on the left of the the ::). \n \
2732
+ \ \n \
2733
+ \You tried to do record completion using the schema: \n \
2734
+ \ \n \
2735
+ \" <> txt0 <> " \n \
2736
+ \ \n \
2737
+ \... which is missing the key: \n \
2738
+ \ \n \
2739
+ \" <> txt1 <> " \n "
2740
+ where
2741
+ txt0 = insert expr0
2742
+ txt1 = pretty fieldName
2743
+
2680
2744
prettyTypeMessage (MustCombineARecord c expr0 expr1) = ErrorMessages {.. }
2681
2745
where
2682
2746
short = " You can only combine records"
@@ -2825,7 +2889,7 @@ prettyTypeMessage (RecordTypeMismatch const0 const1 expr0 expr1) =
2825
2889
2826
2890
prettyTypeMessage (FieldCollision k) = ErrorMessages {.. }
2827
2891
where
2828
- short = " Field collision"
2892
+ short = " Field collision on: " <> Dhall.Pretty.Internal. prettyLabel k
2829
2893
2830
2894
long =
2831
2895
" Explanation: You can combine records or record types if they don't share any \n \
@@ -3035,9 +3099,12 @@ prettyTypeMessage (UnusedHandler ks) = ErrorMessages {..}
3035
3099
where
3036
3100
txt0 = insert (Text. intercalate " , " (Data.Set. toList ks))
3037
3101
3038
- prettyTypeMessage (MissingHandler ks) = ErrorMessages {.. }
3102
+ prettyTypeMessage (MissingHandler exemplar ks) = ErrorMessages {.. }
3039
3103
where
3040
- short = " Missing handler"
3104
+ short = case Data.Set. toList ks of
3105
+ [] -> " Missing handler: " <> Dhall.Pretty.Internal. prettyLabel exemplar
3106
+ xs@ (_: _) -> " Missing handlers: " <> (Pretty. hsep . Pretty. punctuate Pretty. comma
3107
+ . map Dhall.Pretty.Internal. prettyLabel $ exemplar: xs)
3041
3108
3042
3109
long =
3043
3110
" Explanation: You can ❰merge❱ the alternatives of a union using a record with one\n \
@@ -3073,7 +3140,7 @@ prettyTypeMessage (MissingHandler ks) = ErrorMessages {..}
3073
3140
\ \n \
3074
3141
\" <> txt0 <> " \n "
3075
3142
where
3076
- txt0 = insert (Text. intercalate " , " (Data.Set. toList ks))
3143
+ txt0 = insert (Text. intercalate " , " (exemplar : Data.Set. toList ks))
3077
3144
3078
3145
prettyTypeMessage MissingMergeType =
3079
3146
ErrorMessages {.. }
@@ -3336,7 +3403,7 @@ prettyTypeMessage (HandlerOutputTypeMismatch key0 expr0 key1 expr1) =
3336
3403
3337
3404
prettyTypeMessage (HandlerNotAFunction k expr0) = ErrorMessages {.. }
3338
3405
where
3339
- short = " Handler is not a function"
3406
+ short = " Handler for " <> Dhall.Pretty.Internal. prettyLabel k <> " is not a function"
3340
3407
3341
3408
long =
3342
3409
" Explanation: You can ❰merge❱ the alternatives of a union using a record with one\n \
@@ -3729,7 +3796,7 @@ prettyTypeMessage (MissingField k expr0) = ErrorMessages {..}
3729
3796
3730
3797
prettyTypeMessage (MissingConstructor k expr0) = ErrorMessages {.. }
3731
3798
where
3732
- short = " Missing constructor"
3799
+ short = " Missing constructor: " <> Dhall.Pretty.Internal. prettyLabel k
3733
3800
3734
3801
long =
3735
3802
" Explanation: You can access constructors from unions, like this: \n \
@@ -4343,6 +4410,10 @@ messageExpressions f m = case m of
4343
4410
ListAppendMismatch <$> f a <*> f b
4344
4411
MustCombineARecord a b c ->
4345
4412
MustCombineARecord <$> pure a <*> f b <*> f c
4413
+ InvalidRecordCompletion a l ->
4414
+ InvalidRecordCompletion a <$> f l
4415
+ CompletionSchemaMustBeARecord l r ->
4416
+ CompletionSchemaMustBeARecord <$> f l <*> f r
4346
4417
CombineTypesRequiresRecordType a b ->
4347
4418
CombineTypesRequiresRecordType <$> f a <*> f b
4348
4419
RecordTypeMismatch a b c d ->
@@ -4367,8 +4438,8 @@ messageExpressions f m = case m of
4367
4438
pure MissingToMapType
4368
4439
UnusedHandler a ->
4369
4440
UnusedHandler <$> pure a
4370
- MissingHandler a ->
4371
- MissingHandler <$> pure a
4441
+ MissingHandler e a ->
4442
+ MissingHandler <$> pure e <*> pure a
4372
4443
HandlerInputTypeMismatch a b c ->
4373
4444
HandlerInputTypeMismatch <$> pure a <*> f b <*> f c
4374
4445
DisallowedHandlerType a b c d ->
0 commit comments