From 3866efd004b69e070a78511d10be6cfdb361ebb0 Mon Sep 17 00:00:00 2001 From: Jaskirat-s7 Date: Fri, 13 Mar 2026 23:27:43 +0530 Subject: [PATCH 01/10] test(#38): cover IfStmt float condition and VariableDeclaration zero-init paths - Add Float32 to test_if_else_stmt and test_if_only_stmt parametrize lists - Add test_variable_declaration_no_initializer for Int32 and Float32 - Fix: VariableDeclaration visitor checked 'node.value is not None' but astx defaults value to astx.Undefined(); added isinstance check so uninitialized vars reach the zero-init path (llvmliteir.py lines 3023-3059) --- src/irx/builders/llvmliteir.py | 4 ++- tests/test_if_stmt.py | 2 ++ tests/test_variable_assignment.py | 46 ++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/irx/builders/llvmliteir.py b/src/irx/builders/llvmliteir.py index 6fcfd602..9c20ee42 100644 --- a/src/irx/builders/llvmliteir.py +++ b/src/irx/builders/llvmliteir.py @@ -3552,7 +3552,9 @@ def visit(self, node: astx.VariableDeclaration) -> None: type_str = node.type_.__class__.__name__.lower() # Emit the initializer - if node.value is not None: + if node.value is not None and not isinstance( + node.value, astx.Undefined + ): self.visit(node.value) init_val = self.result_stack.pop() if init_val is None: diff --git a/tests/test_if_stmt.py b/tests/test_if_stmt.py index e344668f..9a0233c3 100644 --- a/tests/test_if_stmt.py +++ b/tests/test_if_stmt.py @@ -19,6 +19,7 @@ (astx.Int16, astx.LiteralInt16), (astx.Int8, astx.LiteralInt8), (astx.Int64, astx.LiteralInt64), + (astx.Float32, astx.LiteralFloat32), ], ) @pytest.mark.parametrize( @@ -94,6 +95,7 @@ def test_if_else_stmt( (astx.Int32, astx.LiteralInt32), (astx.Int16, astx.LiteralInt16), (astx.Int8, astx.LiteralInt8), + (astx.Float32, astx.LiteralFloat32), ], ) @pytest.mark.parametrize( diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index bf0b28b2..ad1be68e 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -23,7 +23,7 @@ @pytest.mark.parametrize( "builder_class", [ - # ("translate", "test_variable_assignment.ll"), + # (\"translate\", \"test_variable_assignment.ll\"), LLVMLiteIR, ], ) @@ -66,3 +66,47 @@ def test_variable_assignment( expected_output = "42" check_result("build", builder, module, expected_output=expected_output) + + +@pytest.mark.parametrize( + "var_type, literal_type", + [ + (astx.Int32, astx.LiteralInt32), + (astx.Float32, astx.LiteralFloat32), + ], +) +@pytest.mark.parametrize("builder_class", [LLVMLiteIR]) +def test_variable_declaration_no_initializer( + builder_class: Type[Builder], + var_type: type, + literal_type: type, +) -> None: + """ + title: Test VariableDeclaration without an initializer defaults to zero. + parameters: + builder_class: + type: Type[Builder] + var_type: + type: type + literal_type: + type: type + """ + builder = builder_class() + module = builder.module() + + decl = astx.VariableDeclaration( + name="x", + type_=var_type(), + ) + + proto = astx.FunctionPrototype( + name="main", args=astx.Arguments(), return_type=var_type() + ) + fn_block = astx.Block() + fn_block.append(decl) + fn_block.append(astx.FunctionReturn(astx.Identifier("x"))) + fn_main = astx.FunctionDef(prototype=proto, body=fn_block) + + module.block.append(fn_main) + + check_result("build", builder, module) From a809fd7d04fc7283229cb708cf749bd96be9d17f Mon Sep 17 00:00:00 2001 From: Jaskirat-s7 Date: Tue, 17 Mar 2026 18:30:17 +0530 Subject: [PATCH 02/10] fix: add missing Type import in test_variable_assignment.py --- tests/test_variable_assignment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index ad1be68e..f551a7ff 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -77,7 +77,7 @@ def test_variable_assignment( ) @pytest.mark.parametrize("builder_class", [LLVMLiteIR]) def test_variable_declaration_no_initializer( - builder_class: Type[Builder], + builder_class: type[Builder], var_type: type, literal_type: type, ) -> None: @@ -85,7 +85,7 @@ def test_variable_declaration_no_initializer( title: Test VariableDeclaration without an initializer defaults to zero. parameters: builder_class: - type: Type[Builder] + type: type[Builder] var_type: type: type literal_type: From 357c5b250ee40eae96633ad1683d10bcd897ff90 Mon Sep 17 00:00:00 2001 From: Jaskirat-s7 Date: Wed, 18 Mar 2026 15:27:42 +0530 Subject: [PATCH 03/10] test(#38): add Float64 to IfStmt parametrize list per review feedback --- tests/test_if_stmt.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_if_stmt.py b/tests/test_if_stmt.py index 9a0233c3..d96ca2ee 100644 --- a/tests/test_if_stmt.py +++ b/tests/test_if_stmt.py @@ -20,6 +20,7 @@ (astx.Int8, astx.LiteralInt8), (astx.Int64, astx.LiteralInt64), (astx.Float32, astx.LiteralFloat32), + (astx.Float64, astx.LiteralFloat64), ], ) @pytest.mark.parametrize( @@ -96,6 +97,7 @@ def test_if_else_stmt( (astx.Int16, astx.LiteralInt16), (astx.Int8, astx.LiteralInt8), (astx.Float32, astx.LiteralFloat32), + (astx.Float64, astx.LiteralFloat64), ], ) @pytest.mark.parametrize( From 0db9c57b00f5879d6220e72f1e949fc05247d31c Mon Sep 17 00:00:00 2001 From: Yuvi Mittal <128018763+yuvimittal@users.noreply.github.com> Date: Thu, 19 Mar 2026 13:54:32 +0530 Subject: [PATCH 04/10] Fix commented-out test case in variable assignment test --- tests/test_variable_assignment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index f551a7ff..aacbffdd 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -23,7 +23,7 @@ @pytest.mark.parametrize( "builder_class", [ - # (\"translate\", \"test_variable_assignment.ll\"), + # ("translate\", "test_variable_assignment.ll"), LLVMLiteIR, ], ) From bb3aa82bd69802a3a590bddb11d494a272e56c62 Mon Sep 17 00:00:00 2001 From: Yuvi Mittal <128018763+yuvimittal@users.noreply.github.com> Date: Thu, 19 Mar 2026 13:54:56 +0530 Subject: [PATCH 05/10] Fix comment formatting in test_variable_assignment.py --- tests/test_variable_assignment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index aacbffdd..ac3c0f20 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -23,7 +23,7 @@ @pytest.mark.parametrize( "builder_class", [ - # ("translate\", "test_variable_assignment.ll"), + # ("translate", "test_variable_assignment.ll"), LLVMLiteIR, ], ) From 718fcb08f818be18d0d16154b057d12de6d2db7b Mon Sep 17 00:00:00 2001 From: Jaskirat-s7 Date: Thu, 19 Mar 2026 14:10:31 +0530 Subject: [PATCH 06/10] test(#38): add Float32/Float64 to test_variable_assignment per review --- tests/test_variable_assignment.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index ac3c0f20..8afff916 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -7,64 +7,69 @@ from irx.builders.base import Builder from irx.builders.llvmliteir import LLVMLiteIR +from irx.system import PrintExpr from .conftest import check_result @pytest.mark.parametrize( - "int_type, literal_type", + "var_type, literal_type, expected_output", [ - (astx.Int32, astx.LiteralInt32), - (astx.Int16, astx.LiteralInt16), - (astx.Int8, astx.LiteralInt8), - (astx.Int64, astx.LiteralInt64), + (astx.Int32, astx.LiteralInt32, "42"), + (astx.Int16, astx.LiteralInt16, "42"), + (astx.Int8, astx.LiteralInt8, "42"), + (astx.Int64, astx.LiteralInt64, "42"), + (astx.Float32, astx.LiteralFloat32, "42.000000"), + (astx.Float64, astx.LiteralFloat64, "42.000000"), ], ) @pytest.mark.parametrize( "builder_class", [ - # ("translate", "test_variable_assignment.ll"), LLVMLiteIR, ], ) def test_variable_assignment( builder_class: type[Builder], - int_type: type, + var_type: type, literal_type: type, + expected_output: str, ) -> None: """ title: Test VariableAssignment by reassigning and returning. parameters: builder_class: type: type[Builder] - int_type: + var_type: type: type literal_type: type: type + expected_output: + type: str """ builder = builder_class() module = builder.module() decl = astx.InlineVariableDeclaration( name="x", - type_=int_type(), + type_=var_type(), value=literal_type(10), mutability=astx.MutabilityKind.mutable, ) assignment = astx.VariableAssignment(name="x", value=literal_type(42)) proto = astx.FunctionPrototype( - name="main", args=astx.Arguments(), return_type=int_type() + name="main", args=astx.Arguments(), return_type=astx.Int32() ) fn_block = astx.Block() fn_block.append(decl) fn_block.append(assignment) - fn_block.append(astx.FunctionReturn(astx.Identifier("x"))) + fn_block.append(PrintExpr(astx.Identifier("x"))) + fn_block.append(astx.FunctionReturn(astx.LiteralInt32(0))) fn_main = astx.FunctionDef(prototype=proto, body=fn_block) module.block.append(fn_main) - expected_output = "42" check_result("build", builder, module, expected_output=expected_output) From 259a892ad4f3e3c66ae7e0b3a33d69a3f9c17818 Mon Sep 17 00:00:00 2001 From: Jaskirat-s7 Date: Fri, 20 Mar 2026 01:40:38 +0530 Subject: [PATCH 07/10] test(#38): assert zero-default output in test_variable_declaration_no_initializer Add PrintExpr and expected_output assertion ('0' for Int32, '0.000000' for Float32/Float64) so the test proves default-to-zero behavior at runtime, not just that the build does not crash. Also add Float64 to the parametrize list. --- tests/test_variable_assignment.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index 8afff916..07797831 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -74,10 +74,11 @@ def test_variable_assignment( @pytest.mark.parametrize( - "var_type, literal_type", + "var_type, literal_type, expected_output", [ - (astx.Int32, astx.LiteralInt32), - (astx.Float32, astx.LiteralFloat32), + (astx.Int32, astx.LiteralInt32, "0"), + (astx.Float32, astx.LiteralFloat32, "0.000000"), + (astx.Float64, astx.LiteralFloat64, "0.000000"), ], ) @pytest.mark.parametrize("builder_class", [LLVMLiteIR]) @@ -85,6 +86,7 @@ def test_variable_declaration_no_initializer( builder_class: type[Builder], var_type: type, literal_type: type, + expected_output: str, ) -> None: """ title: Test VariableDeclaration without an initializer defaults to zero. @@ -95,6 +97,8 @@ def test_variable_declaration_no_initializer( type: type literal_type: type: type + expected_output: + type: str """ builder = builder_class() module = builder.module() @@ -105,13 +109,14 @@ def test_variable_declaration_no_initializer( ) proto = astx.FunctionPrototype( - name="main", args=astx.Arguments(), return_type=var_type() + name="main", args=astx.Arguments(), return_type=astx.Int32() ) fn_block = astx.Block() fn_block.append(decl) - fn_block.append(astx.FunctionReturn(astx.Identifier("x"))) + fn_block.append(PrintExpr(astx.Identifier("x"))) + fn_block.append(astx.FunctionReturn(astx.LiteralInt32(0))) fn_main = astx.FunctionDef(prototype=proto, body=fn_block) module.block.append(fn_main) - check_result("build", builder, module) + check_result("build", builder, module, expected_output=expected_output) From db6c4345961758a3760c89d05bb4eaa86ca44a82 Mon Sep 17 00:00:00 2001 From: Jaskirat-s7 Date: Fri, 20 Mar 2026 01:48:14 +0530 Subject: [PATCH 08/10] test(#38): expand test_variable_declaration_no_initializer per review - add PrintExpr + expected_output assertion ('0' for ints, '0.000000' for floats) to prove zero-default at runtime, not just build success - remove unused literal_type parameter from signature and parametrize - add Int8, Int16, Int64 alongside Int32/Float32/Float64 for consistency --- tests/test_variable_assignment.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index 07797831..079ded2d 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -74,18 +74,20 @@ def test_variable_assignment( @pytest.mark.parametrize( - "var_type, literal_type, expected_output", + "var_type, expected_output", [ - (astx.Int32, astx.LiteralInt32, "0"), - (astx.Float32, astx.LiteralFloat32, "0.000000"), - (astx.Float64, astx.LiteralFloat64, "0.000000"), + (astx.Int8, "0"), + (astx.Int16, "0"), + (astx.Int32, "0"), + (astx.Int64, "0"), + (astx.Float32, "0.000000"), + (astx.Float64, "0.000000"), ], ) @pytest.mark.parametrize("builder_class", [LLVMLiteIR]) def test_variable_declaration_no_initializer( builder_class: type[Builder], var_type: type, - literal_type: type, expected_output: str, ) -> None: """ @@ -95,8 +97,6 @@ def test_variable_declaration_no_initializer( type: type[Builder] var_type: type: type - literal_type: - type: type expected_output: type: str """ From 38fb0797fd5a3f3833779eb885a9306c90d38582 Mon Sep 17 00:00:00 2001 From: Jaskirat-s7 Date: Fri, 20 Mar 2026 01:59:22 +0530 Subject: [PATCH 09/10] ci: re-run jobs From 65e3dfa014b6df7e9082c607ee4c56aedb57af87 Mon Sep 17 00:00:00 2001 From: Ivan Ogasawara Date: Tue, 31 Mar 2026 20:01:24 +0000 Subject: [PATCH 10/10] fix small issues --- tests/test_if_stmt.py | 17 +++++++++++------ tests/test_variable_assignment.py | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/test_if_stmt.py b/tests/test_if_stmt.py index d96ca2ee..27f9bb30 100644 --- a/tests/test_if_stmt.py +++ b/tests/test_if_stmt.py @@ -77,17 +77,19 @@ def test_if_else_stmt( if_stmt = astx.IfStmt(condition=cond, then=then_block, else_=else_block) main_proto = astx.FunctionPrototype( - "main", args=astx.Arguments(), return_type=int_type() + "main", args=astx.Arguments(), return_type=astx.Int32() ) main_body = astx.Block() main_body.append(init_a) main_body.append(if_stmt) - main_body.append(astx.FunctionReturn(literal_type(0))) + main_body.append(astx.FunctionReturn(astx.LiteralInt32(0))) main_fn = astx.FunctionDef(prototype=main_proto, body=main_body) module.block.append(main_fn) - check_result(action, builder, module, expected_file) + check_result( + action, builder, module, expected_file, expected_output="then branch" + ) @pytest.mark.parametrize( @@ -150,17 +152,20 @@ def test_if_only_stmt( if_stmt = astx.IfStmt(condition=cond, then=then_block) main_proto = astx.FunctionPrototype( - "main", args=astx.Arguments(), return_type=int_type() + "main", args=astx.Arguments(), return_type=astx.Int32() ) main_body = astx.Block() main_body.append(init_a) main_body.append(if_stmt) - main_body.append(astx.FunctionReturn(literal_type(0))) + main_body.append(PrintExpr(astx.LiteralUTF8String("done"))) + main_body.append(astx.FunctionReturn(astx.LiteralInt32(0))) main_fn = astx.FunctionDef(prototype=main_proto, body=main_body) module.block.append(main_fn) - check_result(action, builder, module, expected_file) + check_result( + action, builder, module, expected_file, expected_output="done" + ) @pytest.mark.parametrize("builder_class", [LLVMLiteIR]) diff --git a/tests/test_variable_assignment.py b/tests/test_variable_assignment.py index 079ded2d..dd60726e 100644 --- a/tests/test_variable_assignment.py +++ b/tests/test_variable_assignment.py @@ -36,7 +36,7 @@ def test_variable_assignment( expected_output: str, ) -> None: """ - title: Test VariableAssignment by reassigning and returning. + title: Test VariableAssignment by reassigning and printing. parameters: builder_class: type: type[Builder]