[Issue 5081] Pure functions as initializers for immutable structures
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 24 20:32:04 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5081
--- Comment #5 from bearophile_hugs at eml.cc 2011-08-24 20:31:58 PDT ---
This is a new part of the design of D purity, and a significant improvement for
D usability.
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:
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: -------
More information about the Digitalmars-d-bugs
mailing list