on master help sign in
Give a much more specific error for bad indentation in let

Improvement for https://github.com/elm-lang/error-message-catalog/issues/96

commitc39a65c8337728dfb0e0d4623f3400279dcd688f authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 15 Dec 2016, 19:07 (10 years ago) parent7dd0bbd
1 file changed+28−7
src/Reporting/Error/Syntax.hs+28−7
src/Reporting/Error/Syntax.hs+28−7
@@ -793,14 +793,14 @@ badSpace stack =
793793
794794 (context, _) : rest ->
795795 case context of
796− ExprIf -> "the end of that `if`" <> badSpaceEnd
797− ExprLet -> "the end of that `let`" <> badSpaceEnd
796+ ExprIf -> "the end of that `if`" <> badSpaceExprEnd rest
797+ ExprLet -> "the end of that `let`" <> badSpaceExprEnd rest
798798 ExprFunc -> badSpace rest
799− ExprCase -> "more of that `case`" <> badSpaceEnd
800− ExprList -> "the end of that list" <> badSpaceEnd
801− ExprTuple -> "a closing paren" <> badSpaceEnd
802− ExprRecord -> "the end of that record" <> badSpaceEnd
803− Definition name -> "the rest of " <> name <> "'s definition" <> badSpaceEnd
799+ ExprCase -> "more of that `case`" <> badSpaceExprEnd rest
800+ ExprList -> "the end of that list" <> badSpaceExprEnd rest
801+ ExprTuple -> "a closing paren" <> badSpaceExprEnd rest
802+ ExprRecord -> "the end of that record" <> badSpaceExprEnd rest
803+ Definition name -> "the rest of " <> name <> "'s definition" <> badSpaceExprEnd stack
804804 Annotation name -> "the rest of " <> name <> "'s type annotation" <> badSpaceEnd
805805 TypeTuple -> "a closing paren" <> badSpaceEnd
806806 TypeRecord -> "the end of that record" <> badSpaceEnd
@@ -818,3 +818,24 @@ badSpace stack =
818818badSpaceEnd :: Text
819819badSpaceEnd =
820820 ". Maybe you forgot some code? Or you need more indentation?"
821+
822+
823+badSpaceExprEnd :: ContextStack -> Text
824+badSpaceExprEnd stack =
825+ case stack of
826+ [] ->
827+ badSpaceEnd
828+
829+ (Definition name, R.Position _ column) : _ ->
830+ let
831+ ending =
832+ if column <= 1 then
833+ "to be indented?"
834+ else
835+ "more indentation? (Try " <> i2t (column + 1) <> "+ spaces.)"
836+ in
837+ ". Maybe you forgot some code? Or maybe the body of `" <> name
838+ <> "` needs " <> ending
839+
840+ _ : rest ->
841+ badSpaceExprEnd rest