summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-15 18:58:08 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-15 18:58:08 +0800
commit8a01e9c4ec201ad7079f6863c9236851d162b864 (patch)
treef60fa49ebe192bfee5e94db6740a062c13af343a
parentd812fcd0853f52afa61ce8c1c028c94d0794ebe6 (diff)
downloadyuescript-0.31.1.tar.gz
yuescript-0.31.1.tar.bz2
yuescript-0.31.1.zip
Fixed a crash issue.HEADv0.31.1main
Diffstat (limited to '')
-rw-r--r--spec/inputs/import_global.yue7
-rw-r--r--spec/outputs/5.1/import_global.lua13
-rw-r--r--spec/outputs/import_global.lua13
-rw-r--r--src/yuescript/yue_compiler.cpp8
4 files changed, 35 insertions, 6 deletions
diff --git a/spec/inputs/import_global.yue b/spec/inputs/import_global.yue
index 30a274e..18f0e85 100644
--- a/spec/inputs/import_global.yue
+++ b/spec/inputs/import_global.yue
@@ -84,3 +84,10 @@ do
84 \func 1, 2, 3 84 \func 1, 2, 3
85 .tag = "abc" 85 .tag = "abc"
86 86
87do
88 import global
89
90 f = ->
91 func!
92 try func
93
diff --git a/spec/outputs/5.1/import_global.lua b/spec/outputs/5.1/import_global.lua
index c748c78..3b8334a 100644
--- a/spec/outputs/5.1/import_global.lua
+++ b/spec/outputs/5.1/import_global.lua
@@ -116,5 +116,16 @@ do
116 local X = X 116 local X = X
117 X:func(1, 2, 3) 117 X:func(1, 2, 3)
118 X.tag = "abc" 118 X.tag = "abc"
119 return X 119end
120local _anon_func_0 = function(func)
121 return func
122end
123do
124 local func = func
125 local pcall = pcall
126 local f
127 f = function()
128 func()
129 return pcall(_anon_func_0, func)
130 end
120end 131end
diff --git a/spec/outputs/import_global.lua b/spec/outputs/import_global.lua
index f76b4fe..895daf9 100644
--- a/spec/outputs/import_global.lua
+++ b/spec/outputs/import_global.lua
@@ -116,5 +116,16 @@ do
116 local X <const> = X 116 local X <const> = X
117 X:func(1, 2, 3) 117 X:func(1, 2, 3)
118 X.tag = "abc" 118 X.tag = "abc"
119 return X 119end
120local _anon_func_0 = function(func)
121 return func
122end
123do
124 local func <const> = func
125 local pcall <const> = pcall
126 local f
127 f = function()
128 func()
129 return pcall(_anon_func_0, func)
130 end
120end 131end
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 09d0bd1..a2d49af 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -78,7 +78,7 @@ static std::unordered_set<std::string> Metamethods = {
78 "close"s // Lua 5.4 78 "close"s // Lua 5.4
79}; 79};
80 80
81const std::string_view version = "0.31.0"sv; 81const std::string_view version = "0.31.1"sv;
82const std::string_view extension = "yue"sv; 82const std::string_view extension = "yue"sv;
83 83
84class CompileError : public std::logic_error { 84class CompileError : public std::logic_error {
@@ -437,7 +437,7 @@ private:
437 struct Scope; 437 struct Scope;
438 struct ImportedGlobal { 438 struct ImportedGlobal {
439 std::string* globalCodeLine = nullptr; 439 std::string* globalCodeLine = nullptr;
440 Scope* importingScope = nullptr; 440 std::unordered_map<std::string, VarType>* vars = nullptr;
441 std::string indent; 441 std::string indent;
442 std::string nl; 442 std::string nl;
443 std::unordered_set<std::string_view> globals; 443 std::unordered_set<std::string_view> globals;
@@ -1625,7 +1625,7 @@ private:
1625 if (_importedGlobal->globals.find(name) == _importedGlobal->globals.end() && !isSolidDefined(name)) { 1625 if (_importedGlobal->globals.find(name) == _importedGlobal->globals.end() && !isSolidDefined(name)) {
1626 const auto& global = _importedGlobal->globalList.emplace_back(name); 1626 const auto& global = _importedGlobal->globalList.emplace_back(name);
1627 _importedGlobal->globals.insert(global); 1627 _importedGlobal->globals.insert(global);
1628 _importedGlobal->importingScope->vars->insert_or_assign(name, VarType::LocalConst); 1628 _importedGlobal->vars->insert_or_assign(name, VarType::LocalConst);
1629 } 1629 }
1630 } 1630 }
1631 1631
@@ -5333,7 +5333,7 @@ private:
5333 auto& scope = currentScope(); 5333 auto& scope = currentScope();
5334 scope.importedGlobal = std::make_unique<ImportedGlobal>(); 5334 scope.importedGlobal = std::make_unique<ImportedGlobal>();
5335 _importedGlobal = scope.importedGlobal.get(); 5335 _importedGlobal = scope.importedGlobal.get();
5336 _importedGlobal->importingScope = &scope; 5336 _importedGlobal->vars = scope.vars.get();
5337 _importedGlobal->indent = indent(); 5337 _importedGlobal->indent = indent();
5338 _importedGlobal->nl = nl(stmt); 5338 _importedGlobal->nl = nl(stmt);
5339 _importedGlobal->globalCodeLine = &temp.emplace_back(); 5339 _importedGlobal->globalCodeLine = &temp.emplace_back();