Skip to content

Commit c43c407

Browse files
committed
Add a new error EInvalidParamCount for exceeding provided arguments and reword EInvalidArgCount for better clarity.
1 parent c3780cd commit c43c407

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

polymod/hscript/_internal/Expr.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ enum Error
164164
EBlacklistedField(f:String);
165165
EPurgedFunction(f:String); // Function can't be called because it previously threw an uncaught exception
166166
EInvalidArgCount(f:String, expected:Int, given:Int); // Given arguments count don't match the minimum required parameters
167+
EExceedArgsCount(f:String, allowed:Int, passed:Int); // Provided arguments exceed the maximum allowed parameter count
167168
ENullObjectReference(f:String); // Accessing a field of "null"
168169
EInvalidScriptedFnAccess(f:String);
169170
EInvalidScriptedVarGet(v:String);

polymod/hscript/_internal/PolymodInterpEx.hx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,15 +1941,24 @@ class PolymodInterpEx extends Interp
19411941
if (args == null) return;
19421942

19431943
var minParams = 0;
1944+
var maxAllowed = params.length;
1945+
19441946
for (i in 0...params.length)
19451947
{
19461948
var p = params[i];
19471949
if (!p.opt && p.value == null) minParams = i + 1;
19481950
}
19491951

1952+
final funcName:String = (name != null) ? " for function '" + name + "'" : "";
19501953
if (args.length < minParams)
19511954
{
1952-
error(EInvalidArgCount((name != null) ? " for function '" + name + "'" : "", minParams, args.length));
1955+
error(EInvalidArgCount(funcName, minParams, args.length));
1956+
}
1957+
else if (args.length > maxAllowed)
1958+
{
1959+
// Manual return for `new` as parameter count shouldn't matter here
1960+
if (name == "new") return;
1961+
error(EExceedArgsCount(funcName, maxAllowed, args.length));
19531962
}
19541963
}
19551964

polymod/hscript/_internal/Printer.hx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ class Printer
696696
case EInvalidModule(m): "Invalid module: " + m;
697697
case EBlacklistedModule(m): "Blacklisted module: " + m;
698698
case EBlacklistedField(m): "Blacklisted field: " + m;
699-
case EInvalidArgCount(f, expected, given): 'Invalid number of given arguments. Got $given, required $expected' + f;
699+
case EInvalidArgCount(f, expected, given): 'Provided arguments are fewer than the required function parameters. Got $given, required $expected' + f;
700+
case EExceedArgsCount(f, allowed, passed): 'Provided arguments exceeds the allowed function parameter count. Passed $passed, allowed $allowed' + f;
700701
case EPurgedFunction(f): "Invalid access to purged function (did it throw an uncaught exception earlier?): " + f;
701702
case ENullObjectReference(f): "Invalid reference to field of a null object: " + f;
702703
case EInvalidInStaticContext(v): "Invalid field access from static context: " + v;

0 commit comments

Comments
 (0)