on master help sign in
Give a much more specific error for bad indentation in let
c39a65cEvan Czaplicki
src/Reporting/Error/Syntax.hs+28−7
@@ -793,14 +793,14 @@ badSpace stack =
793
793
794 (context, _) : rest ->
794 (context, _) : rest ->
795 case context of
795 case context of
796− ExprIf -> "the end of that `if`" <> badSpaceEnd
796+ ExprIf -> "the end of that `if`" <> badSpaceExprEnd rest
797− ExprLet -> "the end of that `let`" <> badSpaceEnd
797+ ExprLet -> "the end of that `let`" <> badSpaceExprEnd rest
798 ExprFunc -> badSpace rest
798 ExprFunc -> badSpace rest
799− ExprCase -> "more of that `case`" <> badSpaceEnd
799+ ExprCase -> "more of that `case`" <> badSpaceExprEnd rest
800− ExprList -> "the end of that list" <> badSpaceEnd
800+ ExprList -> "the end of that list" <> badSpaceExprEnd rest
801− ExprTuple -> "a closing paren" <> badSpaceEnd
801+ ExprTuple -> "a closing paren" <> badSpaceExprEnd rest
802− ExprRecord -> "the end of that record" <> badSpaceEnd
802+ ExprRecord -> "the end of that record" <> badSpaceExprEnd rest
803− Definition name -> "the rest of " <> name <> "'s definition" <> badSpaceEnd
803+ Definition name -> "the rest of " <> name <> "'s definition" <> badSpaceExprEnd stack
804 Annotation name -> "the rest of " <> name <> "'s type annotation" <> badSpaceEnd
804 Annotation name -> "the rest of " <> name <> "'s type annotation" <> badSpaceEnd
805 TypeTuple -> "a closing paren" <> badSpaceEnd
805 TypeTuple -> "a closing paren" <> badSpaceEnd
806 TypeRecord -> "the end of that record" <> badSpaceEnd
806 TypeRecord -> "the end of that record" <> badSpaceEnd
@@ -818,3 +818,24 @@ badSpace stack =
818badSpaceEnd :: Text
818badSpaceEnd :: Text
819badSpaceEnd =
819badSpaceEnd =
820 ". Maybe you forgot some code? Or you need more indentation?"
820 ". 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