From f7b674213bd996016cb94c44ef22736a6cbdf6f3 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 14 Jul 2022 17:35:04 +0800 Subject: fix else clause issue in switch statement with table matching. --- spec/inputs/switch.yue | 2 +- spec/outputs/switch.lua | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue index 9e7ecfd..08330bf 100644 --- a/spec/inputs/switch.yue +++ b/spec/inputs/switch.yue @@ -146,7 +146,7 @@ do do switch y - when {x: #:mt} + when {x: #: mt} print mt nil diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index a341e99..c4cde26 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua @@ -213,12 +213,15 @@ do end end if not _match_2 then + local _match_3 = false if _tab_0 then local mt = getmetatable(item) if mt ~= nil then + _match_3 = true print("A table with metatable") end - else + end + if not _match_3 then print("item not accepted!") end end @@ -316,13 +319,16 @@ do if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 or 4 == _exp_0 or 5 == _exp_0 then return "number 1 - 5" else + local _match_1 = false if _tab_0 then local matchAnyTable = _exp_0.matchAnyTable if matchAnyTable == nil then matchAnyTable = "fallback" end + _match_1 = true return matchAnyTable - else + end + if not _match_1 then return "should not reach here unless it is not a table" end end -- cgit v1.2.3-55-g6feb