1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Check that returns work within if-clauses.

This commit is contained in:
Patrick Thomson 2019-09-11 12:21:24 -04:00
parent b3a2221390
commit 9728ef0199
2 changed files with 16 additions and 1 deletions

View File

@ -68,7 +68,9 @@ instance Compile Py.Call
instance Compile Py.ClassDefinition
instance Compile Py.ComparisonOperator
instance Compile Py.CompoundStatement where compile = compileSum
instance Compile Py.CompoundStatement where
compile = compileSum
compileCC = compileCCSum
instance Compile Py.ConcatenatedString
instance Compile Py.ConditionalExpression
@ -128,6 +130,12 @@ instance Compile Py.IfStatement where
clause (Left Py.ElifClause{ condition, consequence }) rest =
if' <$> compile condition <*> compile consequence <*> rest
compileCC Py.IfStatement{ condition, consequence, alternative} cc =
if' <$> compile condition <*> compileCC consequence cc <*> foldr clause cc alternative
where clause (Right Py.ElseClause{ body }) _ = compileCC body cc
clause (Left Py.ElifClause{ condition, consequence }) rest =
if' <$> compile condition <*> compileCC consequence cc <*> rest
instance Compile Py.ImportFromStatement
instance Compile Py.ImportStatement

View File

@ -0,0 +1,7 @@
# CHECK-JQ: .tree.contents[0][1].contents[1] | .tag == "Lam" and .contents.value.tag == "If"
# CHECK-JQ: .tree.contents[0][1].contents[1].contents.value | .contents == [[], [], { "tag": "Unit" }]
def foo(a):
if a: return a
return ()
()