Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Bug: (foo :: bar) < baz becomes foo :: bar < baz, which leads to syntax errors #940

@4teapo

Description

@4teapo

For example, if you have an if-then-else expression with a cast and a less-than operation, you might write

return if (foo :: number) < bar
	then very + very + very + long + line + right + here + hopefully
	else lets + ensure + stylua + writes + this + out + using + multiple + lines

When the line is long enough for StyLua 2.0.2 with syntax = "Luau" specified in the config to prefer formatting it in this way, with then and else on their own lines, it also chooses to discard the parentheses around the cast expression, leaving

return if foo :: number < bar
	then very + very + very + long + line + right + here + hopefully
	else lets + ensure + stylua + writes + this + out + using + multiple + lines

This is a syntax error because the parser thinks bar is now a type parameter for number, thanks to < after number, but never finds a closing >.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions