From d383eafb40974331969d3a0eb00bfadddcb5d135 Mon Sep 17 00:00:00 2001 From: recepsadullahyegin Date: Thu, 11 Sep 2025 19:56:12 +0300 Subject: [PATCH] Verify failed using undefined expr Issue: #ICXM1V Description: Fix verifier error Signed-off-by: recepsadullahyegin --- .../ets/constantExpressionLowering.cpp | 19 +++++++++++++++++++ .../lowering/ets/constantExpressionLowering.h | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index eb32e5f004..53225c3e9e 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -21,6 +21,7 @@ #include "checker/ETSchecker.h" #include "checker/types/typeError.h" #include "compiler/lowering/util.h" +#include "generated/tokenType.h" #include "ir/expressions/literals/undefinedLiteral.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "util/helpers.h" @@ -148,6 +149,11 @@ static bool TestLiteral(const ir::Literal *lit) if (lit->IsNumberLiteral()) { return !lit->AsNumberLiteral()->Number().IsZero(); } + + if (lit->IsUndefinedLiteral()) { + return false; + } + ES2PANDA_UNREACHABLE(); } @@ -710,6 +716,15 @@ private: } } + if(left->IsUndefinedLiteral() && right->IsUndefinedLiteral()) { + bool res = (opType == lexer::TokenType::PUNCTUATOR_EQUAL || opType == lexer::TokenType::PUNCTUATOR_STRICT_EQUAL); + return CreateBooleanLiteral(res); + } + + if (left->IsUndefinedLiteral() || right->IsUndefinedLiteral()) { + return PerformRelationOperation(left, right, opType); + } + LogError(diagnostic::WRONG_OPERAND_TYPE_FOR_BINARY_EXPRESSION, {}, expr->Start()); return nullptr; } @@ -802,6 +817,10 @@ private: ir::Literal *HandleLogicalExpression(const ir::BinaryExpression *expr, const ir::Literal *left, const ir::Literal *right) { + if (left->IsUndefinedLiteral() || right->IsUndefinedLiteral()) { + return nullptr; + } + bool lhs = TestLiteral(left); bool rhs = TestLiteral(right); diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.h b/ets2panda/compiler/lowering/ets/constantExpressionLowering.h index 487cbeaa2a..f99d093336 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.h +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.h @@ -37,7 +37,7 @@ inline ir::Literal *AsSupportedLiteral(ir::Expression *const node) auto literal = node->AsLiteral(); if (IsValidNumberLiteral(literal) || literal->IsCharLiteral() || literal->IsBooleanLiteral() || - literal->IsStringLiteral()) { + literal->IsStringLiteral() || literal->IsUndefinedLiteral()) { return literal; } return nullptr; -- Gitee