Skip to content

Commit

Permalink
Type check if conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
healeycodes committed Dec 28, 2023
1 parent d33ca73 commit 2ead2ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit 2ead2ff

Please sign in to comment.