[Issue 12065] New: Some refused implicit string cast in pure methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 2 13:10:55 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12065

           Summary: Some refused implicit string cast in pure methods
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2014-02-02 13:10:52 PST ---
I have tried to understand what's happening here, but I can't tell why some
times it accepts the implicit string cast and other times it doesn't:



import std.string: text;

struct Foo1 {
    char[][] matrix;

    string spam() const pure {
        char[] m = text(matrix).dup;
        return m; // OK
    }
}

struct Foo2 {
    enum Bar : char { A }
    Bar[][] matrix;

    string spam1() const pure {
        return text(matrix).dup; // OK
    }

    string spam2() const pure {
        char[] m = text(matrix).dup;
        return m; // line 22, Error
    }

    char[][] matrix2;

    string spam3() const pure {
        char[] m = text(matrix2).dup;
        return m; // line 29, Error.
    }
}

void main() {}


dmd 2.065.0b2 gives:

test.d(22): Error: cannot implicitly convert expression (m) of type char[] to
string
test.d(29): Error: cannot implicitly convert expression (m) of type char[] to
string


If it's not a compiler bug then I think it's not easy for D newbies to learn
such behaviours.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list