diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 06e2f1ff8c980ec8ad89f9744bab020283860cab..474a24b0e0586935f133e39ac2110b31fbdf4b2b 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -217,7 +217,7 @@ void Binder::LookupIdentReference(ir::Identifier *ident) if (res.level != 0) { ASSERT(res.variable); - util::Concurrent::CheckUsingMutableLexicalVar(Program()->GetLineIndex(), ident, res); + util::Concurrent::VerifyConstLexicalVarForConcurrentFunction(Program()->GetLineIndex(), ident, res); res.variable->SetLexical(res.scope, program_->HotfixHelper()); } diff --git a/es2panda/binder/scope.cpp b/es2panda/binder/scope.cpp index b6a4162fdd70a102bdf0380245cb62fb61df0e36..9ee64ef6881aa9d746df67bc160af07d4eb630cd 100644 --- a/es2panda/binder/scope.cpp +++ b/es2panda/binder/scope.cpp @@ -21,12 +21,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index 44274f48bf1e7b6844f84dc7c587699d79ede946..a149872d70bcde1a0ec8c00c785813c5c166d477 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -27,8 +27,8 @@ #include #include #include -#include #include +#include namespace panda::es2panda::compiler { diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 9ab19aecbf33908a35725294a9e49401d621d00a..26faa98df35c681ffe3999e36bb5074e2667d666 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -51,17 +51,17 @@ namespace panda::es2panda::compiler { void PandaGen::SetFunctionKind() { - // make sure concurrent info will not be overwritten - if (funcKind_ == panda::panda_file::FunctionKind::CONCURRENT_FUNCTION) { - return; - } - if (rootNode_->IsProgram()) { funcKind_ = panda::panda_file::FunctionKind::FUNCTION; return; } auto *func = rootNode_->AsScriptFunction(); + if (func->IsConcurrent()) { + funcKind_ = panda::panda_file::FunctionKind::CONCURRENT_FUNCTION; + return; + } + if (func->IsMethod()) { return; } @@ -1814,7 +1814,7 @@ void PandaGen::StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t void PandaGen::StoreLexicalEnv(const ir::AstNode *node) { - ra_.Emit(node); // modify later + ra_.Emit(node); } void PandaGen::ThrowIfSuperNotCorrectCall(const ir::AstNode *node, int64_t num) diff --git a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt index 9f8e5184316be625632b45e7c647a6c3636823a2..df76adeac5bd985beaa5641d2b61415861a49d4a 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use const lexical variable [using-mutable-lexical-variable-1.js:20:11] +Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-1.js:20:11] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt index 3b3081439e0af22aefd873b17f7dc2515ea19c48..741aa1119718aeef6486ffc9f783792dfede5924 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use const lexical variable [using-mutable-lexical-variable-2.js:20:11] +Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-2.js:20:11] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt index f3b03414065793eeeca4969c4e1be51086f05c5d..015a6b4ab98ce0dfe2a05286e11e8779527cd03d 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use const lexical variable [using-mutable-lexical-variable-3.js:20:11] +Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-3.js:20:11] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/util/concurrent.cpp b/es2panda/util/concurrent.cpp index 34e9d2d19fe4f468688e3566bc9901327811455e..2eb77e9f3c4f88f468f56e0f513f7faba839a45e 100644 --- a/es2panda/util/concurrent.cpp +++ b/es2panda/util/concurrent.cpp @@ -18,9 +18,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -69,12 +69,12 @@ void Concurrent::SetConcurrent(ir::ScriptFunction *func, const lexer::LineIndex // concurrent function should only be function declaration if (!func->CanBeConcurrent()) { - ThrowIncorrectUsing(lineIndex, stmt, ConcurrentInvalidFlag::NOT_ORDINARY_FUNCTION); + ThrowInvalidConcurrentFunction(lineIndex, stmt, ConcurrentInvalidFlag::NOT_ORDINARY_FUNCTION); } // concurrent function should be defined in top-level scope if (!func->Parent()->Parent()->IsProgram()) { - ThrowIncorrectUsing(lineIndex, stmt, ConcurrentInvalidFlag::NOT_TOP_LEVEL); + ThrowInvalidConcurrentFunction(lineIndex, stmt, ConcurrentInvalidFlag::NOT_TOP_LEVEL); } func->AddFlag(ir::ScriptFunctionFlags::CONCURRENT); @@ -89,7 +89,7 @@ void Concurrent::SetConcurrent(ir::ScriptFunction *func, const lexer::LineIndex } } -void Concurrent::ThrowIncorrectUsing(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, +void Concurrent::ThrowInvalidConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, ConcurrentInvalidFlag errFlag) { auto line = expr->Range().start.line; @@ -106,8 +106,8 @@ void Concurrent::ThrowIncorrectUsing(const lexer::LineIndex &lineIndex, const ir break; } case ConcurrentInvalidFlag::USING_MUTABLE_VARIABLE: { - throw Error {ErrorType::GENERIC, "Concurrent function should only use const lexical variable", line, - column}; + throw Error {ErrorType::GENERIC, "Concurrent function should only use import variable or local variable", + line, column}; break; } default: @@ -127,7 +127,7 @@ void Concurrent::StoreEnvForConcurrent(compiler::PandaGen *pg, const ir::AstNode } } -void Concurrent::CheckUsingMutableLexicalVar(const lexer::LineIndex &lineIndex, const ir::AstNode *node, +void Concurrent::VerifyConstLexicalVarForConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *node, const binder::ScopeFindResult &result) { if (!result.crossConcurrent) { @@ -135,7 +135,7 @@ void Concurrent::CheckUsingMutableLexicalVar(const lexer::LineIndex &lineIndex, } if (!result.variable->Declaration()->IsConstDecl()) { - ThrowIncorrectUsing(lineIndex, node, ConcurrentInvalidFlag::USING_MUTABLE_VARIABLE); + ThrowInvalidConcurrentFunction(lineIndex, node, ConcurrentInvalidFlag::USING_MUTABLE_VARIABLE); } } diff --git a/es2panda/util/concurrent.h b/es2panda/util/concurrent.h index 18c84e219f1b6f46cbca9ff75f65f207f7806a39..d7f4c70147729d9a7793a00b6860239966f6c0c2 100644 --- a/es2panda/util/concurrent.h +++ b/es2panda/util/concurrent.h @@ -49,10 +49,10 @@ public: Concurrent() = delete; static void SetConcurrent(ir::ScriptFunction *func, const lexer::LineIndex &lineIndex); - static void ThrowIncorrectUsing(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, + static void ThrowInvalidConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, ConcurrentInvalidFlag errFlag); static void StoreEnvForConcurrent(compiler::PandaGen *pg, const ir::AstNode *node); - static void CheckUsingMutableLexicalVar(const lexer::LineIndex &lineIndex, const ir::AstNode *node, + static void VerifyConstLexicalVarForConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *node, const binder::ScopeFindResult &result); static constexpr std::string_view USE_CONCURRENT = "use concurrent";