Thread overview
[Issue 1412] New: stringof shouldn't be shadowed by member func
Aug 11, 2007
d-bugmail
Aug 11, 2007
d-bugmail
Aug 11, 2007
d-bugmail
Aug 12, 2007
d-bugmail
May 12, 2008
d-bugmail
May 27, 2008
d-bugmail
August 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1412

           Summary: stringof shouldn't be shadowed by member func
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: davidl@126.com


import std.stdio;
struct k
{
        char[] stringof()
        {
                return "mystringof";
        }
}
void main()
{
        k v;
        writefln(v.stringof);
}


-- 

August 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1412


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from bugzilla@digitalmars.com  2007-08-11 12:36 -------
The builtin properties can be overridden by the user if he desires. This is working as designed.


-- 

August 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1412


davidl@126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #2 from davidl@126.com  2007-08-11 18:38 -------
this design would break generic programing. Consider if users are not aware of this design feature, they use stringof as their private internal use?

And I still don't know why a user want to overload stringof? For me, overloading these builtin properties could only be inconsistent


-- 

August 12, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1412


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID




------- Comment #3 from bugzilla@digitalmars.com  2007-08-11 19:00 -------
It's designed this way so the class designer can customize what the properties do.


-- 

May 12, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1412


davidl@126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #4 from davidl@126.com  2008-05-11 20:59 -------
i will appreciate that a warning or a explicit override const keyword?

struct k
{
        override const char[] stringof() // for overloading the stringof
builtin prop,users have to use "override const" keyword explicitly?
        {
                return "mystringof";
        }
}

or the compiler emits a warning will be nice also


-- 

May 27, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1412


brunodomedeiros+bugz@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |brunodomedeiros+bugz@gmail.c
                   |                            |om




------- Comment #5 from brunodomedeiros+bugz@gmail.com  2008-05-27 17:29 -------
But unlike "init" or others, stringof is not a real property, nor anything like
it. It is a special, meta-programming construct that has a syntax like a
property, but behaves quite differently from a property, due to the fact that
the stringof expression is never evaluated. For example such expression:
  (new Foo()).stringof
does not create a new Foo.
That alone shows the difference in semantics. It's not even possible to define
a custom stringof property that behaves like the original stringof!
So the language should not allow "redefining" the stringof property. It should
be the same as sizeof, which cannot be redefined (and also does not evaluate
it's expression).

(One could also suggest that a free function syntax, ie: "sizeof(new A())",
should be allowed, and maybe even prefered)


--