Skip to content

Commit

Permalink
fix an empty check case.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Feb 5, 2024
1 parent 018b940 commit 5ef5cff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
4 changes: 3 additions & 1 deletion spec/inputs/in_expression.yue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ do
2
x: 3
}

print a in []
a = 1
print a in {}
nil

6 changes: 6 additions & 0 deletions spec/outputs/in_expression.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,11 @@ do
b = not _find_0
end
end
print((function()
local _val_0 = a
return false
end)())
local a = 1
print((false))
end
return nil
26 changes: 17 additions & 9 deletions src/yuescript/yue_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = {
"close"s // Lua 5.4
};

const std::string_view version = "0.21.7"sv;
const std::string_view version = "0.21.8"sv;
const std::string_view extension = "yue"sv;

class CompileError : public std::logic_error {
Expand Down Expand Up @@ -6162,10 +6162,14 @@ class YueCompilerImpl {
if (unary_exp->inExp->not_) {
_buf << "not ("sv;
}
for (const auto& exp : tmp) {
_buf << exp << " == "sv << newVar;
if (exp != tmp.back()) {
_buf << " or "sv;
if (tmp.empty()) {
_buf << "false"sv;
} else {
for (const auto& exp : tmp) {
_buf << exp << " == "sv << newVar;
if (exp != tmp.back()) {
_buf << " or "sv;
}
}
}
if (unary_exp->inExp->not_) {
Expand Down Expand Up @@ -6203,10 +6207,14 @@ class YueCompilerImpl {
_buf << "not "sv;
}
_buf << '(';
for (const auto& exp : tmp) {
_buf << exp << " == "sv << varName;
if (exp != tmp.back()) {
_buf << " or "sv;
if (tmp.empty()) {
_buf << "false"sv;
} else {
for (const auto& exp : tmp) {
_buf << exp << " == "sv << varName;
if (exp != tmp.back()) {
_buf << " or "sv;
}
}
}
_buf << ')';
Expand Down

0 comments on commit 5ef5cff

Please sign in to comment.