digitalmars.D - BUG?
- Tomás Rossi (54/54) Oct 31 2005 With the latest DMD compiler for Windows this is what happens:
- Derek Parnell (15/82) Oct 31 2005 The main problem is that you need to remove the ambiguous references.
- Regan Heath (10/90) Nov 01 2005 In addition, the style guide:
- Tomás Rossi (15/97) Nov 01 2005 This is fine but, i've missed to mention the real problem (sorry):
- Derek Parnell (11/14) Nov 01 2005 My guess is when DMD sees "Person!(int)", it interprets "Person" as the
- John C (9/65) Nov 01 2005 The recommendation is to use lower case module names.
With the latest DMD compiler for Windows this is what happens: --in file Person.d-- module Person; private import std.string; alias char[] string; class Person(T) { protected: uint m_age; string m_name; T m_other_property; public: // Default constructor. this(string name, uint age) { m_name = name; m_age = age; } string toString() { return m_name ~": "~ .toString(m_age) ~","~ toString(m_other_property); } } --in file test1.d-- private import std.stdio, std.process; import Person; int main() { int ret_code; try { Person!(int) new_person = new Person!(int)("George", 16); writefln(new_person.toString()); } catch (Exception ex) { writefln("Unknown Exception: %s", ex.toString()); ret_code = 1; } finally { std.process.system("pause"); } return ret_code; } DMD throws: ERROR(9): template instance Person is not a template declaration, it is a import ERROR(9): Person!(int) used as a type .. etc ... If i comment the "import Person;" and copy-paste the class code into the main file, everything compiles fine. I don't understand why?!?! Tom
Oct 31 2005
On Tue, 1 Nov 2005 04:58:56 +0000 (UTC), Tomás Rossi wrote:With the latest DMD compiler for Windows this is what happens: --in file Person.d-- module Person; private import std.string; alias char[] string; class Person(T) { protected: uint m_age; string m_name; T m_other_property; public: // Default constructor. this(string name, uint age) { m_name = name; m_age = age; } string toString() { return m_name ~": "~ .toString(m_age) ~","~ toString(m_other_property); } } --in file test1.d-- private import std.stdio, std.process; import Person; int main() { int ret_code; try { Person!(int) new_person = new Person!(int)("George", 16); writefln(new_person.toString()); } catch (Exception ex) { writefln("Unknown Exception: %s", ex.toString()); ret_code = 1; } finally { std.process.system("pause"); } return ret_code; } DMD throws: ERROR(9): template instance Person is not a template declaration, it is a import ERROR(9): Person!(int) used as a type .. etc ... If i comment the "import Person;" and copy-paste the class code into the main file, everything compiles fine. I don't understand why?!?! TomThe main problem is that you need to remove the ambiguous references. There are two issues. (1) In Person.d change the toString() to this ... string toString() { return m_name ~": "~ .toString(m_age) ~","~ std.string.toString(m_other_property); } (2) In test1.d change the declaration to ... Person.Person!(int) new_person = new Person.Person!(int)("George", 16); -- Derek Parnell Melbourne, Australia 1/11/2005 6:37:58 PM
Oct 31 2005
On Tue, 1 Nov 2005 18:41:02 +1100, Derek Parnell <derek psych.ward> wrote:On Tue, 1 Nov 2005 04:58:56 +0000 (UTC), Tomás Rossi wrote:In addition, the style guide: http://www.digitalmars.com/d/dstyle.html would have you change: "Person.d" to "person.d" "module Person" to "module person" "import Person" to "import person" ..etc.. This would have prevented the ambiguous references from occuring. ReganWith the latest DMD compiler for Windows this is what happens: --in file Person.d-- module Person; private import std.string; alias char[] string; class Person(T) { protected: uint m_age; string m_name; T m_other_property; public: // Default constructor. this(string name, uint age) { m_name = name; m_age = age; } string toString() { return m_name ~": "~ .toString(m_age) ~","~ toString(m_other_property); } } --in file test1.d-- private import std.stdio, std.process; import Person; int main() { int ret_code; try { Person!(int) new_person = new Person!(int)("George", 16); writefln(new_person.toString()); } catch (Exception ex) { writefln("Unknown Exception: %s", ex.toString()); ret_code = 1; } finally { std.process.system("pause"); } return ret_code; } DMD throws: ERROR(9): template instance Person is not a template declaration, it is a import ERROR(9): Person!(int) used as a type .. etc ... If i comment the "import Person;" and copy-paste the class code into the main file, everything compiles fine. I don't understand why?!?! TomThe main problem is that you need to remove the ambiguous references. There are two issues. (1) In Person.d change the toString() to this ... string toString() { return m_name ~": "~ .toString(m_age) ~","~ std.string.toString(m_other_property); } (2) In test1.d change the declaration to ... Person.Person!(int) new_person = new Person.Person!(int)("George", 16);
Nov 01 2005
In article <1t0aqb9bev97m$.1btnl6miit6v4$.dlg 40tude.net>, Derek Parnell says...On Tue, 1 Nov 2005 04:58:56 +0000 (UTC), Tomás Rossi wrote:OK, this was a cpoy paste mistake, since in my code i had it .toString(...blah)With the latest DMD compiler for Windows this is what happens: --in file Person.d-- module Person; private import std.string; alias char[] string; class Person(T) { protected: uint m_age; string m_name; T m_other_property; public: // Default constructor. this(string name, uint age) { m_name = name; m_age = age; } string toString() { return m_name ~": "~ .toString(m_age) ~","~ toString(m_other_property); } } --in file test1.d-- private import std.stdio, std.process; import Person; int main() { int ret_code; try { Person!(int) new_person = new Person!(int)("George", 16); writefln(new_person.toString()); } catch (Exception ex) { writefln("Unknown Exception: %s", ex.toString()); ret_code = 1; } finally { std.process.system("pause"); } return ret_code; } DMD throws: ERROR(9): template instance Person is not a template declaration, it is a import ERROR(9): Person!(int) used as a type .. etc ... If i comment the "import Person;" and copy-paste the class code into the main file, everything compiles fine. I don't understand why?!?! TomThe main problem is that you need to remove the ambiguous references. There are two issues. (1) In Person.d change the toString() to this ... string toString() { return m_name ~": "~ .toString(m_age) ~","~ std.string.toString(m_other_property); }(2) In test1.d change the declaration to ... Person.Person!(int) new_person = new Person.Person!(int)("George", 16);This is fine but, i've missed to mention the real problem (sorry): If I remove al the generic (template) things for example: class Person(T) --> class Person remove the T member and the toString of T member. and i instantiate like this: Person new_person = new Person("George", 16); Everything goes just fine. There are no Module-Class ambiguity (the class remains still in Person.d module). Summarizing, the same code but with a template parameter goes to compiler errors and when removing the template parameter (and all the related code to T), the error just come into light. Why?-- Derek Parnell Melbourne, Australia 1/11/2005 6:37:58 PMTom SFME (Sorry for my English)
Nov 01 2005
On Tue, 1 Nov 2005 10:52:57 +0000 (UTC), Tomás Rossi wrote: [snip]Summarizing, the same code but with a template parameter goes to compiler errors and when removing the template parameter (and all the related code to T), the error just come into light. Why?My guess is when DMD sees "Person!(int)", it interprets "Person" as the module name and wonders why you are trying to use the template instantiation syntax on the module. Thus when you remove that stuff, it goes to another level of analysis and corrects the interpretation of "Person" to a class name and now it works. -- Derek Parnell Melbourne, Australia 2/11/2005 12:00:53 AM
Nov 01 2005
"Tomás Rossi" <Tomás_member pathlink.com> wrote in message news:dk6smg$2b64$1 digitaldaemon.com...With the latest DMD compiler for Windows this is what happens: --in file Person.d-- module Person;The recommendation is to use lower case module names.private import std.string; alias char[] string; class Person(T) { protected: uint m_age; string m_name; T m_other_property; public: // Default constructor. this(string name, uint age) { m_name = name; m_age = age; } string toString() { return m_name ~": "~ .toString(m_age) ~","~ toString(m_other_property); } }D sees 'toString(m_other_property)' as being ambiguous (it tries to match your Person's toString). Just use the global scope operator as you did with '.toString(m_age)'.--in file test1.d-- private import std.stdio, std.process; import Person; int main() { int ret_code; try { Person!(int) new_person = new Person!(int)("George", 16); writefln(new_person.toString()); } catch (Exception ex) { writefln("Unknown Exception: %s", ex.toString()); ret_code = 1; } finally { std.process.system("pause"); } return ret_code; } DMD throws: ERROR(9): template instance Person is not a template declaration, it is a import ERROR(9): Person!(int) used as a typeFollow the advise above and it will compile fine. Think of modules as namespaces. In C++, you wouldn't name a namespace "Person" and have a class with the same name... etc ... If i comment the "import Person;" and copy-paste the class code into the main file, everything compiles fine. I don't understand why?!?! Tom
Nov 01 2005