StyLua icon indicating copy to clipboard operation
StyLua copied to clipboard

Call ambiguity syntax is handled oddly

Open appgurueu opened this issue 4 years ago • 1 comments

Due to Lua not recognizing line breaks as statement delimiters, there is an infamous ambiguity of the Lua syntax. If a blank line is left in an indented block as follows, preceded by a parenthesized call statement:

do
	_ = a

	(b or c)()
end

StyLua will first turn this into:

do
	_ = a
(b or c)()
end

And only after this into the expected form (which highlights how Lua actually treats the newline):

do
	_ = a(b or c)()
end

appgurueu avatar Dec 16 '21 17:12 appgurueu

This is somewhat related to #169, and it is quite hard to solve with the current way StyLua works. Fixing this and #169 will require a large overhaul of formatting at the token level, which is why its taken me a while to do this.

At the moment, the 2-pass formatting isn't a particular concern for me (it might actually help someone notice the ambiguity in this situation), but I will try to fix this bug one day

JohnnyMorganz avatar Dec 17 '21 19:12 JohnnyMorganz