on master help sign in
Improve error message for stray equals sign
60ac31bEvan Czaplicki
src/Reporting/Error/Syntax.hs+37−3
@@ -542,9 +542,7 @@ problemToReport subRegion problem =
542 "Maybe you want :: instead? Or maybe your indentation is a bit off?"
542 "Maybe you want :: instead? Or maybe your indentation is a bit off?"
543
543
544 Equals ->
544 Equals ->
545− badOp subRegion stack "an equals sign" "(=)"
545+ badEquals subRegion stack
546− "definitions"
547− "Maybe you want == instead? Or maybe your indentation is a bit off?"
548
546
549 Arrow ->
547 Arrow ->
550 if isCaseRelated stack then
548 if isCaseRelated stack then
@@ -631,6 +629,42 @@ badOp subRegion stack opName op setting hint =
631 ]
629 ]
632
630
633
631
632+badEquals :: Maybe R.Region -> ContextStack -> Report.Report
633+badEquals subRegion stack =
634+ let
635+ pre =
636+ "I was not expecting this equals sign"
637+ <> contextToText "" " while parsing " stack <> "."
638+ in
639+ makeParseReport subRegion pre (badEqualsHelp stack)
640+
641+
642+badEqualsHelp :: ContextStack -> Help.Doc
643+badEqualsHelp stack =
644+ case stack of
645+ [] ->
646+ reflowParagraph $
647+ "Maybe you want == instead? Or maybe your indentation is a bit off?"
648+
649+ (ExprRecord, _) : _ ->
650+ reflowParagraph $
651+ "Records look like { x = 3, y = 4 } with the equals sign right\
652+ \ after the field name. Maybe you forgot a comma?"
653+
654+ (Definition name, _) : rest ->
655+ reflowParagraph $
656+ "Maybe this is supposed to be a separate definition? If so, it\
657+ \ is indented too far. "
658+ <>
659+ if any ((==) ExprLet . fst) rest then
660+ "All definitions in a `let` expression must be vertically aligned."
661+ else
662+ "Spaces are not allowed before top-level definitions."
663+
664+ _ : rest ->
665+ badEqualsHelp rest
666+
667+
634contextToText :: Text -> Text -> ContextStack -> Text
668contextToText :: Text -> Text -> ContextStack -> Text
635contextToText defaultText prefixText stack =
669contextToText defaultText prefixText stack =
636 case stack of
670 case stack of