Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix function parsing with ambiguous lists in parameters. #6579

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

Moderocky
Copy link
Member

@Moderocky Moderocky commented Apr 17, 2024

Summary

Upon failing to parse a function (with too few arguments) Skript will re-attempt it explicitly as an ExpressionList of arguments.

This fixes func(uuid of player, "hello") being wrongly-interpreted as func(uuid of (player, "hello")) and failing to parse.

Note: the Git diff is a nightmare because the methods in SkriptParser are nine million lines long, I can't do anything about that, sorry 😦

The problem

Functions struggle with ambiguous parameters: is func(uuid of {_a}, {_b}) asking for a function with two parameters (uuid of {_a} and {_b}) or is it asking for a function with a single parameter (uuid of {_a} and {_b})?

Most rational people would say the first, but Skript does not think so! Lists are checked after singular expression parsing (for arguably good reason), so uuid of {_a} and {_b} will be matched first.

This means that your function func(uuid: string, something: string) will fail.

This on its own is fine. Everything here is intended, however we have a secret enemy: string converters!

Since 2.6 we are in an era where a string can be anything it wants. This means that while uuid of "hello" ought to fail (because how can a text have a UUID?) the text can be implicitly converted to a World, which can have a UUID.
This means that even nonsensical stuff like uuid of {_a}, "have a nice day!" is technically admissible at parse time.

Converters bring us lots of nice things, but they've also exacerbated this issue with function parsing, because it's even harder for us to identify a mistake.

My Lovely(ish) Solution

My fix is as follows:
If the function fails -- specifically because it has too few parameters -- the arguments string is reparsed as only a list of expressions, and then it's tested again. If it still fails, oh well.

This isn't perfect: obviously it's a second needless check for things that are actually just wrong, but that's not the end of the world.

It also can't fix parsing ambiguity mid-way through the arguments: "hello", uuid of {_a}, "there" is still gonna be parsed the wrong way because that's how Skript parses stuff, and we probably shouldn't change that.
Walrus said it's fine 🙂


Target Minecraft Versions: any
Requirements: none
Related Issues: closes #4988

@Moderocky Moderocky added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. functions Related to functions labels Apr 17, 2024
Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good in testing too

@sovdeeth sovdeeth added the patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version. label Apr 22, 2024
@Moderocky Moderocky merged commit 3e55190 into SkriptLang:dev/patch Apr 24, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. functions Related to functions patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants