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:
parent
b3a2221390
commit
9728ef0199
@ -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
|
||||
|
7
semantic-python/test/fixtures/2-03-return-in-if-statement.py
vendored
Normal file
7
semantic-python/test/fixtures/2-03-return-in-if-statement.py
vendored
Normal 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 ()
|
||||
()
|
Loading…
Reference in New Issue
Block a user