-
I was wondering:
var say = Fn.new {|word| System.print(word) }
say.call() // invalid
say.call("hello") // ok
say.call("hello", "there") // ok, "there" is ignored
class Person {
construct new() {}
say(word) {
System.print(word)
}
}
var person = Person.new()
person.say("hello", "there") // not ok |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
It should definitely be an error to call a function with too many arguments IMO. Possibly the reason why it's allowed for functions but not methods is because the former do not allow overloading based on arity but the latter, of course, do. The current situation is in fact down-right dangerous - see #731 and #1050. @mhermier has posted a PR (#1124) to fix the dangerous part. I'd like to see this go further and outlaw excess arguments altogether. |
Beta Was this translation helpful? Give feedback.
-
The reason is simple. It does allow to have common call interface for free.
And it can only apply for functions because methods must be redirected to
the correct symbol. Since it can't be done at compile, we can't have it for
methods, and we manually added it for functions.
|
Beta Was this translation helpful? Give feedback.
-
I don't really follow that explanation as I can't see how it can be regarded as a good thing to allow functions to be called with too many arguments even if it's harmless (which it currently isn't) and the excess arguments can just be discarded. If the VM can detect that a function is being called with two few arguments, then presumably it could detect if it's being called with too many or is the real reason for this that the extra check is considered to be too expensive performance-wise? |
Beta Was this translation helpful? Give feedback.
-
It was meant to avoid to implement a The fact that it has a bug in the implementation doesn't make it more dangerous as any other bugs. |
Beta Was this translation helpful? Give feedback.
-
OK, if the reason for allowing excess arguments is to significantly ease implementation, then I can accept that even if it's not ideal. On thing we can probably all agree on is that the current bug in the implementation needs fixing quickly as it's very dangerous. |
Beta Was this translation helpful? Give feedback.
It should definitely be an error to call a function with too many arguments IMO. Possibly the reason why it's allowed for functions but not methods is because the former do not allow overloading based on arity but the latter, of course, do.
The current situation is in fact down-right dangerous - see #731 and #1050.
@mhermier has posted a PR (#1124) to fix the dangerous part. I'd like to see this go further and outlaw excess arguments altogether.