diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index eb32e5f0040da45702a05a8db8b7475afe2431f9..53225c3e9e3507cd50304ddc171fa470bc25807b 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 487cbeaa2a01ad947d1c8296de9e156c70383058..f99d093336d11fd15a3d78f92d3cd9ec6634640f 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;