www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1412] New: stringof shouldn't be shadowed by member func

reply d-bugmail puremagic.com writes:
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);
}


-- 
Aug 11 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1412


bugzilla digitalmars.com changed:

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





The builtin properties can be overridden by the user if he desires. This is
working as designed.


-- 
Aug 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1412


davidl 126.com changed:

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





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


-- 
Aug 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1412


bugzilla digitalmars.com changed:

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





It's designed this way so the class designer can customize what the properties
do.


-- 
Aug 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
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                     |





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 11 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1412


brunodomedeiros+bugz gmail.com changed:

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





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)


-- 
May 27 2008