on master help sign in
Move Report.toCodeSnippet to Code.toSnippet
e43ce3dEvan Czaplicki
compiler/src/Reporting/Error/Canonicalize.hs+33−33
@@ -151,7 +151,7 @@ toReport source err =
151 numDefArgs = numTypeArgs + leftovers
151 numDefArgs = numTypeArgs + leftovers
152 in
152 in
153 Report.Report "BAD TYPE ANNOTATION" region [] $
153 Report.Report "BAD TYPE ANNOTATION" region [] $
154− Report.toCodeSnippet source region Nothing
154+ Code.toSnippet source region Nothing
155 (
155 (
156 D.reflow $
156 D.reflow $
157 "The type annotation for `" <> Name.toChars name <> "` says it can accept "
157 "The type annotation for `" <> Name.toChars name <> "` says it can accept "
@@ -185,7 +185,7 @@ toReport source err =
185 in
185 in
186 if actual < expected then
186 if actual < expected then
187 Report.Report "TOO FEW ARGS" region [] $
187 Report.Report "TOO FEW ARGS" region [] $
188− Report.toCodeSnippet source region Nothing
188+ Code.toSnippet source region Nothing
189 (
189 (
190 D.reflow $
190 D.reflow $
191 "The `" <> Name.toChars name <> "` " <> thing <> " needs "
191 "The `" <> Name.toChars name <> "` " <> thing <> " needs "
@@ -197,7 +197,7 @@ toReport source err =
197
197
198 else
198 else
199 Report.Report "TOO MANY ARGS" region [] $
199 Report.Report "TOO MANY ARGS" region [] $
200− Report.toCodeSnippet source region Nothing
200+ Code.toSnippet source region Nothing
201 (
201 (
202 D.reflow $
202 D.reflow $
203 "The `" <> Name.toChars name <> "` " <> thing <> " needs "
203 "The `" <> Name.toChars name <> "` " <> thing <> " needs "
@@ -211,7 +211,7 @@ toReport source err =
211
211
212 Binop region op1 op2 ->
212 Binop region op1 op2 ->
213 Report.Report "INFIX PROBLEM" region [] $
213 Report.Report "INFIX PROBLEM" region [] $
214− Report.toCodeSnippet source region Nothing
214+ Code.toSnippet source region Nothing
215 (
215 (
216 D.reflow $
216 D.reflow $
217 "You cannot mix (" <> Name.toChars op1 <> ") and (" <> Name.toChars op2 <> ") without parentheses."
217 "You cannot mix (" <> Name.toChars op1 <> ") and (" <> Name.toChars op2 <> ") without parentheses."
@@ -268,7 +268,7 @@ toReport source err =
268
268
269 EffectNotFound region name ->
269 EffectNotFound region name ->
270 Report.Report "EFFECT PROBLEM" region [] $
270 Report.Report "EFFECT PROBLEM" region [] $
271− Report.toCodeSnippet source region Nothing
271+ Code.toSnippet source region Nothing
272 (
272 (
273 D.reflow $
273 D.reflow $
274 "You have declared that `" ++ Name.toChars name ++ "` is an effect type:"
274 "You have declared that `" ++ Name.toChars name ++ "` is an effect type:"
@@ -279,7 +279,7 @@ toReport source err =
279
279
280 EffectFunctionNotFound region name ->
280 EffectFunctionNotFound region name ->
281 Report.Report "EFFECT PROBLEM" region [] $
281 Report.Report "EFFECT PROBLEM" region [] $
282− Report.toCodeSnippet source region Nothing
282+ Code.toSnippet source region Nothing
283 (
283 (
284 D.reflow $
284 D.reflow $
285 "This kind of effect module must define a `" ++ Name.toChars name ++ "` function."
285 "This kind of effect module must define a `" ++ Name.toChars name ++ "` function."
@@ -295,7 +295,7 @@ toReport source err =
295 "You are trying to expose `" <> Name.toChars name <> "` multiple times!"
295 "You are trying to expose `" <> Name.toChars name <> "` multiple times!"
296 in
296 in
297 Report.Report "REDUNDANT EXPORT" r2 [] $
297 Report.Report "REDUNDANT EXPORT" r2 [] $
298− Report.toCodePair source r1 r2
298+ Code.toPair source r1 r2
299 (
299 (
300 D.reflow messageThatEndsWithPunctuation
300 D.reflow messageThatEndsWithPunctuation
301 ,
301 ,
@@ -339,7 +339,7 @@ toReport source err =
339
339
340 ExportOpenAlias region name ->
340 ExportOpenAlias region name ->
341 Report.Report "BAD EXPORT" region [] $
341 Report.Report "BAD EXPORT" region [] $
342− Report.toCodeSnippet source region Nothing
342+ Code.toSnippet source region Nothing
343 (
343 (
344 D.reflow $
344 D.reflow $
345 "The (..) syntax is for exposing union type constructors. It cannot be used with a type alias like `"
345 "The (..) syntax is for exposing union type constructors. It cannot be used with a type alias like `"
@@ -351,7 +351,7 @@ toReport source err =
351
351
352 ImportCtorByName region ctor tipe ->
352 ImportCtorByName region ctor tipe ->
353 Report.Report "BAD IMPORT" region [] $
353 Report.Report "BAD IMPORT" region [] $
354− Report.toCodeSnippet source region Nothing
354+ Code.toSnippet source region Nothing
355 (
355 (
356 D.reflow $
356 D.reflow $
357 "You are trying to import the `" <> Name.toChars ctor
357 "You are trying to import the `" <> Name.toChars ctor
@@ -371,7 +371,7 @@ toReport source err =
371 -- So this error should never actually get printed out.
371 -- So this error should never actually get printed out.
372 --
372 --
373 Report.Report "UNKNOWN IMPORT" region [] $
373 Report.Report "UNKNOWN IMPORT" region [] $
374− Report.toCodeSnippet source region Nothing
374+ Code.toSnippet source region Nothing
375 (
375 (
376 D.reflow $
376 D.reflow $
377 "I could not find a `" <> Name.toChars name <> "` module to import!"
377 "I could not find a `" <> Name.toChars name <> "` module to import!"
@@ -381,7 +381,7 @@ toReport source err =
381
381
382 ImportOpenAlias region name ->
382 ImportOpenAlias region name ->
383 Report.Report "BAD IMPORT" region [] $
383 Report.Report "BAD IMPORT" region [] $
384− Report.toCodeSnippet source region Nothing
384+ Code.toSnippet source region Nothing
385 (
385 (
386 D.reflow $
386 D.reflow $
387 "The `" <> Name.toChars name <> "` type alias cannot be followed by (..) like this:"
387 "The `" <> Name.toChars name <> "` type alias cannot be followed by (..) like this:"
@@ -402,7 +402,7 @@ toReport source err =
402 Suggest.sort (Name.toChars home) Name.toChars possibleNames
402 Suggest.sort (Name.toChars home) Name.toChars possibleNames
403 in
403 in
404 Report.Report "BAD IMPORT" region suggestions $
404 Report.Report "BAD IMPORT" region suggestions $
405− Report.toCodeSnippet source region Nothing
405+ Code.toSnippet source region Nothing
406 (
406 (
407 D.reflow $
407 D.reflow $
408 "The `" <> Name.toChars home
408 "The `" <> Name.toChars home
@@ -435,7 +435,7 @@ toReport source err =
435 NotFoundBinop region op locals ->
435 NotFoundBinop region op locals ->
436 if op == "===" then
436 if op == "===" then
437 Report.Report "UNKNOWN OPERATOR" region ["=="] $
437 Report.Report "UNKNOWN OPERATOR" region ["=="] $
438− Report.toCodeSnippet source region Nothing
438+ Code.toSnippet source region Nothing
439 (
439 (
440 "Elm does not have a (===) operator like JavaScript."
440 "Elm does not have a (===) operator like JavaScript."
441 ,
441 ,
@@ -444,7 +444,7 @@ toReport source err =
444
444
445 else if op == "!=" || op == "!==" then
445 else if op == "!=" || op == "!==" then
446 Report.Report "UNKNOWN OPERATOR" region ["/="] $
446 Report.Report "UNKNOWN OPERATOR" region ["/="] $
447− Report.toCodeSnippet source region Nothing
447+ Code.toSnippet source region Nothing
448 (
448 (
449 D.reflow $
449 D.reflow $
450 "Elm uses a different name for the “not equal” operator:"
450 "Elm uses a different name for the “not equal” operator:"
@@ -459,7 +459,7 @@ toReport source err =
459
459
460 else if op == "**" then
460 else if op == "**" then
461 Report.Report "UNKNOWN OPERATOR" region ["^","*"] $
461 Report.Report "UNKNOWN OPERATOR" region ["^","*"] $
462− Report.toCodeSnippet source region Nothing
462+ Code.toSnippet source region Nothing
463 (
463 (
464 D.reflow $
464 D.reflow $
465 "I do not recognize the (**) operator:"
465 "I do not recognize the (**) operator:"
@@ -470,7 +470,7 @@ toReport source err =
470
470
471 else if op == "%" then
471 else if op == "%" then
472 Report.Report "UNKNOWN OPERATOR" region [] $
472 Report.Report "UNKNOWN OPERATOR" region [] $
473− Report.toCodeSnippet source region Nothing
473+ Code.toSnippet source region Nothing
474 (
474 (
475 D.reflow $
475 D.reflow $
476 "Elm does not use (%) as the remainder operator:"
476 "Elm does not use (%) as the remainder operator:"
@@ -497,7 +497,7 @@ toReport source err =
497 D.green $ "(" <> altOp <> ")"
497 D.green $ "(" <> altOp <> ")"
498 in
498 in
499 Report.Report "UNKNOWN OPERATOR" region suggestions $
499 Report.Report "UNKNOWN OPERATOR" region suggestions $
500− Report.toCodeSnippet source region Nothing
500+ Code.toSnippet source region Nothing
501 (
501 (
502 D.reflow $
502 D.reflow $
503 "I do not recognize the (" ++ Name.toChars op ++ ") operator."
503 "I do not recognize the (" ++ Name.toChars op ++ ") operator."
@@ -515,7 +515,7 @@ toReport source err =
515
515
516 PatternHasRecordCtor region name ->
516 PatternHasRecordCtor region name ->
517 Report.Report "BAD PATTERN" region [] $
517 Report.Report "BAD PATTERN" region [] $
518− Report.toCodeSnippet source region Nothing
518+ Code.toSnippet source region Nothing
519 (
519 (
520 D.reflow $
520 D.reflow $
521 "You can construct records by using `" <> Name.toChars name
521 "You can construct records by using `" <> Name.toChars name
@@ -529,7 +529,7 @@ toReport source err =
529 let
529 let
530 formatDetails (aBadKindOfThing, elaboration) =
530 formatDetails (aBadKindOfThing, elaboration) =
531 Report.Report "PORT ERROR" region [] $
531 Report.Report "PORT ERROR" region [] $
532− Report.toCodeSnippet source region Nothing
532+ Code.toSnippet source region Nothing
533 (
533 (
534 D.reflow $
534 D.reflow $
535 "The `" <> Name.toChars portName <> "` port is trying to transmit " <> aBadKindOfThing <> ":"
535 "The `" <> Name.toChars portName <> "` port is trying to transmit " <> aBadKindOfThing <> ":"
@@ -595,7 +595,7 @@ toReport source err =
595 let
595 let
596 formatDetails (before, after) =
596 formatDetails (before, after) =
597 Report.Report "BAD PORT" region [] $
597 Report.Report "BAD PORT" region [] $
598− Report.toCodeSnippet source region Nothing $
598+ Code.toSnippet source region Nothing $
599 (
599 (
600 D.reflow before
600 D.reflow before
601 ,
601 ,
@@ -674,7 +674,7 @@ toReport source err =
674 D.fillSep $ map (D.dullyellow . D.fromChars) (words question) ++ map D.fromChars (words details)
674 D.fillSep $ map (D.dullyellow . D.fromChars) (words question) ++ map D.fromChars (words details)
675 in
675 in
676 Report.Report "CYCLIC DEFINITION" region [] $
676 Report.Report "CYCLIC DEFINITION" region [] $
677− Report.toCodeSnippet source region Nothing $
677+ Code.toSnippet source region Nothing $
678 case names of
678 case names of
679 [] ->
679 [] ->
680 (
680 (
@@ -716,7 +716,7 @@ toReport source err =
716
716
717 RecursiveLet (A.At region name) names ->
717 RecursiveLet (A.At region name) names ->
718 Report.Report "CYCLIC VALUE" region [] $
718 Report.Report "CYCLIC VALUE" region [] $
719− Report.toCodeSnippet source region Nothing $
719+ Code.toSnippet source region Nothing $
720 case names of
720 case names of
721 [] ->
721 [] ->
722 let
722 let
@@ -762,7 +762,7 @@ toReport source err =
762
762
763 Shadowing name r1 r2 ->
763 Shadowing name r1 r2 ->
764 Report.Report "SHADOWING" r2 [] $
764 Report.Report "SHADOWING" r2 [] $
765− Report.toCodePair source r1 r2
765+ Code.toPair source r1 r2
766 ( "These variables cannot have the same name:"
766 ( "These variables cannot have the same name:"
767 , advice
767 , advice
768 )
768 )
@@ -783,7 +783,7 @@ toReport source err =
783
783
784 TupleLargerThanThree region ->
784 TupleLargerThanThree region ->
785 Report.Report "BAD TUPLE" region [] $
785 Report.Report "BAD TUPLE" region [] $
786− Report.toCodeSnippet source region Nothing
786+ Code.toSnippet source region Nothing
787 (
787 (
788 "I only accept tuples with two or three items. This has too many:"
788 "I only accept tuples with two or three items. This has too many:"
789 ,
789 ,
@@ -832,7 +832,7 @@ toReport source err =
832 )
832 )
833 in
833 in
834 Report.Report title aliasRegion [] $
834 Report.Report title aliasRegion [] $
835− Report.toCodeSnippet source aliasRegion subRegion
835+ Code.toSnippet source aliasRegion subRegion
836 (
836 (
837 D.fillSep overview
837 D.fillSep overview
838 ,
838 ,
@@ -885,7 +885,7 @@ toReport source err =
885
885
886 in
886 in
887 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
887 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
888− Report.toCodeSnippet source aliasRegion Nothing
888+ Code.toSnippet source aliasRegion Nothing
889 (
889 (
890 D.reflow $
890 D.reflow $
891 "Type alias `" <> Name.toChars typeName <> "` has some type variable problems."
891 "Type alias `" <> Name.toChars typeName <> "` has some type variable problems."
@@ -932,7 +932,7 @@ unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion)
932 )
932 )
933 in
933 in
934 Report.Report title declRegion [] $
934 Report.Report title declRegion [] $
935− Report.toCodeSnippet source declRegion subRegion
935+ Code.toSnippet source declRegion subRegion
936 (
936 (
937 D.fillSep overview
937 D.fillSep overview
938 ,
938 ,
@@ -960,7 +960,7 @@ unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion)
960nameClash :: Code.Source -> A.Region -> A.Region -> String -> Report.Report
960nameClash :: Code.Source -> A.Region -> A.Region -> String -> Report.Report
961nameClash source r1 r2 messageThatEndsWithPunctuation =
961nameClash source r1 r2 messageThatEndsWithPunctuation =
962 Report.Report "NAME CLASH" r2 [] $
962 Report.Report "NAME CLASH" r2 [] $
963− Report.toCodePair source r1 r2
963+ Code.toPair source r1 r2
964 (
964 (
965 D.reflow messageThatEndsWithPunctuation
965 D.reflow messageThatEndsWithPunctuation
966 ,
966 ,
@@ -982,7 +982,7 @@ nameClash source r1 r2 messageThatEndsWithPunctuation =
982ambiguousName :: Code.Source -> A.Region -> Maybe Name.Name -> Name.Name -> [ModuleName.Canonical] -> String -> Report.Report
982ambiguousName :: Code.Source -> A.Region -> Maybe Name.Name -> Name.Name -> [ModuleName.Canonical] -> String -> Report.Report
983ambiguousName source region maybePrefix name possibleHomes thing =
983ambiguousName source region maybePrefix name possibleHomes thing =
984 Report.Report "AMBIGUOUS NAME" region [] $
984 Report.Report "AMBIGUOUS NAME" region [] $
985− Report.toCodeSnippet source region Nothing $
985+ Code.toSnippet source region Nothing $
986 case maybePrefix of
986 case maybePrefix of
987 Nothing ->
987 Nothing ->
988 let
988 let
@@ -1065,7 +1065,7 @@ notFound source region maybePrefix name thing (PossibleNames locals quals) =
1065
1065
1066 in
1066 in
1067 Report.Report "NAMING ERROR" region nearbyNames $
1067 Report.Report "NAMING ERROR" region nearbyNames $
1068− Report.toCodeSnippet source region Nothing
1068+ Code.toSnippet source region Nothing
1069 (
1069 (
1070 D.reflow $
1070 D.reflow $
1071 "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
1071 "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
@@ -1195,7 +1195,7 @@ _argMismatchReport source region kind name expected actual =
1195 <> " arguments"
1195 <> " arguments"
1196 in
1196 in
1197 Report.Report (map Char.toUpper numArgs) region [] $
1197 Report.Report (map Char.toUpper numArgs) region [] $
1198− Report.toCodeSnippet source region Nothing
1198+ Code.toSnippet source region Nothing
1199 (
1199 (
1200 D.reflow $
1200 D.reflow $
1201 kind <> " " <> Name.toChars name <> " has " <> numArgs <> "."
1201 kind <> " " <> Name.toChars name <> " has " <> numArgs <> "."
@@ -1214,7 +1214,7 @@ aliasRecursionReport source region name args tipe others =
1214 case others of
1214 case others of
1215 [] ->
1215 [] ->
1216 Report.Report "ALIAS PROBLEM" region [] $
1216 Report.Report "ALIAS PROBLEM" region [] $
1217− Report.toCodeSnippet source region Nothing
1217+ Code.toSnippet source region Nothing
1218 (
1218 (
1219 "This type alias is recursive, forming an infinite type!"
1219 "This type alias is recursive, forming an infinite type!"
1220 ,
1220 ,
@@ -1233,7 +1233,7 @@ aliasRecursionReport source region name args tipe others =
1233
1233
1234 _ ->
1234 _ ->
1235 Report.Report "ALIAS PROBLEM" region [] $
1235 Report.Report "ALIAS PROBLEM" region [] $
1236− Report.toCodeSnippet source region Nothing
1236+ Code.toSnippet source region Nothing
1237 (
1237 (
1238 "This type alias is part of a mutually recursive set of type aliases."
1238 "This type alias is part of a mutually recursive set of type aliases."
1239 ,
1239 ,
compiler/src/Reporting/Error/Docs.hs+5−5
@@ -63,7 +63,7 @@ toReport source err =
63
63
64 Duplicate name r1 r2 ->
64 Duplicate name r1 r2 ->
65 Report.Report "DUPLICATE DOCS" r2 [] $
65 Report.Report "DUPLICATE DOCS" r2 [] $
66− Report.toCodePair source r1 r2
66+ Code.toPair source r1 r2
67 (
67 (
68 D.reflow $
68 D.reflow $
69 "There can only be one `" <> Name.toChars name
69 "There can only be one `" <> Name.toChars name
@@ -83,7 +83,7 @@ toReport source err =
83
83
84 OnlyInDocs name region ->
84 OnlyInDocs name region ->
85 Report.Report "DOCS MISTAKE" region [] $
85 Report.Report "DOCS MISTAKE" region [] $
86− Report.toCodeSnippet source region Nothing
86+ Code.toSnippet source region Nothing
87 (
87 (
88 D.reflow $
88 D.reflow $
89 "I do not see `" <> Name.toChars name
89 "I do not see `" <> Name.toChars name
@@ -96,7 +96,7 @@ toReport source err =
96
96
97 OnlyInExports name region ->
97 OnlyInExports name region ->
98 Report.Report "DOCS MISTAKE" region [] $
98 Report.Report "DOCS MISTAKE" region [] $
99− Report.toCodeSnippet source region Nothing
99+ Code.toSnippet source region Nothing
100 (
100 (
101 D.reflow $
101 D.reflow $
102 "I do not see `" <> Name.toChars name
102 "I do not see `" <> Name.toChars name
@@ -112,7 +112,7 @@ toReport source err =
112
112
113 NoComment name region ->
113 NoComment name region ->
114 Report.Report "NO DOCS" region [] $
114 Report.Report "NO DOCS" region [] $
115− Report.toCodeSnippet source region Nothing
115+ Code.toSnippet source region Nothing
116 (
116 (
117 D.reflow $
117 D.reflow $
118 "The `" <> Name.toChars name <> "` definition does not have a documentation comment."
118 "The `" <> Name.toChars name <> "` definition does not have a documentation comment."
@@ -126,7 +126,7 @@ toReport source err =
126
126
127 NoAnnotation name region ->
127 NoAnnotation name region ->
128 Report.Report "NO TYPE ANNOTATION" region [] $
128 Report.Report "NO TYPE ANNOTATION" region [] $
129− Report.toCodeSnippet source region Nothing
129+ Code.toSnippet source region Nothing
130 (
130 (
131 D.reflow $
131 D.reflow $
132 "The `" <> Name.toChars name <> "` definition does not have a type annotation."
132 "The `" <> Name.toChars name <> "` definition does not have a type annotation."
compiler/src/Reporting/Error/Import.hs+4−4
@@ -48,7 +48,7 @@ toReport source (Error region name unimportedModules problem) =
48 case problem of
48 case problem of
49 NotFound ->
49 NotFound ->
50 Report.Report "MODULE NOT FOUND" region [] $
50 Report.Report "MODULE NOT FOUND" region [] $
51− Report.toCodeSnippet source region Nothing
51+ Code.toSnippet source region Nothing
52 (
52 (
53 D.reflow $
53 D.reflow $
54 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
54 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
@@ -83,7 +83,7 @@ toReport source (Error region name unimportedModules problem) =
83
83
84 Ambiguous path _ pkg _ ->
84 Ambiguous path _ pkg _ ->
85 Report.Report "AMBIGUOUS IMPORT" region [] $
85 Report.Report "AMBIGUOUS IMPORT" region [] $
86− Report.toCodeSnippet source region Nothing
86+ Code.toSnippet source region Nothing
87 (
87 (
88 D.reflow $
88 D.reflow $
89 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
89 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
@@ -105,7 +105,7 @@ toReport source (Error region name unimportedModules problem) =
105
105
106 AmbiguousLocal path1 path2 paths ->
106 AmbiguousLocal path1 path2 paths ->
107 Report.Report "AMBIGUOUS IMPORT" region [] $
107 Report.Report "AMBIGUOUS IMPORT" region [] $
108− Report.toCodeSnippet source region Nothing
108+ Code.toSnippet source region Nothing
109 (
109 (
110 D.reflow $
110 D.reflow $
111 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
111 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
@@ -125,7 +125,7 @@ toReport source (Error region name unimportedModules problem) =
125
125
126 AmbiguousForeign pkg1 pkg2 pkgs ->
126 AmbiguousForeign pkg1 pkg2 pkgs ->
127 Report.Report "AMBIGUOUS IMPORT" region [] $
127 Report.Report "AMBIGUOUS IMPORT" region [] $
128− Report.toCodeSnippet source region Nothing
128+ Code.toSnippet source region Nothing
129 (
129 (
130 D.reflow $
130 D.reflow $
131 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
131 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
compiler/src/Reporting/Error/Main.hs+3−3
@@ -38,7 +38,7 @@ toReport localizer source err =
38 case err of
38 case err of
39 BadType region tipe ->
39 BadType region tipe ->
40 Report.Report "BAD MAIN TYPE" region [] $
40 Report.Report "BAD MAIN TYPE" region [] $
41− Report.toCodeSnippet source region Nothing
41+ Code.toSnippet source region Nothing
42 (
42 (
43 "I cannot handle this type of `main` value:"
43 "I cannot handle this type of `main` value:"
44 ,
44 ,
@@ -53,7 +53,7 @@ toReport localizer source err =
53
53
54 BadCycle region name names ->
54 BadCycle region name names ->
55 Report.Report "BAD MAIN" region [] $
55 Report.Report "BAD MAIN" region [] $
56− Report.toCodeSnippet source region Nothing
56+ Code.toSnippet source region Nothing
57 (
57 (
58 "A `main` definition cannot be defined in terms of itself."
58 "A `main` definition cannot be defined in terms of itself."
59 ,
59 ,
@@ -69,7 +69,7 @@ toReport localizer source err =
69 let
69 let
70 formatDetails (aBadKindOfThing, butThatIsNoGood) =
70 formatDetails (aBadKindOfThing, butThatIsNoGood) =
71 Report.Report "BAD FLAGS" region [] $
71 Report.Report "BAD FLAGS" region [] $
72− Report.toCodeSnippet source region Nothing
72+ Code.toSnippet source region Nothing
73 (
73 (
74 D.reflow $
74 D.reflow $
75 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
75 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
compiler/src/Reporting/Error/Pattern.hs+4−4
@@ -24,7 +24,7 @@ toReport source err =
24 case err of
24 case err of
25 P.Redundant caseRegion patternRegion index ->
25 P.Redundant caseRegion patternRegion index ->
26 Report.Report "REDUNDANT PATTERN" patternRegion [] $
26 Report.Report "REDUNDANT PATTERN" patternRegion [] $
27− Report.toCodeSnippet source caseRegion (Just patternRegion)
27+ Code.toSnippet source caseRegion (Just patternRegion)
28 (
28 (
29 D.reflow $
29 D.reflow $
30 "The " <> D.intToOrdinal index <> " pattern is redundant:"
30 "The " <> D.intToOrdinal index <> " pattern is redundant:"
@@ -38,7 +38,7 @@ toReport source err =
38 case context of
38 case context of
39 P.BadArg ->
39 P.BadArg ->
40 Report.Report "UNSAFE PATTERN" region [] $
40 Report.Report "UNSAFE PATTERN" region [] $
41− Report.toCodeSnippet source region Nothing
41+ Code.toSnippet source region Nothing
42 (
42 (
43 "This pattern does not cover all possiblities:"
43 "This pattern does not cover all possiblities:"
44 ,
44 ,
@@ -54,7 +54,7 @@ toReport source err =
54
54
55 P.BadDestruct ->
55 P.BadDestruct ->
56 Report.Report "UNSAFE PATTERN" region [] $
56 Report.Report "UNSAFE PATTERN" region [] $
57− Report.toCodeSnippet source region Nothing
57+ Code.toSnippet source region Nothing
58 (
58 (
59 "This pattern does not cover all possible values:"
59 "This pattern does not cover all possible values:"
60 ,
60 ,
@@ -74,7 +74,7 @@ toReport source err =
74
74
75 P.BadCase ->
75 P.BadCase ->
76 Report.Report "MISSING PATTERNS" region [] $
76 Report.Report "MISSING PATTERNS" region [] $
77− Report.toCodeSnippet source region Nothing
77+ Code.toSnippet source region Nothing
78 (
78 (
79 "This `case` does not have branches for all possibilities:"
79 "This `case` does not have branches for all possibilities:"
80 ,
80 ,
compiler/src/Reporting/Error/Type.hs+9−9
@@ -188,7 +188,7 @@ toPatternReport source localizer patternRegion category tipe expected =
188 Report.Report "TYPE MISMATCH" patternRegion [] $
188 Report.Report "TYPE MISMATCH" patternRegion [] $
189 case expected of
189 case expected of
190 PNoExpectation expectedType ->
190 PNoExpectation expectedType ->
191− Report.toCodeSnippet source patternRegion Nothing $
191+ Code.toSnippet source patternRegion Nothing $
192 ( "This pattern is being used in an unexpected way:"
192 ( "This pattern is being used in an unexpected way:"
193 , patternTypeComparison localizer tipe expectedType
193 , patternTypeComparison localizer tipe expectedType
194 (addPatternCategory "It is" category)
194 (addPatternCategory "It is" category)
@@ -197,7 +197,7 @@ toPatternReport source localizer patternRegion category tipe expected =
197 )
197 )
198
198
199 PFromContext region context expectedType ->
199 PFromContext region context expectedType ->
200− Report.toCodeSnippet source region (Just patternRegion) $
200+ Code.toSnippet source region (Just patternRegion) $
201 case context of
201 case context of
202 PTypedArg name index ->
202 PTypedArg name index ->
203 ( D.reflow $
203 ( D.reflow $
@@ -630,7 +630,7 @@ toExprReport source localizer exprRegion category tipe expected =
630 case expected of
630 case expected of
631 NoExpectation expectedType ->
631 NoExpectation expectedType ->
632 Report.Report "TYPE MISMATCH" exprRegion [] $
632 Report.Report "TYPE MISMATCH" exprRegion [] $
633− Report.toCodeSnippet source exprRegion Nothing
633+ Code.toSnippet source exprRegion Nothing
634 ( "This expression is being used in an unexpected way:"
634 ( "This expression is being used in an unexpected way:"
635 , typeComparison localizer tipe expectedType
635 , typeComparison localizer tipe expectedType
636 (addCategory "It is" category)
636 (addCategory "It is" category)
@@ -653,7 +653,7 @@ toExprReport source localizer exprRegion category tipe expected =
653 TypedBody -> "The body is"
653 TypedBody -> "The body is"
654 in
654 in
655 Report.Report "TYPE MISMATCH" exprRegion [] $
655 Report.Report "TYPE MISMATCH" exprRegion [] $
656− Report.toCodeSnippet source exprRegion Nothing $
656+ Code.toSnippet source exprRegion Nothing $
657 ( D.reflow ("Something is off with the " <> thing)
657 ( D.reflow ("Something is off with the " <> thing)
658 , typeComparison localizer tipe expectedType
658 , typeComparison localizer tipe expectedType
659 (addCategory itIs category)
659 (addCategory itIs category)
@@ -665,21 +665,21 @@ toExprReport source localizer exprRegion category tipe expected =
665 let
665 let
666 mismatch (maybeHighlight, problem, thisIs, insteadOf, furtherDetails) =
666 mismatch (maybeHighlight, problem, thisIs, insteadOf, furtherDetails) =
667 Report.Report "TYPE MISMATCH" exprRegion [] $
667 Report.Report "TYPE MISMATCH" exprRegion [] $
668− Report.toCodeSnippet source region maybeHighlight
668+ Code.toSnippet source region maybeHighlight
669 ( D.reflow problem
669 ( D.reflow problem
670 , typeComparison localizer tipe expectedType (addCategory thisIs category) insteadOf furtherDetails
670 , typeComparison localizer tipe expectedType (addCategory thisIs category) insteadOf furtherDetails
671 )
671 )
672
672
673 badType (maybeHighlight, problem, thisIs, furtherDetails) =
673 badType (maybeHighlight, problem, thisIs, furtherDetails) =
674 Report.Report "TYPE MISMATCH" exprRegion [] $
674 Report.Report "TYPE MISMATCH" exprRegion [] $
675− Report.toCodeSnippet source region maybeHighlight
675+ Code.toSnippet source region maybeHighlight
676 ( D.reflow problem
676 ( D.reflow problem
677 , loneType localizer tipe expectedType (D.reflow (addCategory thisIs category)) furtherDetails
677 , loneType localizer tipe expectedType (D.reflow (addCategory thisIs category)) furtherDetails
678 )
678 )
679
679
680 custom maybeHighlight docPair =
680 custom maybeHighlight docPair =
681 Report.Report "TYPE MISMATCH" exprRegion [] $
681 Report.Report "TYPE MISMATCH" exprRegion [] $
682− Report.toCodeSnippet source region maybeHighlight docPair
682+ Code.toSnippet source region maybeHighlight docPair
683 in
683 in
684 case context of
684 case context of
685 ListEntry index ->
685 ListEntry index ->
@@ -762,7 +762,7 @@ toExprReport source localizer exprRegion category tipe expected =
762
762
763 CallArity maybeFuncName numGivenArgs ->
763 CallArity maybeFuncName numGivenArgs ->
764 Report.Report "TOO MANY ARGS" exprRegion [] $
764 Report.Report "TOO MANY ARGS" exprRegion [] $
765− Report.toCodeSnippet source region (Just exprRegion) $
765+ Code.toSnippet source region (Just exprRegion) $
766 case countArgs tipe of
766 case countArgs tipe of
767 0 ->
767 0 ->
768 let
768 let
@@ -1574,7 +1574,7 @@ badEquality localizer op tipe expected =
1574toInfiniteReport :: Code.Source -> L.Localizer -> A.Region -> Name.Name -> T.Type -> Report.Report
1574toInfiniteReport :: Code.Source -> L.Localizer -> A.Region -> Name.Name -> T.Type -> Report.Report
1575toInfiniteReport source localizer region name overallType =
1575toInfiniteReport source localizer region name overallType =
1576 Report.Report "INFINITE TYPE" region [] $
1576 Report.Report "INFINITE TYPE" region [] $
1577− Report.toCodeSnippet source region Nothing
1577+ Code.toSnippet source region Nothing
1578 (
1578 (
1579 D.reflow $
1579 D.reflow $
1580 "I am inferring a weird self-referential type for " <> Name.toChars name <> ":"
1580 "I am inferring a weird self-referential type for " <> Name.toChars name <> ":"
compiler/src/Reporting/Render/Code.hs+40−4
@@ -3,9 +3,8 @@
3module Reporting.Render.Code
3module Reporting.Render.Code
4 ( Source
4 ( Source
5 , toSource
5 , toSource
6− , render
6+ , toSnippet
7− , CodePair(..)
7+ , toPair
8− , renderPair
9 )
8 )
10 where
9 where
11
10
@@ -35,7 +34,44 @@ toSource source =
35
34
36
35
37
36
37+-- CODE FORMATTING
38+
39+
40+toSnippet :: Source -> A.Region -> Maybe A.Region -> (D.Doc, D.Doc) -> D.Doc
41+toSnippet source region highlight (preHint, postHint) =
42+ D.vcat
43+ [ preHint
44+ , ""
45+ , render source region highlight
46+ , postHint
47+ ]
48+
49+
50+toPair :: Source -> A.Region -> A.Region -> (D.Doc, D.Doc) -> (D.Doc, D.Doc, D.Doc) -> D.Doc
51+toPair source r1 r2 (oneStart, oneEnd) (twoStart, twoMiddle, twoEnd) =
52+ case renderPair source r1 r2 of
53+ OneLine codeDocs ->
54+ D.vcat
55+ [ oneStart
56+ , ""
57+ , codeDocs
58+ , oneEnd
59+ ]
60+
61+ TwoChunks code1 code2 ->
62+ D.vcat
63+ [ twoStart
64+ , ""
65+ , code1
66+ , twoMiddle
67+ , ""
68+ , code2
69+ , twoEnd
70+ ]
71+
72+
73+
38−-- RENDER
74+-- RENDER SNIPPET
39
75
40
76
41(|>) :: a -> (a -> b) -> b
77(|>) :: a -> (a -> b) -> b
compiler/src/Reporting/Report.hs−40
@@ -1,15 +1,12 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Report
2module Reporting.Report
3 ( Report(..)
3 ( Report(..)
4− , toCodeSnippet
5− , toCodePair
6 )
4 )
7 where
5 where
8
6
9
7
10import qualified Reporting.Annotation as A
8import qualified Reporting.Annotation as A
11import qualified Reporting.Doc as D
9import qualified Reporting.Doc as D
12−import qualified Reporting.Render.Code as Code
13
10
14
11
15
12
@@ -23,40 +20,3 @@ data Report =
23 , _sgstns :: [String]
20 , _sgstns :: [String]
24 , _message :: D.Doc
21 , _message :: D.Doc
25 }
22 }
26−
27−
28−
29−-- CODE FORMATTING
30−
31−
32−toCodeSnippet :: Code.Source -> A.Region -> Maybe A.Region -> (D.Doc, D.Doc) -> D.Doc
33−toCodeSnippet source region highlight (preHint, postHint) =
34− D.vcat
35− [ preHint
36− , ""
37− , Code.render source region highlight
38− , postHint
39− ]
40−
41−
42−toCodePair :: Code.Source -> A.Region -> A.Region -> (D.Doc, D.Doc) -> (D.Doc, D.Doc, D.Doc) -> D.Doc
43−toCodePair source r1 r2 (oneStart, oneEnd) (twoStart, twoMiddle, twoEnd) =
44− case Code.renderPair source r1 r2 of
45− Code.OneLine codeDocs ->
46− D.vcat
47− [ oneStart
48− , ""
49− , codeDocs
50− , oneEnd
51− ]
52−
53− Code.TwoChunks code1 code2 ->
54− D.vcat
55− [ twoStart
56− , ""
57− , code1
58− , twoMiddle
59− , ""
60− , code2
61− , twoEnd
62− ]
compiler/src/Reporting/Warning.hs+3−3
@@ -43,7 +43,7 @@ toReport localizer source warning =
43 case warning of
43 case warning of
44 UnusedImport region moduleName ->
44 UnusedImport region moduleName ->
45 Report.Report "unused import" region [] $
45 Report.Report "unused import" region [] $
46− Report.toCodeSnippet source region Nothing
46+ Code.toSnippet source region Nothing
47 (
47 (
48 D.reflow $
48 D.reflow $
49 "Nothing from the `" <> Name.toChars moduleName <> "` module is used in this file."
49 "Nothing from the `" <> Name.toChars moduleName <> "` module is used in this file."
@@ -54,7 +54,7 @@ toReport localizer source warning =
54 UnusedVariable region context name ->
54 UnusedVariable region context name ->
55 let title = defOrPat context "unused definition" "unused variable" in
55 let title = defOrPat context "unused definition" "unused variable" in
56 Report.Report title region [] $
56 Report.Report title region [] $
57− Report.toCodeSnippet source region Nothing
57+ Code.toSnippet source region Nothing
58 (
58 (
59 D.reflow $
59 D.reflow $
60 "You are not using `" <> Name.toChars name <> "` anywhere."
60 "You are not using `" <> Name.toChars name <> "` anywhere."
@@ -76,7 +76,7 @@ toReport localizer source warning =
76
76
77 MissingTypeAnnotation region name inferredType ->
77 MissingTypeAnnotation region name inferredType ->
78 Report.Report "missing type annotation" region [] $
78 Report.Report "missing type annotation" region [] $
79− Report.toCodeSnippet source region Nothing
79+ Code.toSnippet source region Nothing
80 (
80 (
81 D.reflow $
81 D.reflow $
82 case Type.deepDealias inferredType of
82 case Type.deepDealias inferredType of