www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6553] New: Better const(char[]) !-> string error message

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

           Summary: Better const(char[]) !-> string error message
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is related to bug 5081 , see there for more context.


I think the behaviours shown by this little program are correct, but I think
that error message needs to be improved (completed with more details), because
in some cases (like foo1) that's an acceptable operation (dmd 2.055 head):


string foo1() pure {
    const(char[]) s2 = ['a'];
    return s2;
}
string foo2() pure {
    return ['a'];
}
string foo3(immutable char[] s) pure {
    return s;
}
string foo4(in char[] s1, immutable char[] s2) pure {
    return s2;
}
string foo5(in char[] s) pure {
    return s; // Error: cannot implicitly convert expression (s) of type
const(char[]) to string
}
void main() {
    immutable r1 = foo1();             // OK
    immutable r2 = foo2();             // OK
    immutable r3 = foo3(['a']);        // OK
    immutable r4 = foo4(['a'], ['b']); // OK
    immutable r5 = foo5(['a']);        // Error
}


Good and complete error messages are needed to help the programmer understand
her mistake and build a correct model of D semantics in her head.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 24 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6553


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



17:52:42 PST ---
All of these compile in 2.061. Got any other test-cases or should we close?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6553





 All of these compile in 2.061. Got any other test-cases or should we close?
Wait, the conversion in foo5 should fail correctly. If it is allowed, following code will accidentally break const-correctness. void main() { char[] buf = ['a']; immutable str = foo5(buf); assert(str[0] == 'a'); buf[0] = 'b'; assert(str[0] == 'a'); // fails!? } And this code compiles without errors in current git head. I think this is a regression. Will open a new issue. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 27 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6553





 I think this is a regression. Will open a new issue.
Opened: Issue 9230 - Incorrect implicit immutable conversion occurs in pure function -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 27 2012