full-moon icon indicating copy to clipboard operation
full-moon copied to clipboard

Does not support leading &

Open iamawatermelo opened this issue 1 year ago • 2 comments

From https://github.com/JohnnyMorganz/StyLua/issues/877:

local f: & number & string = "hi"

This is valid Luau code:

image

StyLua cannot format it, though:

sarah@localhost ~/project (main) [2]> StyLua example.luau
error: could not format file example.luau: error parsing: error occurred while creating ast: unexpected token `&`. (starting from line 1, character 10 and ending on line 1, character 11)
additional information: expected type after colon
sarah@localhost ~/project (main) [2]> StyLua --version
stylua 0.20.0
sarah@localhost ~/project (main)>

StyLua was installed from aftman.

The issue appears to be that full-moon cannot parse it, so StyLua fails.

iamawatermelo avatar Jul 25 '24 22:07 iamawatermelo

Fixed by #306

Kampfkarren avatar Jul 27 '24 02:07 Kampfkarren

When the leading & or | are used in some specific cases, they don't parse. Here are the cases I found so far

-- in function return types
type Fn = () -> & A & B
local function oof():  & A & B end

-- in generic parameters
type A = Generic<&boolean & string>

-- in variadic type packs
type Fn = (...&boolean & string) -> ()

jeparlefrancais avatar Oct 14 '24 21:10 jeparlefrancais