Skip to content

Commit 75e4ddb

Browse files
Fix type-aware function parsing for functions with only optional arguments (#8189)
Account for functions with all optional parameters
1 parent 9a83341 commit 75e4ddb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/main/java/ch/njol/skript/lang/SkriptParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ record SignatureData(ClassInfo<?> classInfo, boolean plural) { }
12341234
boolean trySingle = false;
12351235
boolean trySinglePlural = false;
12361236
for (var signature : signatures) {
1237-
trySingle |= signature.getMinParameters() == 1 || signature.getMaxParameters() == 1;
1237+
trySingle |= signature.getMinParameters() <= 1 || signature.getMaxParameters() == 1;
12381238
trySinglePlural |= trySingle && !signature.getParameter(0).isSingleValue();
12391239
for (int i = 0; i < signature.getMaxParameters(); i++) {
12401240
if (signatureDatas.size() <= i) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local function test(x: number = 3, y: number = 5) returns number:
2+
return {_x} + {_y}
3+
4+
test "functions behave wrong with all default args":
5+
assert test() is 8 with "no args did not use both default values"
6+
assert test(1) is 6 with "only one arg did not use the second default value"
7+
assert test(1, 2) is 3 with "both args still used a default value"

0 commit comments

Comments
 (0)