diff options
author | Li Jin <dragon-fly@qq.com> | 2022-02-15 09:55:18 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-02-15 09:55:18 +0800 |
commit | f4e2286da2b0212b0a7ac76821203bd398cfac5b (patch) | |
tree | 74e009d36b1cd67426ba729c8cb073f414f86cbf /src/yuescript/yue_compiler.cpp | |
parent | ddb0b9deb720368a425d00bce0c0352469b55911 (diff) | |
download | yuescript-f4e2286da2b0212b0a7ac76821203bd398cfac5b.tar.gz yuescript-f4e2286da2b0212b0a7ac76821203bd398cfac5b.tar.bz2 yuescript-f4e2286da2b0212b0a7ac76821203bd398cfac5b.zip |
fix a global variable check case.
Diffstat (limited to '')
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 6bc9fe8..6c8e167 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -60,7 +60,7 @@ using namespace parserlib; | |||
60 | 60 | ||
61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
62 | 62 | ||
63 | const std::string_view version = "0.9.10"sv; | 63 | const std::string_view version = "0.9.11"sv; |
64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
65 | 65 | ||
66 | class YueCompilerImpl { | 66 | class YueCompilerImpl { |
@@ -3539,7 +3539,19 @@ private: | |||
3539 | } | 3539 | } |
3540 | BLOCK_END | 3540 | BLOCK_END |
3541 | auto objVar = singleVariableFrom(partOne); | 3541 | auto objVar = singleVariableFrom(partOne); |
3542 | if (objVar.empty()) { | 3542 | bool isScoped = false; |
3543 | if (objVar.empty() || !isLocal(objVar)) { | ||
3544 | switch (usage) { | ||
3545 | case ExpUsage::Common: | ||
3546 | case ExpUsage::Assignment: | ||
3547 | isScoped = true; | ||
3548 | break; | ||
3549 | default: break; | ||
3550 | } | ||
3551 | if (isScoped) { | ||
3552 | temp.push_back(indent() + "do"s + nll(x)); | ||
3553 | pushScope(); | ||
3554 | } | ||
3543 | objVar = getUnusedName("_obj_"sv); | 3555 | objVar = getUnusedName("_obj_"sv); |
3544 | if (auto colonItem = ast_cast<ColonChainItem_t>(partOne->items.back())) { | 3556 | if (auto colonItem = ast_cast<ColonChainItem_t>(partOne->items.back())) { |
3545 | auto chainValue = x->new_ptr<ChainValue_t>(); | 3557 | auto chainValue = x->new_ptr<ChainValue_t>(); |
@@ -3549,7 +3561,7 @@ private: | |||
3549 | if (_withVars.empty()) { | 3561 | if (_withVars.empty()) { |
3550 | throw std::logic_error(_info.errorMessage("short dot/colon syntax must be called within a with block"sv, x)); | 3562 | throw std::logic_error(_info.errorMessage("short dot/colon syntax must be called within a with block"sv, x)); |
3551 | } | 3563 | } |
3552 | chainValue->items.push_back(toAst<Callable_t>(_withVars.top(), x)); | 3564 | chainValue->items.push_back(toAst<Callable_t>(_withVars.top(), x)); |
3553 | } | 3565 | } |
3554 | auto newObj = singleVariableFrom(chainValue); | 3566 | auto newObj = singleVariableFrom(chainValue); |
3555 | if (!newObj.empty()) { | 3567 | if (!newObj.empty()) { |
@@ -3650,6 +3662,10 @@ private: | |||
3650 | default: | 3662 | default: |
3651 | break; | 3663 | break; |
3652 | } | 3664 | } |
3665 | if (isScoped) { | ||
3666 | popScope(); | ||
3667 | temp.push_back(indent() + "end"s + nlr(x)); | ||
3668 | } | ||
3653 | out.push_back(join(temp)); | 3669 | out.push_back(join(temp)); |
3654 | return true; | 3670 | return true; |
3655 | } | 3671 | } |