summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-05 22:58:52 +0800
committerruki <[email protected]>2024-01-05 22:58:52 +0800
commit0ddd12e31ccf61b4238f77e167850cb9b14ae9c2 (patch)
treed6f186faf939e0d20f2149ebb72e847961d7e740
parent70079330098ef44836a13ff9d26609a3bcd2de48 (diff)
check invalid scope name #4547
-rw-r--r--xmake/core/base/interpreter.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index dfefe3438..e1cd08a78 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -956,7 +956,20 @@ end
function interpreter:api_register_scope(...)
-- define implementation
- local implementation = function (self, scopes, scope_kind, scope_name, scope_info)
+ local implementation = function (self, scopes, scope_kind, ...)
+ local scope_args = table.pack(...)
+ local scope_name = scope_args[1]
+ local scope_info = scope_args[2]
+
+ -- check invalid scope name, @see https://github.com/xmake-io/xmake/issues/4547
+ if scope_args.n > 0 and type(scope_name) ~= "string" then
+ local errors = string.format("%s(%s): invalid %s name", scope_kind, scope_name, scope_kind)
+ local sourceinfo = debug.getinfo(2, "Sl")
+ if sourceinfo then
+ errors = string.format("%s:%s: %s", sourceinfo.short_src or sourceinfo.source, sourceinfo.currentline, errors)
+ end
+ interpreter._raise(errors)
+ end
-- init scope for kind
local scope_for_kind = scopes[scope_kind] or {}