From 3ea3f9b1c42eae103c370a986f539a0f1550db9f Mon Sep 17 00:00:00 2001
From: Li Jin <dragon-fly@qq.com>
Date: Thu, 18 Feb 2021 11:54:14 +0800
Subject: prevent inserting global or local statements with wildcard operators
 from macro. update changelog.

---
 src/yuescript/yue_compiler.cpp | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 4917e4e..7be0c84 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -58,7 +58,7 @@ inline std::string s(std::string_view sv) {
 	return std::string(sv);
 }
 
-const std::string_view version = "0.6.6"sv;
+const std::string_view version = "0.6.7"sv;
 const std::string_view extension = "yue"sv;
 
 class YueCompilerImpl {
@@ -3460,6 +3460,20 @@ private:
 						info.node.set(exp);
 					}
 				}
+				if (auto block = info.node.as<Block_t>()) {
+					for (auto stmt_ : block->statements.objects()) {
+						auto stmt = static_cast<Statement_t*>(stmt_);
+						if (auto global = stmt->content.as<Global_t>()) {
+							if (global->item.is<global_op_t>()) {
+								throw std::logic_error(_info.errorMessage(s("can not insert global statement with wildcard operator from macro"sv), x));
+							}
+						} else if (auto local = stmt->content.as<Local_t>()) {
+							if (local->item.is<local_flag_t>()) {
+								throw std::logic_error(_info.errorMessage(s("can not insert local statement with wildcard operator from macro"sv), x));
+							}
+						}
+					}
+				}
 				return {info.node, std::move(info.codes), Empty, std::move(localVars)};
 			} else {
 				if (!isBlock) throw std::logic_error(_info.errorMessage(s("failed to expanded empty macro as expr"sv), x));
-- 
cgit v1.2.3-55-g6feb