JohnnyMorganz / StyLua

An opinionated Lua code formatter
Mozilla Public License 2.0
1.53k stars 68 forks source link

[Lua 5.2] Parsing error when label is used after break #861

Open raiguard opened 3 months ago

raiguard commented 3 months ago

Attempting to format this valid Lua code:

for i = 1, 10 do
  if i < 8 then
    print(i)
    goto continue
  end
  break
  ::continue::
end

gives the following error:

error: could not format from stdin: failed to format from stdin: error parsing: error occurred while creating ast: unexpected token `::`. (starting from line 52, character 5 and ending on line 52, character 7)
additional information: expected 'end'

This is likely a full-moon issue rather than something specific to stylua, but I don't want to jump the gun just in case.

JohnnyMorganz commented 3 months ago

This is the same issue as #402

The stylua release binaries are built with all feature flags enabled, and the Luau type assertion syntax conflicts with Lua 5.2 label syntax.

You can use cargo to build a binary with only lua52 enabled and that should work. Hopefully in the next major release we will have runtime configurable syntax selection