aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-07-17 19:22:33 +0800
committerLi Jin <dragon-fly@qq.com>2025-07-17 19:22:33 +0800
commit828fee1907a8fd8773d304d3d9a49fc0e2f8cb84 (patch)
treef4b82e38c793fee7141b5d8f4d326fd31bee985e
parentc03bf36db11bcd90034b0e67bd1f5c8c0765eb7f (diff)
downloadyuescript-828fee1907a8fd8773d304d3d9a49fc0e2f8cb84.tar.gz
yuescript-828fee1907a8fd8773d304d3d9a49fc0e2f8cb84.tar.bz2
yuescript-828fee1907a8fd8773d304d3d9a49fc0e2f8cb84.zip
Fixed a crash.
-rw-r--r--spec/outputs/codes_from_doc.lua29
-rw-r--r--spec/outputs/codes_from_doc_zh.lua29
-rw-r--r--src/yuescript/yue_compiler.cpp14
3 files changed, 41 insertions, 31 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 085179c..f1e46d9 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.lua
@@ -209,14 +209,16 @@ for _key_0, _value_0 in pairs(b) do
209 end 209 end
210end 210end
211merge = _tab_0 211merge = _tab_0
212print((function() 212local last
213do
213 local _item_0 = data.items 214 local _item_0 = data.items
214 return _item_0[#_item_0] 215 last = _item_0[#_item_0]
215end)()) 216end
216print((function() 217local second_last
218do
217 local _item_0 = data.items 219 local _item_0 = data.items
218 return _item_0[#_item_0 - 1] 220 second_last = _item_0[#_item_0 - 1]
219end)()) 221end
220local mt = { } 222local mt = { }
221local add 223local add
222add = function(self, right) 224add = function(self, right)
@@ -2603,14 +2605,16 @@ for _key_0, _value_0 in pairs(b) do
2603 end 2605 end
2604end 2606end
2605merge = _tab_0 2607merge = _tab_0
2606print((function() 2608local last
2609do
2607 local _item_0 = data.items 2610 local _item_0 = data.items
2608 return _item_0[#_item_0] 2611 last = _item_0[#_item_0]
2609end)()) 2612end
2610print((function() 2613local second_last
2614do
2611 local _item_0 = data.items 2615 local _item_0 = data.items
2612 return _item_0[#_item_0 - 1] 2616 second_last = _item_0[#_item_0 - 1]
2613end)()) 2617end
2614local mt = { } 2618local mt = { }
2615local add 2619local add
2616add = function(self, right) 2620add = function(self, right)
@@ -3207,6 +3211,7 @@ local some_string = "Here is a string\n that has a line break in it."
3207print("I am " .. tostring(math.random() * 100) .. "% sure.") 3211print("I am " .. tostring(math.random() * 100) .. "% sure.")
3208local integer = 1000000 3212local integer = 1000000
3209local hex = 0xEFBBBF 3213local hex = 0xEFBBBF
3214local binary = 19
3210local my_function 3215local my_function
3211my_function = function() end 3216my_function = function() end
3212my_function() 3217my_function()
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index bb9af58..4689232 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -209,14 +209,16 @@ for _key_0, _value_0 in pairs(b) do
209 end 209 end
210end 210end
211merge = _tab_0 211merge = _tab_0
212print((function() 212local last
213do
213 local _item_0 = data.items 214 local _item_0 = data.items
214 return _item_0[#_item_0] 215 last = _item_0[#_item_0]
215end)()) 216end
216print((function() 217local second_last
218do
217 local _item_0 = data.items 219 local _item_0 = data.items
218 return _item_0[#_item_0 - 1] 220 second_last = _item_0[#_item_0 - 1]
219end)()) 221end
220local mt = { } 222local mt = { }
221local add 223local add
222add = function(self, right) 224add = function(self, right)
@@ -2597,14 +2599,16 @@ for _key_0, _value_0 in pairs(b) do
2597 end 2599 end
2598end 2600end
2599merge = _tab_0 2601merge = _tab_0
2600print((function() 2602local last
2603do
2601 local _item_0 = data.items 2604 local _item_0 = data.items
2602 return _item_0[#_item_0] 2605 last = _item_0[#_item_0]
2603end)()) 2606end
2604print((function() 2607local second_last
2608do
2605 local _item_0 = data.items 2609 local _item_0 = data.items
2606 return _item_0[#_item_0 - 1] 2610 second_last = _item_0[#_item_0 - 1]
2607end)()) 2611end
2608local mt = { } 2612local mt = { }
2609local add 2613local add
2610add = function(self, right) 2614add = function(self, right)
@@ -3201,6 +3205,7 @@ local some_string = "这是一个字符串\n 并包括一个换行。"
3201print("我有" .. tostring(math.random() * 100) .. "%的把握。") 3205print("我有" .. tostring(math.random() * 100) .. "%的把握。")
3202local integer = 1000000 3206local integer = 1000000
3203local hex = 0xEFBBBF 3207local hex = 0xEFBBBF
3208local binary = 19
3204local my_function 3209local my_function
3205my_function = function() end 3210my_function = function() end
3206my_function() 3211my_function()
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 35d99bd..f952e9a 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -5448,14 +5448,14 @@ private:
5448 if (argsDef->varArg) { 5448 if (argsDef->varArg) {
5449 newArgs.emplace_back(_parser.toString(argsDef->varArg)); 5449 newArgs.emplace_back(_parser.toString(argsDef->varArg));
5450 } 5450 }
5451 } 5451 if (argsDef->label) {
5452 if (argsDef->label) { 5452 hasCheck = true;
5453 hasCheck = true; 5453 const auto& astName = _parser.toString(argsDef->label);
5454 const auto& astName = _parser.toString(argsDef->label); 5454 if (!_parser.hasAST(astName)) {
5455 if (!_parser.hasAST(astName)) { 5455 throw CompileError("invalid AST name"sv, argsDef->label);
5456 throw CompileError("invalid AST name"sv, argsDef->label); 5456 }
5457 argChecks.emplace_back("..."s + astName);
5457 } 5458 }
5458 argChecks.emplace_back("..."s + astName);
5459 } 5459 }
5460 std::string macroCodes = "_ENV=require('yue').macro_env\n("s + join(newArgs, ","sv) + ")->"s + _parser.toString(macroLit->body); 5460 std::string macroCodes = "_ENV=require('yue').macro_env\n("s + join(newArgs, ","sv) + ")->"s + _parser.toString(macroLit->body);
5461 auto chunkName = "=(macro "s + macroName + ')'; 5461 auto chunkName = "=(macro "s + macroName + ')';