1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 08:54:14 +03:00

Fix Compile instance for ExpressionStatement and Assignment.

This commit is contained in:
Patrick Thomson 2019-09-23 12:31:25 -04:00
parent dccc1942aa
commit 54b5d379ea
2 changed files with 17 additions and 8 deletions

View File

@ -109,11 +109,18 @@ instance Compile (Py.AssertStatement Span)
instance Compile (Py.Attribute Span)
instance Compile (Py.Assignment Span) where
compile it@Py.Assignment { Py.left = Py.ExpressionList { Py.extraChildren = [lhs] }, Py.right = Just rhs } = do
target <- compile lhs
compileCC it@Py.Assignment
{ Py.left = Py.ExpressionList
{ Py.extraChildren =
[ Py.PrimaryExpressionExpression (Py.IdentifierPrimaryExpression (Py.Identifier { Py.bytes = name }))
]
}
, Py.right = Just rhs
} cc = do
value <- compile rhs
locate it $ target .= value
compile other = fail ("Unhandled assignment case: " <> show other)
locate it =<< ((Name.named' name :<- value) >>>=) <$> local (def name) cc
compileCC other _ = fail ("Unhandled assignment case: " <> show other)
compile t = compileCC t (pure none)
instance Compile (Py.AugmentedAssignment Span)
instance Compile (Py.Await Span)
@ -145,9 +152,11 @@ instance Compile (Py.ExecStatement Span)
deriving via CompileSum (Py.Expression Span) instance Compile (Py.Expression Span)
instance Compile (Py.ExpressionStatement Span) where
compile it@Py.ExpressionStatement { Py.extraChildren = children } = do
actions <- traverse compile children
locate it $ do' (fmap (Nothing :<-) actions)
compileCC it@Py.ExpressionStatement
{ Py.extraChildren = children
} cc = do
foldr compileCC cc children >>= locate it
compile stmt = compileCC stmt (pure none)
instance Compile (Py.ExpressionList Span) where
compile it@Py.ExpressionList { Py.extraChildren = exprs } = do

View File

@ -98,7 +98,7 @@ fixtureTestTreeForFile fp = HUnit.testCaseSteps (Path.toString fp) $ \step -> wi
(Right (Left err), _) -> HUnit.assertFailure ("Compilation failed: " <> err)
(Right (Right _), Directive.Fails) -> HUnit.assertFailure ("Expected translation to fail")
(Right (Right item), Directive.JQ _) -> assertJQExpressionSucceeds directive result item
(Right (Right item), Directive.Tree t) -> let msg = "lhs = " <> showCore t <> "\n rhs " <> showCore item'
(Right (Right item), Directive.Tree t) -> let msg = "expected (pretty): " <> showCore item'
item' = stripAnnotations item
in HUnit.assertEqual msg t item' where