digitalmars.D.bugs - Static method resolution bug (dmd 0.113)
- zwang <nehzgnaw gmail.com> Feb 18 2005
- zwang <nehzgnaw gmail.com> Feb 18 2005
- Stewart Gordon <smjg_1998 yahoo.com> Feb 18 2005
- zwang <nehzgnaw gmail.com> Feb 18 2005
<code>
#1 class B{
#2 int f(int i){return i;}
#3 static int f(){
#4 return 0;
#5 }
#6 }
#7 class A{
#8 int f(){
#9 return B.f();
#10 }
#11 }
</code>
DMD 0.113 complains:
"test.d(9): 'this' is required, but B is not a base class of A"
As we can see, class A doesn't have to derive from B to call its
static method.
BTW, the code compiles if line #2 is commented out.
Feb 18 2005
Here is a variant example to demonstrate the bug:
<code>
class B{
void f(int i){}
static void f(){}
}
void main(){
B.f();
}
</code>
DMD error message:
"test.d(6): 'this' is only allowed in non-static member functions"
Interestingly, if we switch the order of method declaration,
the code compiles happily.
<code>
class B{
static void f(){}
void f(int i){}
}
void main(){
B.f();
}
</code>
zwang wrote:
<code>
#1 class B{
#2 int f(int i){return i;}
#3 static int f(){
#4 return 0;
#5 }
#6 }
#7 class A{
#8 int f(){
#9 return B.f();
#10 }
#11 }
</code>
DMD 0.113 complains:
"test.d(9): 'this' is required, but B is not a base class of A"
As we can see, class A doesn't have to derive from B to call its
static method.
BTW, the code compiles if line #2 is commented out.
Feb 18 2005
zwang wrote:Here is a variant example to demonstrate the bug: <code> class B{ void f(int i){} static void f(){} } void main(){ B.f(); } </code> DMD error message: "test.d(6): 'this' is only allowed in non-static member functions"
This bug has been around for ages and reported several times. Here are just some of the bugs that have been around for a while (if you haven't found it already): http://www.wikiservice.at/wiki4d/wiki.cgi?PendingPeeves Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Feb 18 2005
Stewart Gordon wrote:This bug has been around for ages and reported several times. Here are just some of the bugs that have been around for a while (if you haven't found it already): http://www.wikiservice.at/wiki4d/wiki.cgi?PendingPeeves Stewart.
Thanks. I wasn't aware of this page before.
Feb 18 2005








zwang <nehzgnaw gmail.com>