Verse - bug(?) with default named arguments in extension methods

I’m getting a compile error if I try to call a function that has a single named argument with a default value, and I don’t specify the value when calling (i.e. attempt to rely on the default value). This only happens when the function is also an extension method. It works fine if it is a normal non-extension method, or if the function has at least 1 additional argument, or if I set the named argument instead of relying on the default, so it’s a very specific combination that breaks.

e.g. with this function which just adds 2 ints, as an extension method of int:

(Value:int).Add(?OtherValue:int=0):int = Value + OtherValue

This compiles:

1.Add(?OtherValue:=2)

This doesn’t:

1.Add()

The error is:

Script error 3509: This function parameter expects a value of type tuple(int,tuple(),?OtherValue:int = …), but this argument is an incompatible value of type tuple(type{1},tuple(),tuple()).

1 Like

This is a bug (I’ve filed a bug report for it). You can workaround it by using overloads:

(Value:int).Add(OtherValue:int):int = Value + OtherValue
(Value:int).Add():int = Value
1 Like