godot-gdscript-toolkit: GDScript 2.0 - multiline lambdas not supported
This is flagged as error on gd-format but completely legit syntax in GDScript 2.0:
func f():
return func():
pass
Error:
return func():
^
Unexpected token Token('_NL', '\n\t\t') at line 11, column 16.
Expected one of:
* NOT
* HEX
* BANG
* BIN
* VAR
* AWAIT
* PERCENT
* NUMBER
* LPAR
* LBRACE
* REGULAR_STRING
* CIRCUMFLEX
* TILDE
* LSQB
* RETURN
* NAME
* LONG_STRING
* DOLLAR
* MINUS
* FUNC
* PLUS
* AMPERSAND
* PASS
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 12
- Comments: 15 (6 by maintainers)
@Skyway666 that’s a good point - I can try exploring that. It’s definitely not as simple as writing a single
if
statement or so, but maybe with some more conditions, it will be possible to give such helpful error in, say, 80% of situations. That would help a lot, I agree.@MikeSchulze since it does happen on the parser level, the
# gdlint:disable=
is not possible. I’ll try to fix it at some point probably. Anyway, it’s still a low prio as for fairly small lambdas it can be worked around by turning multiline lambda into single-line one:func(key):prints("key:", key);return true
Multiline lambdas are currently not supported. They won’t be anytime soon as it requires writing a custom lexer to avoid ambiguity on the parser level.
I can understand not wanting to support Multiline Lambdas if it implies too much work (I’ve never build a linter or formatter) since a simple workaround is creating a separate function for the callback.
However, would it be much harder to work on handling the exception? When parsing multiple files the user doesn’t even know which one is causing the error, and it’s hard to deduce why it is happening. An error message as the following would be helpful:
Error in "sample.gd" line 32: gdscript toolkit doesn't support Multiline Lambda functions, please create a separate function to assign as callback.
At least it will prevent users from writing more duplicate issues about the matter 😃
Same problem here on a maybe more tricky problem
Error:
Disable the linter is ok but we can’t disable the formatter for this problem. Also if we have a “if”, can’t make the trick to do all in the same line
Unexpected token Token('COLON', ':') at line 11, column 66.