digitalmars.D - Is this intended behavior?
- Jacob Carlborg (30/30) Aug 10 2008 Is this intended behavior?
- downs (1/1) Aug 10 2008 Try .id
- Jacob Carlborg (6/7) Aug 10 2008 Yeah that works but I'm porting a library from Java to D so it breaks
- Jarrett Billingsley (6/13) Aug 10 2008 It's intended behavior. Name lookup happens from the innermost scope
- Jacob Carlborg (2/18) Aug 10 2008 Tanks for that answer.
- Auria (2/39) Aug 10 2008 I would say it's not a good diea to name both a class and its member var...
- Jacob Carlborg (6/47) Aug 10 2008 I know that the convention is that class names should begin with an
- Michel Fortin (11/17) Aug 10 2008 kind of Java library is that you're porting?
- Jacob Carlborg (2/21) Aug 11 2008 SWT Cocoa, http://www.eclipse.org/swt/
Is this intended behavior? class id { public int id; public this () { } public this (int id) { this.id = id; } } class NSObject : id { public this () { } public this (int id) { this.id = id; } id foo () // error here { return new id(3); } } The compiler says: "Error: id is used as a type" using the gdc bundle from the tango website on osx. Apparently the compiler thinks the return type "id" refers to the member variable instead of the class.
Aug 10 2008
downs wrote:Try .idYeah that works but I'm porting a library from Java to D so it breaks the interface and I have to replace every "id" with ".id". For now I have changed the member variable to "id_" then I can do a global search and replace for "this.id" and replace to "this.id_". I've solved my problem but I was wondering if this was the intended behavior or a bug.
Aug 10 2008
"Jacob Carlborg" <doobnet gmail.com> wrote in message news:g7mqd2$2rab$1 digitalmars.com...downs wrote:It's intended behavior. Name lookup happens from the innermost scope outwards, and does not depend upon how the name is used. Since 'id' is a member of the class, it finds that first, rather than the class 'id'. Maybe Java keeps looking for another name 'id' that can be used as a type?Try .idYeah that works but I'm porting a library from Java to D so it breaks the interface and I have to replace every "id" with ".id". For now I have changed the member variable to "id_" then I can do a global search and replace for "this.id" and replace to "this.id_". I've solved my problem but I was wondering if this was the intended behavior or a bug.
Aug 10 2008
Jarrett Billingsley wrote:"Jacob Carlborg" <doobnet gmail.com> wrote in message news:g7mqd2$2rab$1 digitalmars.com...Tanks for that answer.downs wrote:It's intended behavior. Name lookup happens from the innermost scope outwards, and does not depend upon how the name is used. Since 'id' is a member of the class, it finds that first, rather than the class 'id'. Maybe Java keeps looking for another name 'id' that can be used as a type?Try .idYeah that works but I'm porting a library from Java to D so it breaks the interface and I have to replace every "id" with ".id". For now I have changed the member variable to "id_" then I can do a global search and replace for "this.id" and replace to "this.id_". I've solved my problem but I was wondering if this was the intended behavior or a bug.
Aug 10 2008
Jacob Carlborg Wrote:Is this intended behavior? class id { public int id; public this () { } public this (int id) { this.id = id; } } class NSObject : id { public this () { } public this (int id) { this.id = id; } id foo () // error here { return new id(3); } } The compiler says: "Error: id is used as a type" using the gdc bundle from the tango website on osx. Apparently the compiler thinks the return type "id" refers to the member variable instead of the class.I would say it's not a good diea to name both a class and its member variable the same name. (nyway, the convention is usually that class names begin with an upper case letter IIRC) Even if it was allowed, i'd discourage it, your use of "id" is very confusing, it's both a class and a variable
Aug 10 2008
Auria wrote:Jacob Carlborg Wrote:I know that the convention is that class names should begin with an uppercase letter and it's not very good to name a member variable the same as the class name but I have not created the library I'm just porting it. In this case "id" refers to the type "id" in Objective-cIs this intended behavior? class id { public int id; public this () { } public this (int id) { this.id = id; } } class NSObject : id { public this () { } public this (int id) { this.id = id; } id foo () // error here { return new id(3); } } The compiler says: "Error: id is used as a type" using the gdc bundle from the tango website on osx. Apparently the compiler thinks the return type "id" refers to the member variable instead of the class.I would say it's not a good diea to name both a class and its member variable the same name. (nyway, the convention is usually that class names begin with an upper case letter IIRC) Even if it was allowed, i'd discourage it, your use of "id" is very confusing, it's both a class and a variable
Aug 10 2008
On 2008-08-10 16:54:57 -0400, Jacob Carlborg <doobnet gmail.com> said:I know that the convention is that class names should begin with an uppercase letter and it's not very good to name a member variable the same as the class name but I have not created the library I'm just porting it. In this case "id" refers to the type "id" in Objective-cWhatkind of Java library is that you're porting? By the way, in my D/Objective-C bridge, I'm using the root Object class in D as an equivalent to to the Objective-C id type, and it allows any D object to be passed to Objective-C code. <http://michelf.com/projects/d-objc-bridge/> -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Aug 10 2008
Michel Fortin wrote:On 2008-08-10 16:54:57 -0400, Jacob Carlborg <doobnet gmail.com> said:SWT Cocoa, http://www.eclipse.org/swt/I know that the convention is that class names should begin with an uppercase letter and it's not very good to name a member variable the same as the class name but I have not created the library I'm just porting it. In this case "id" refers to the type "id" in Objective-c TP30001163-CH11-SW3Whatkind of Java library is that you're porting? By the way, in my D/Objective-C bridge, I'm using the root Object class in D as an equivalent to to the Objective-C id type, and it allows any D object to be passed to Objective-C code. <http://michelf.com/projects/d-objc-bridge/>
Aug 11 2008