D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6696 - Error messages for const/immutable arrays given to immutable/const
Summary: Error messages for const/immutable arrays given to immutable/const
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 minor
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-09-19 14:52 UTC by bearophile_hugs
Modified: 2012-10-20 18:18 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-09-19 14:52:47 UTC
A wrong D2 program:

void foo(immutable ref int[5] a) {}
void bar(const ref int[5] a) {}
void main() {
    const int[5] arr1;
    foo(arr1); // line 5
    immutable int[5] arr2;
    bar(arr2); // line 7
}


DMD 2.055 prints:

test.d(5): Error: function test.foo (ref immutable immutable(int[5u]) a) is not callable using argument types (const(int[5u]))
test.d(5): Error: cast(immutable(int[5u]))arr1 is not an lvalue
test.d(7): Error: cast(const(int[5u]))arr2 is not an lvalue

The first error message is almost good, but why does it print "immutable immutable"?

I think the second error message is useless.

In line 7 the bar(arr2) call gives just a "arr2 is not an lvalue" that I think is not good enough.


So for this program I think a better error message printout is something like:

test.d(5): Error: function test.foo(ref immutable(int[5]) a) is not callable using argument types (const(int[5])).
test.d(7): Error: function test.foo(ref const(int[5]) a) is not callable using argument types (immutable(int[5])).
Comment 1 Andrej Mitrovic 2012-10-20 18:18:39 UTC
Only error now is:

Error: function test.foo (ref immutable(int[5u]) a) is not callable using argument types (const(int[5u]))

line 7 is now allowed apparently.