-
-
Notifications
You must be signed in to change notification settings - Fork 416
Implement better function argument ordering parsing #8352
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
Implement better function argument ordering parsing #8352
Conversation
src/main/java/org/skriptlang/skript/common/function/FunctionReferenceParser.java
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/common/function/FunctionReferenceParser.java
Outdated
Show resolved
Hide resolved
Efnilite
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some extra comments would be appreciated 🙏
src/main/java/org/skriptlang/skript/common/function/FunctionReferenceParser.java
Outdated
Show resolved
Hide resolved
Efnilite
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, although the getExactReferences method is now quite long and complicated. future improvements could split it up tho. nice 🔥
Problem
Currently, the enhanced function argument parsing with named arguments is too restrictive when optional parameters exist. For example, the following function call errors for a somewhat unclear reason:
set {_loc} to location(x: 1, y: 1, z: 1, yaw: 1, pitch: 1)(Mixing named and unnamed arguments is not allowed unless the order of the arguments matches the order of the parameters.). This error is because theworldparameter must occur before theyawparameter. However, given that it is optional. one would expect for this function call to work without issue.Solution
I have reworked the function argument parsing so that the user provided arguments are instead reworked into the order defined by the function signature. First, all named parameters are inserted into their respective positions. Then, the remaining unnamed arguments are inserted into the remaining positions. An unnamed parameter is only valid in its position if the named parameter it represents occurs before all named parameters that come after in the user's provided arguments.
For example, the following calls are now valid:
location(1, 2, 3, pitch: 10, yaw: 5)where1,2, and3representx,y, andzrespectivelylocation(x: 1, y: 2, z: 3, yaw: 4, 5)where5representspitchlocation(x: 1, 2, z: 3) where2representsy`.Further, I fixed a mistake where failures to parse arguments as expressions would result in the default value being used. Instead, an error about the input being invalid for that parameter is now parsed.
Testing Completed
I have added a few additional tests to
StructFunction.skSupporting Information
n/a
Completes: none
Related: none
AI assistance: none