Const struct assign error messages

bearophile bearophileHUGS at lycos.com
Fri Mar 4 15:19:22 PST 2011


This is a little wrong D2 program:


void bar(const int data) {
    auto d = data;
    d = data;
}
void main() {}


With the error message DMD gives it's easy to understand the error and fix it:
test.d(3): Error: variable test.bar.d cannot modify const


This is a similar program that uses a Tuple instead of an int:

import std.typecons;
alias Tuple!(int) Foo;
void bar(const Foo data) {
    auto d = data;
    d = data;
}
void main() {}


But now the errors given are not so easy to understand:
test.d(5): Error: template std.typecons.Tuple!(int).Tuple.opAssign(R) if (isTuple!(R)) does not match any function template declaration
test.d(5): Error: template std.typecons.Tuple!(int).Tuple.opAssign(R) if (isTuple!(R)) cannot deduce template function from argument types !()(const(Tuple!(int)))


Being that "d" a const Foo struct, that you can never be assigned to, can't DMD give a nicer error message, like in the first program?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list