Optional Argument Improvements
Fixes an issue detailed in the previous release (0.41.0):
Optional arguments in a variadic function must be specified somewhere in the argument list, to prevent the variadic arguments from being "stolen" by the positional parameter (then you get an error about how you must pass the optional argument by name, even though that wasn't your intention).
For example, this:fn qux(x: str, y: int = 3, args: [str: ...]) { ... }Will result in this error:
error: optional argument 'y' must be passed by name at: ultratiny.flx:28:26 | 28 | qux("hello, world!", "hi", "my", "name", "is", "bob", "ross") | ‾‾‾‾
Now, the example above will work "intuitively"; the strings (starting from "hi"
) will be passed as varargs to the function, and y
will have the default value of 3
.
Note that this means if the intention was to pass a value to y
(but you forgot the name), like this: foo("bla", 7, "a", "bunch", "of", "strings")
, the error will now be the failure in casting 7
to str
, because we presume you wanted to pass 7
as a vararg.
We can't have it both ways, but I feel like the new behaviour will be the more helpful error in the majority of cases.