www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - is this a dmd bug ?

reply Long Chang <changedalone gmail.com> writes:
public interface Listener {
    void handleEvent (int);
}

void main(){
    void print(int evt){

    }
    Listener listener    = new class() Listener {
        public void handleEvent(int evt) {
            .print(evt);
        }
    };
}

-----------------------------------------------------------------------------------
x.d(20): Error: undefined identifier module x.print
x.d(20): Error: function expected before (), not module x.print of type void
Nov 24 2009
next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Tue, 24 Nov 2009 14:55:44 +0300, Long Chang <changedalone gmail.com>  
wrote:

 public interface Listener {
     void handleEvent (int);
 }

 void main(){
     void print(int evt){

     }
     Listener listener    = new class() Listener {
         public void handleEvent(int evt) {
             .print(evt);
         }
     };
 }

 -----------------------------------------------------------------------------------
 x.d(20): Error: undefined identifier module x.print
 x.d(20): Error: function expected before (), not module x.print of type  
 void
Try removing a dot before print. As is, it searches for a print function at a global scope, fails to find one and shows an error. I'm not sure it is a proper behavior, though. Try creating a bugzilla report.
Nov 24 2009
prev sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 24 Nov 2009 06:55:44 -0500, Long Chang <changedalone gmail.com>  
wrote:

 public interface Listener {
     void handleEvent (int);
 }

 void main(){
     void print(int evt){

     }
     Listener listener    = new class() Listener {
         public void handleEvent(int evt) {
             .print(evt);
         }
     };
 }

 -----------------------------------------------------------------------------------
 x.d(20): Error: undefined identifier module x.print
 x.d(20): Error: function expected before (), not module x.print of type  
 void
It's the . before the print. It means "only look in the global scope". -Steve
Nov 24 2009
parent reply Long Chang <changedalone gmail.com> writes:
how about this case:


public interface Listener {
    void handleEvent (int);
}

class Test{
    this(){
        Listener listener    = new class() Listener {
            public void handleEvent(int evt) {
                toString(evt);
            }
        };
    }

    void toString(int evt){

    }
}

void main(){

}

---------------------------------------
x.d(17): Error: function object.Object.toString () does not match parameter
types (int)
x.d(17): Error: expected 0 arguments, not 1 for non-variadic function type
char[]()
Nov 24 2009
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 24 Nov 2009 07:38:51 -0500, Long Chang <changedalone gmail.com>  
wrote:

 how about this case:


 public interface Listener {
     void handleEvent (int);
 }

 class Test{
     this(){
         Listener listener    = new class() Listener {
             public void handleEvent(int evt) {
                 toString(evt);
             }
         };
     }

     void toString(int evt){

     }
 }

 void main(){

 }

 ---------------------------------------
 x.d(17): Error: function object.Object.toString () does not match  
 parameter
 types (int)
 x.d(17): Error: expected 0 arguments, not 1 for non-variadic function  
 type
 char[]()
Try outer.toString(evt). Note that the anonymous class inherits from Object, which defines toString as: char[] toString(); So the compiler thinks you are trying to call your anonymous class' toString, not the outer class' toString. -Steve
Nov 24 2009
parent reply Long Chang <changedalone gmail.com> writes:
I use the d1 & tango trunk & dwt-win.
there is a new dispose method for Object, and Dwt-win already have a dispose
width Event argument.

I try it with outer,  the error is :


x.d(17): Error: undefined identifier outer
x.d(17): Error: undefined identifier outer
x.d(17): Error: no property 'toString' for type 'int'
x.d(17): Error: function expected before (), not 1 of type int
Nov 24 2009
next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Tue, 24 Nov 2009 16:09:28 +0300, Long Chang <changedalone gmail.com>  
wrote:

 I use the d1 & tango trunk & dwt-win.
 there is a new dispose method for Object, and Dwt-win already have a  
 dispose
 width Event argument.

 I try it with outer,  the error is :


 x.d(17): Error: undefined identifier outer
 x.d(17): Error: undefined identifier outer
 x.d(17): Error: no property 'toString' for type 'int'
 x.d(17): Error: function expected before (), not 1 of type int
Try using older version of Tango (before introducing Object.dispose() method), or ask for help in digitalmars.DWT newsgroup. It's not a DMD but, it's just DWT is incompatible with Tango trunk at the moment (due to a breaking change in Tango).
Nov 24 2009
prev sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 24 Nov 2009 08:09:28 -0500, Long Chang <changedalone gmail.com>  
wrote:

 I use the d1 & tango trunk & dwt-win.
 there is a new dispose method for Object, and Dwt-win already have a  
 dispose
 width Event argument.

 I try it with outer,  the error is :


 x.d(17): Error: undefined identifier outer
 x.d(17): Error: undefined identifier outer
 x.d(17): Error: no property 'toString' for type 'int'
 x.d(17): Error: function expected before (), not 1 of type int
Hm... I've noticed that you can't just call outer, you have to use this.outer. Does anyone know if this is expected behavior or a bug? Why would it be expected behavior? This code compiles for me and works on dmd 2.033 import std.stdio; public interface Listener { void handleEvent (int); } class Test{ Listener listener; this(){ listener = new class() Listener { public void handleEvent(int evt) { this.outer.toString(evt); } }; } void call() { listener.handleEvent(0); } void toString(int evt){ writefln("event is %d", evt); } } void main(){ (new Test()).call(); } -Steve
Nov 24 2009
parent Long Chang <changedalone gmail.com> writes:
 this.outer also. work on d1.
=C2=A0thank you guys.
Nov 24 2009