Skip to content

Commit

Permalink
fix testIfExpr test
Browse files Browse the repository at this point in the history
  • Loading branch information
maximiliankaul committed Sep 4, 2023
1 parent 803ade6 commit 43fd4da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,25 @@ class ExpressionHandler(frontend: PythonLanguageFrontend) :
is PythonAST.Attribute -> handleAttribute(node)
is PythonAST.BinOp -> handleBinOp(node)
is PythonAST.Compare -> handleCompare(node)
is PythonAST.Dict -> handleDict(node)
is PythonAST.IfExp -> handleIfExp(node)
else -> TODO()
}
}

private fun handleIfExp(node: PythonAST.IfExp): Expression {
return newConditionalExpression(
condition = handle(node.test),
thenExpr = handle(node.body),
elseExpr = handle(node.orelse),
rawNode = node
)
}

private fun handleDict(node: PythonAST.Dict): Expression {
TODO()
}

private fun handleCompare(node: PythonAST.Compare): Expression {
if (node.comparators.size != 1 || node.ops.size != 1) {
return newProblemExpression("Multi compare is not (yet) supported.", rawNode = node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ class PythonFrontendTest : BaseTest() {
val main = p.functions["foo"]
assertNotNull(main)

val body = (main.body as? CompoundStatement)?.statements?.get(0) as? DeclarationStatement
assertNotNull(body)
val assignExpr = (main.body as? CompoundStatement)?.statements?.first() as? AssignExpression
assertNotNull(assignExpr)

val foo = body.singleDeclaration as? VariableDeclaration
val foo = assignExpr.declarations.first() as? VariableDeclaration
assertNotNull(foo)
assertLocalName("foo", foo)
assertEquals(tu.primitiveType("int"), foo.type)

val initializer = foo.initializer as? ConditionalExpression
val initializer = foo.firstAssignment as? ConditionalExpression
assertNotNull(initializer)
assertEquals(tu.primitiveType("int"), initializer.type)

Expand Down

0 comments on commit 43fd4da

Please sign in to comment.