[Issue 10487] New: Bad error message with assignment of const tuple
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 27 04:54:30 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10487
Summary: Bad error message with assignment of const tuple
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: diagnostic
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2013-06-27 04:54:28 PDT ---
I tag this as enhancement request, but it's borderline with being a bug report.
This is a common programming mistake in D; using "auto" y becomes "const int"
and not just an int, so later you can't assign to it the result of bar():
int bar() {
return 0;
}
void spam(in int x) {
auto y = x;
// ...
y = bar();
}
void main() {}
The error message is quite clear and easy to understand:
test.d(7): Error: cannot modify const expression y
But if I replace the type int with a Tuple:
import std.typecons: Tuple;
alias Foo = Tuple!int;
Foo bar() {
return Foo();
}
void spam(in Foo x) {
auto y = x;
// ...
y = bar();
}
void main() {}
DMD 2.064alpha gives me:
test.d(9): Error: template std.typecons.Tuple!int.Tuple.opAssign does not match
any function template declaration. Candidates are:
...\dmd2\src\phobos\std\typecons.d(504):
std.typecons.Tuple!int.Tuple.opAssign(R)(auto ref R rhs) if
(areCompatibleTuples!(typeof(this), R, "="))
test.d(9): Error: template std.typecons.Tuple!int.Tuple.opAssign(R)(auto ref R
rhs) if (areCompatibleTuples!(typeof(this), R, "=")) cannot deduce template
function from argument types !()(Tuple!int)
The error messages are too much long, and they don't even talk about const
tuples.
I think those error messages should be improved.
I expect future built-in D tuples to give an error message like the int case:
test.d(7): Error: cannot modify const expression y
--
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