Skip to content

Commit 8a01e9c

Browse files
committed
Fixed a crash issue.
1 parent d812fcd commit 8a01e9c

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

spec/inputs/import_global.yue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,10 @@ do
8484
\func 1, 2, 3
8585
.tag = "abc"
8686

87+
do
88+
import global
89+
90+
f = ->
91+
func!
92+
try func
93+

spec/outputs/5.1/import_global.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,16 @@ do
116116
local X = X
117117
X:func(1, 2, 3)
118118
X.tag = "abc"
119-
return X
119+
end
120+
local _anon_func_0 = function(func)
121+
return func
122+
end
123+
do
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
120131
end

spec/outputs/import_global.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,16 @@ do
116116
local X <const> = X
117117
X:func(1, 2, 3)
118118
X.tag = "abc"
119-
return X
119+
end
120+
local _anon_func_0 = function(func)
121+
return func
122+
end
123+
do
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
120131
end

src/yuescript/yue_compiler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static std::unordered_set<std::string> Metamethods = {
7878
"close"s // Lua 5.4
7979
};
8080

81-
const std::string_view version = "0.31.0"sv;
81+
const std::string_view version = "0.31.1"sv;
8282
const std::string_view extension = "yue"sv;
8383

8484
class CompileError : public std::logic_error {
@@ -437,7 +437,7 @@ class YueCompilerImpl {
437437
struct Scope;
438438
struct ImportedGlobal {
439439
std::string* globalCodeLine = nullptr;
440-
Scope* importingScope = nullptr;
440+
std::unordered_map<std::string, VarType>* vars = nullptr;
441441
std::string indent;
442442
std::string nl;
443443
std::unordered_set<std::string_view> globals;
@@ -1625,7 +1625,7 @@ class YueCompilerImpl {
16251625
if (_importedGlobal->globals.find(name) == _importedGlobal->globals.end() && !isSolidDefined(name)) {
16261626
const auto& global = _importedGlobal->globalList.emplace_back(name);
16271627
_importedGlobal->globals.insert(global);
1628-
_importedGlobal->importingScope->vars->insert_or_assign(name, VarType::LocalConst);
1628+
_importedGlobal->vars->insert_or_assign(name, VarType::LocalConst);
16291629
}
16301630
}
16311631

@@ -5333,7 +5333,7 @@ class YueCompilerImpl {
53335333
auto& scope = currentScope();
53345334
scope.importedGlobal = std::make_unique<ImportedGlobal>();
53355335
_importedGlobal = scope.importedGlobal.get();
5336-
_importedGlobal->importingScope = &scope;
5336+
_importedGlobal->vars = scope.vars.get();
53375337
_importedGlobal->indent = indent();
53385338
_importedGlobal->nl = nl(stmt);
53395339
_importedGlobal->globalCodeLine = &temp.emplace_back();

0 commit comments

Comments
 (0)