From 828fee1907a8fd8773d304d3d9a49fc0e2f8cb84 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 17 Jul 2025 19:22:33 +0800 Subject: Fixed a crash. --- spec/outputs/codes_from_doc.lua | 29 +++++++++++++++++------------ spec/outputs/codes_from_doc_zh.lua | 29 +++++++++++++++++------------ src/yuescript/yue_compiler.cpp | 14 +++++++------- 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 end end merge = _tab_0 -print((function() +local last +do local _item_0 = data.items - return _item_0[#_item_0] -end)()) -print((function() + last = _item_0[#_item_0] +end +local second_last +do local _item_0 = data.items - return _item_0[#_item_0 - 1] -end)()) + second_last = _item_0[#_item_0 - 1] +end local mt = { } local add add = function(self, right) @@ -2603,14 +2605,16 @@ for _key_0, _value_0 in pairs(b) do end end merge = _tab_0 -print((function() +local last +do local _item_0 = data.items - return _item_0[#_item_0] -end)()) -print((function() + last = _item_0[#_item_0] +end +local second_last +do local _item_0 = data.items - return _item_0[#_item_0 - 1] -end)()) + second_last = _item_0[#_item_0 - 1] +end local mt = { } local add add = function(self, right) @@ -3207,6 +3211,7 @@ local some_string = "Here is a string\n that has a line break in it." print("I am " .. tostring(math.random() * 100) .. "% sure.") local integer = 1000000 local hex = 0xEFBBBF +local binary = 19 local my_function my_function = function() end my_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 end end merge = _tab_0 -print((function() +local last +do local _item_0 = data.items - return _item_0[#_item_0] -end)()) -print((function() + last = _item_0[#_item_0] +end +local second_last +do local _item_0 = data.items - return _item_0[#_item_0 - 1] -end)()) + second_last = _item_0[#_item_0 - 1] +end local mt = { } local add add = function(self, right) @@ -2597,14 +2599,16 @@ for _key_0, _value_0 in pairs(b) do end end merge = _tab_0 -print((function() +local last +do local _item_0 = data.items - return _item_0[#_item_0] -end)()) -print((function() + last = _item_0[#_item_0] +end +local second_last +do local _item_0 = data.items - return _item_0[#_item_0 - 1] -end)()) + second_last = _item_0[#_item_0 - 1] +end local mt = { } local add add = function(self, right) @@ -3201,6 +3205,7 @@ local some_string = "这是一个字符串\n 并包括一个换行。" print("我有" .. tostring(math.random() * 100) .. "%的把握。") local integer = 1000000 local hex = 0xEFBBBF +local binary = 19 local my_function my_function = function() end my_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: if (argsDef->varArg) { newArgs.emplace_back(_parser.toString(argsDef->varArg)); } - } - if (argsDef->label) { - hasCheck = true; - const auto& astName = _parser.toString(argsDef->label); - if (!_parser.hasAST(astName)) { - throw CompileError("invalid AST name"sv, argsDef->label); + if (argsDef->label) { + hasCheck = true; + const auto& astName = _parser.toString(argsDef->label); + if (!_parser.hasAST(astName)) { + throw CompileError("invalid AST name"sv, argsDef->label); + } + argChecks.emplace_back("..."s + astName); } - argChecks.emplace_back("..."s + astName); } std::string macroCodes = "_ENV=require('yue').macro_env\n("s + join(newArgs, ","sv) + ")->"s + _parser.toString(macroLit->body); auto chunkName = "=(macro "s + macroName + ')'; -- cgit v1.2.3-55-g6feb