Need clarification on optional parameters without an explicit default value #352
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
P1
A high priority bug; for example, a single project is unusable or has many test failures
This issue was originally filed by [email protected]
I may just need to be pointed to the right area in the spec - but I couldn't figure this out on a quick read this morning. I'm trying to understand the precise meaning of "default value is specified in the signature".
What is the difference between:
void m([a]) and void m([a=null])?
In dart code and from observing the VM, these two methods appear to have the same runtime behavior of marking 'a' as optional and using a default value of null when calling 'm' with zero arguments.
However, these two declarations appear to be treated differently by the VM for errors. Specifically, the rules in the spec of the form: "It is a compile-time error if any default values are specified in the signature of an abstract method." and similar ones appear to treat the two signatures above differently where void m([a]) is not considered to be specifying a default value, but void m([a=nlll]) is.
Is the VM's current behavior correct? If so, what is the meaning of the optional parameters on an abstract method? Also, is the current behavior (which feels very useful to me) or treating an optional parameter without an explicit default value as having a default value of null correct?
tests/language/src/NamedParameters8NegativeTest is a good example of this. As written, it produces the expected error from the VM. However, if the '= null' is removed, it will compile and run - producing instead the runtime error on Expect.equals(true, false);
Thanks for helping to clarify this - Jim
The text was updated successfully, but these errors were encountered: