Skip to content

Bug: Empty list/table pattern in switch generates invalid Lua code with { } = _exp_0 #249

@tolpify

Description

@tolpify

When using an empty list [] (or empty table {}) as a pattern in a switch/when clause, YueScript generates invalid Lua code that attempts to destructure into an empty table literal, which causes a syntax error in Lua.
Code example:

switch x
  when [] then []
  else x

Generated lua

local _exp_0 = x
local _type_0 = type(_exp_0)
local _tab_0 = "table" == _type_0 or "userdata" == _type_0
local _match_0 = false
if _tab_0 then
	{ } = _exp_0	-- Syntax error here
	_match_0 = true
	return { }
end
if not _match_0 then
	return x
end

Environment:

$ yue --version
Yuescript version: 0.33.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions