You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In DMD64 v2.062, if you define a method with a default argument from a member variable, DMD only complains if the method is actually called:
class Foo{ int a = 0; void bar(int x = a) { }}void main(){ Foo f = new Foo(); //f.bar(); -> does not complain with this commented out}
With the method call it produces the error "need 'this' to access member a", which seems to be the defined behavior (but why not allow the default argument to be variable? you can just read 'a' and push it on the stack).
The text was updated successfully, but these errors were encountered:
(In reply to comment #1)
> Default arguments are evaluated at the call site... so I don't think this is> necessarily wrong.
I think the compiler should give errors for wrong code, even if the function is not yet called.
Hmm, this doesn't work either.
class Foo
{
int a = 0;
void bar(int x = a){}void baz(){ bar();}
}
void main()
{
Foo f = new Foo();
//f.bar(); -> does not complain with this commented out
}
They probably should be banned.
Luís Marques (@luismarques) reported this on 2013-04-25T19:54:34Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=9992
CC List
Description
In DMD64 v2.062, if you define a method with a default argument from a member variable, DMD only complains if the method is actually called: class Foo { int a = 0; void bar(int x = a) { } } void main() { Foo f = new Foo(); //f.bar(); -> does not complain with this commented out } With the method call it produces the error "need 'this' to access member a", which seems to be the defined behavior (but why not allow the default argument to be variable? you can just read 'a' and push it on the stack).The text was updated successfully, but these errors were encountered: