From 3bb117e4fee72c4d4019c575bf0cb21043584954 Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Fri, 18 Apr 2025 19:46:22 +0000
Subject: [PATCH] fix if statement

---
 src/Parser/Parser.cpp  |    4 +++-
 test_scripts/object.vs |    9 ++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp
index a2fd154..b2bebf5 100644
--- a/src/Parser/Parser.cpp
+++ b/src/Parser/Parser.cpp
@@ -83,7 +83,9 @@
     // 'if'
     auto ifToken = expect(Lexer::Tokens::Type::KEYWORD, "if");
     expect(Lexer::Tokens::Type::PUNCTUATION, "(");
-    auto condExpr = parseParsedExpression(Symbols::Variables::Type::BOOLEAN);
+    // Parse the condition expression without restricting literal types,
+    // dynamic evaluation will enforce boolean type at runtime
+    auto condExpr = parseParsedExpression(Symbols::Variables::Type::NULL_TYPE);
     expect(Lexer::Tokens::Type::PUNCTUATION, ")");
     expect(Lexer::Tokens::Type::PUNCTUATION, "{");
     // then branch
diff --git a/test_scripts/object.vs b/test_scripts/object.vs
index 976c926..cd88c71 100644
--- a/test_scripts/object.vs
+++ b/test_scripts/object.vs
@@ -26,4 +26,11 @@
 
 printnl("Child1 old age: ",$person2->children->age);
 $person2->children->age = $person2->children->age + 2;
-printnl("Child1 new age: ",$person2->children->age);
\ No newline at end of file
+printnl("Child1 new age: ",$person2->children->age);
+
+int $age = 10;
+if ($person2->children->age > 18) {
+    printnl("Child1 is old enough to go to school.");
+} else {
+    printnl("Child1 is too young to go to school.");
+}
\ No newline at end of file

--
Gitblit v1.9.3