From 51c7ae5831f16ddbfff12aa91a9a193b8e14c209 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Tue, 25 Jul 2023 16:37:18 +0800 Subject: [PATCH] fixed e6ca9a1 from https://gitee.com/ctw-ian/ark_ts2abc/pulls/1134 Optimize error message of concurrent function Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I7NV35 Signed-off-by: ctw-ian Change-Id: I482d16a9c8f05dc101e767c7ece91d7499a5af83 --- .../using-const-lexical-variable-4-expected.txt | 2 +- .../using-mutable-lexical-variable-1-expected.txt | 2 +- .../using-mutable-lexical-variable-2-expected.txt | 2 +- .../using-mutable-lexical-variable-3-expected.txt | 2 +- .../using-mutable-lexical-variable-4-expected.txt | 2 +- .../using-mutable-lexical-variable-5-expected.txt | 2 +- es2panda/util/concurrent.cpp | 11 +++++++---- es2panda/util/concurrent.h | 2 +- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/es2panda/test/parser/concurrent/using-const-lexical-variable-4-expected.txt b/es2panda/test/parser/concurrent/using-const-lexical-variable-4-expected.txt index 6565cc7a65..296459a6ac 100644 --- a/es2panda/test/parser/concurrent/using-const-lexical-variable-4-expected.txt +++ b/es2panda/test/parser/concurrent/using-const-lexical-variable-4-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use import variable or local variable [using-const-lexical-variable-4.js:20:11] +Error: Concurrent function should only use import variable or local variable, 'a' is not one of them [using-const-lexical-variable-4.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-1-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt index df76adeac5..5ceb272d0e 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 import variable or local variable [using-mutable-lexical-variable-1.js:20:11] +Error: Concurrent function should only use import variable or local variable, 'a' is not one of them [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 741aa11197..31e320a2fe 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 import variable or local variable [using-mutable-lexical-variable-2.js:20:11] +Error: Concurrent function should only use import variable or local variable, 'a' is not one of them [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 015a6b4ab9..40d3e6e3a5 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 import variable or local variable [using-mutable-lexical-variable-3.js:20:11] +Error: Concurrent function should only use import variable or local variable, 'a' is not one of them [using-mutable-lexical-variable-3.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-4-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-4-expected.txt index 80b0902093..feac12bee6 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-4-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-4-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-4.js:21:15] +Error: Concurrent function should only use import variable or local variable, 'a' is not one of them [using-mutable-lexical-variable-4.js:21:15] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-5-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-5-expected.txt index c07b60b047..cf2d433fbd 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-5-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-5-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-5.js:20:11] +Error: Concurrent function should only use import variable or local variable, 'a' is not one of them [using-mutable-lexical-variable-5.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 058fecbeb1..2090f6af02 100644 --- a/es2panda/util/concurrent.cpp +++ b/es2panda/util/concurrent.cpp @@ -38,7 +38,7 @@ void Concurrent::SetConcurrent(ir::ScriptFunction *func, const ir::AstNode * nod } void Concurrent::ThrowInvalidConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, - ConcurrentInvalidFlag errFlag) + ConcurrentInvalidFlag errFlag, util::StringView varName) { auto line = expr->Range().start.line; auto column = (const_cast(lineIndex)).GetLocation(expr->Range().start).col - 1; @@ -49,8 +49,10 @@ void Concurrent::ThrowInvalidConcurrentFunction(const lexer::LineIndex &lineInde break; } case ConcurrentInvalidFlag::NOT_IMPORT_VARIABLE: { - throw Error {ErrorType::GENERIC, "Concurrent function should only use import variable or local variable", - line, column}; + std::stringstream ss; + ss << "Concurrent function should only use import variable or local variable, '" << varName + << "' is not one of them"; + throw Error {ErrorType::GENERIC, ss.str(), line, column}; break; } default: @@ -69,7 +71,8 @@ void Concurrent::VerifyImportVarForConcurrentFunction(const lexer::LineIndex &li return; } - ThrowInvalidConcurrentFunction(lineIndex, node, ConcurrentInvalidFlag::NOT_IMPORT_VARIABLE); + ThrowInvalidConcurrentFunction(lineIndex, node, ConcurrentInvalidFlag::NOT_IMPORT_VARIABLE, + result.variable->Declaration()->Name()); } } // namespace panda::es2panda::util \ No newline at end of file diff --git a/es2panda/util/concurrent.h b/es2panda/util/concurrent.h index 633d654617..ae718dcabb 100644 --- a/es2panda/util/concurrent.h +++ b/es2panda/util/concurrent.h @@ -49,7 +49,7 @@ public: static void SetConcurrent(ir::ScriptFunction *func, const ir::AstNode *node, const lexer::LineIndex &lineIndex); static void ThrowInvalidConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, - ConcurrentInvalidFlag errFlag); + ConcurrentInvalidFlag errFlag, util::StringView varName = ""); static void VerifyImportVarForConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *node, const binder::ScopeFindResult &result); }; -- Gitee