[Issue 1621] New: cannot access string member in const method
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Oct 28 10:34:45 PDT 2007
    
    
  
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 at digitalmars.com
        ReportedBy: i.kasiuk at 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.
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list