From 2ead2ff1e6949d19b5515e3e9b4fbb62112d489e Mon Sep 17 00:00:00 2001 From: Andrew Healey Date: Thu, 28 Dec 2023 23:08:27 +0000 Subject: [PATCH] Type check if conditional --- compiler.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler.py b/compiler.py index dd527ff..bdb9ab4 100644 --- a/compiler.py +++ b/compiler.py @@ -358,7 +358,12 @@ def visit_return_stmt(node: Tree, context: Context): def visit_if_stmt(node: Tree, context: Context): - visit_expression(node.children[2], context) + line, col = node.meta.line, node.meta.column + ntype = visit_expression(node.children[2], context) + if type(ntype) != I32: + raise Exception( + f"type error if: expected {I32()} got {ntype} ({line}:{col})" + ) context.write( """(if (then\n"""