diff --git a/src/T/Error.hs b/src/T/Error.hs index c606cef..3a887e0 100644 --- a/src/T/Error.hs +++ b/src/T/Error.hs @@ -58,6 +58,7 @@ prettyError = \case excerpt ann TypeError (ann :< _) expected actual value -> header ann <> + "mismatched types:" <> PP.line <> PP.indent 2 "expected: " <> PP.pretty (show expected) <> PP.line <> PP.indent 2 " but got: " <> PP.pretty value <> " : " <> PP.pretty (show actual) <> PP.line <> excerpt ann diff --git a/src/T/Parse.hs b/src/T/Parse.hs index 6b1d40a..88a1d06 100644 --- a/src/T/Parse.hs +++ b/src/T/Parse.hs @@ -236,17 +236,11 @@ accessOp = Postfix (chainl1 (idxP <|> dotP) (pure (flip (.)))) where idxP = do - ann :+ expIdx <- anned $ do - _ <- symbol "[" - expIdx <- expP - _ <- symbol "]" - pure expIdx + ann :+ expIdx <- anned (between (symbol "[") (symbol "]") expP) pure (\exp -> ann :< Idx exp expIdx) dotP = do - ann :+ key <- anned $ do - _ <- symbol "." - nameP - pure (\exp -> ann :< Key exp key) + ann0 :+ (ann1 :+ key) <- anned (symbol "." *> nameP_) <* spaces + pure (\exp -> ann0 :< Key exp (ann1 :+ key)) infixOp :: DeltaParsing m => String -> Operator m Exp infixOp name = @@ -365,7 +359,11 @@ varP = nameP :: DeltaParsing m => m (Ann :+ Name) nameP = - anned (map fromString (liftA2 (:) firstL (many restL))) <* spaces + nameP_ <* spaces + +nameP_ :: DeltaParsing m => m (Ann :+ Name) +nameP_ = + anned (map fromString (liftA2 (:) firstL (many restL))) where firstL = letter <|> char '_' diff --git a/test/T/Parse/AnnSpec.hs b/test/T/Parse/AnnSpec.hs index 28eda34..e1c9789 100644 --- a/test/T/Parse/AnnSpec.hs +++ b/test/T/Parse/AnnSpec.hs @@ -8,7 +8,7 @@ import T.Prelude spec :: Spec spec = - describe "annotations" $ + describe "annotations" $ do context "literals" $ do it "null" $ errorOf "{{ null + 1 }}" `shouldBe` @@ -74,6 +74,15 @@ spec = \1 | {{ {foo:4} + 1 }} \n\ \ | ~~~~~~~ " + context "property access" $ do + it "record" $ do + errorOf "{% set foo = {} foo.bar = [] %}{{ foo.bar }}" `shouldBe` + "(interactive):1:38: error: mismatched types:\n\ + \ expected: Renderable\n\ + \ but got: [] : Array\n\ + \1 | {% set foo = {} foo.bar = [] %}{{ foo.bar }} \n\ + \ | ~~~~ " + errorOf :: Text -> String errorOf str = let