diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-04-27 16:16:09 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-04-27 16:16:09 +0800 |
| commit | 1cccc82917066556eb8a825bbe7097aefd9541dd (patch) | |
| tree | 6645d3b80380f2f5e639b012ab422ac8e40e806c | |
| parent | 956cacc11b6b3b45ba5bc914b8332d8a7c23be05 (diff) | |
| download | yuescript-1cccc82917066556eb8a825bbe7097aefd9541dd.tar.gz yuescript-1cccc82917066556eb8a825bbe7097aefd9541dd.tar.bz2 yuescript-1cccc82917066556eb8a825bbe7097aefd9541dd.zip | |
fix some missed case.
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index ff554ac..1b5a17c 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -312,6 +312,14 @@ private: | |||
| 312 | 312 | ||
| 313 | bool isConst(const std::string& name) const { | 313 | bool isConst(const std::string& name) const { |
| 314 | bool isConst = false; | 314 | bool isConst = false; |
| 315 | decltype(_scopes.back().allows.get()) allows = nullptr; | ||
| 316 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { | ||
| 317 | if (it->allows) allows = it->allows.get(); | ||
| 318 | } | ||
| 319 | bool checkShadowScopeOnly = false; | ||
| 320 | if (allows) { | ||
| 321 | checkShadowScopeOnly = allows->find(name) == allows->end(); | ||
| 322 | } | ||
| 315 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { | 323 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { |
| 316 | auto vars = it->vars.get(); | 324 | auto vars = it->vars.get(); |
| 317 | auto vit = vars->find(name); | 325 | auto vit = vars->find(name); |
| @@ -319,6 +327,7 @@ private: | |||
| 319 | isConst = vit->second; | 327 | isConst = vit->second; |
| 320 | break; | 328 | break; |
| 321 | } | 329 | } |
| 330 | if (checkShadowScopeOnly && it->allows) break; | ||
| 322 | } | 331 | } |
| 323 | return isConst; | 332 | return isConst; |
| 324 | } | 333 | } |
| @@ -4144,7 +4153,8 @@ private: | |||
| 4144 | } | 4153 | } |
| 4145 | for (auto& var : varBefore) addToScope(var); | 4154 | for (auto& var : varBefore) addToScope(var); |
| 4146 | pushScope(); | 4155 | pushScope(); |
| 4147 | for (auto& var : varAfter) addToScope(var); | 4156 | for (const auto& var : vars) forceAddToScope(var); |
| 4157 | for (const auto& var : varAfter) addToScope(var); | ||
| 4148 | if (!destructPairs.empty()) { | 4158 | if (!destructPairs.empty()) { |
| 4149 | temp.clear(); | 4159 | temp.clear(); |
| 4150 | for (auto& pair : destructPairs) { | 4160 | for (auto& pair : destructPairs) { |
| @@ -4229,7 +4239,7 @@ private: | |||
| 4229 | const auto& step = *(++it); | 4239 | const auto& step = *(++it); |
| 4230 | _buf << indent() << "for "sv << varName << " = "sv << start << ", "sv << stop << (step.empty() ? Empty : s(", "sv) + step) << " do"sv << nll(forNode); | 4240 | _buf << indent() << "for "sv << varName << " = "sv << start << ", "sv << stop << (step.empty() ? Empty : s(", "sv) + step) << " do"sv << nll(forNode); |
| 4231 | pushScope(); | 4241 | pushScope(); |
| 4232 | addToScope(varName); | 4242 | forceAddToScope(varName); |
| 4233 | out.push_back(clearBuf()); | 4243 | out.push_back(clearBuf()); |
| 4234 | } | 4244 | } |
| 4235 | 4245 | ||
| @@ -5411,7 +5421,7 @@ private: | |||
| 5411 | _buf << indent() << "for "sv << varName << " = "sv << start << ", "sv << stop << (step.empty() ? Empty : s(", "sv) + step) << " do"sv << nll(comp); | 5421 | _buf << indent() << "for "sv << varName << " = "sv << start << ", "sv << stop << (step.empty() ? Empty : s(", "sv) + step) << " do"sv << nll(comp); |
| 5412 | out.push_back(clearBuf()); | 5422 | out.push_back(clearBuf()); |
| 5413 | pushScope(); | 5423 | pushScope(); |
| 5414 | addToScope(varName); | 5424 | forceAddToScope(varName); |
| 5415 | } | 5425 | } |
| 5416 | 5426 | ||
| 5417 | void transformTableBlockIndent(TableBlockIndent_t* table, str_list& out) { | 5427 | void transformTableBlockIndent(TableBlockIndent_t* table, str_list& out) { |
