www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1621] New: cannot access string member in const method

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1621

           Summary: cannot access string member in const method
           Product: D
           Version: 2.006
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: i.kasiuk gmx.de


Maybe I just don't understand const and invariant properly. But I wonder why
the following code doesn't compile:

class A {
    string s;
    const string f() { return s; }
}

The error message is:

test.d(3): Error: cannot implicitly convert expression (this.s) of type const
char[] to invariant(char)[]


Why does it state that s is of type const char[]? Shouldn't it be const
invariant(char)[]?

Replacing "return s;" by "return cast(string) s;" fixes the compilation error.
But why do I have to cast s to its own type?

The compilation error also disappears if the method is invariant instead of
const.


-- 
Oct 28 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1621






This seems to be fixed in DMD 2.007.


-- 
Nov 23 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1621


i.kasiuk gmx.de changed:

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





fixed in >=2.007


-- 
Mar 01 2008