D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7853 - Almost useless error message related to postblit with AA of const struct
Summary: Almost useless error message related to postblit with AA of const struct
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 minor
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2012-04-07 17:15 UTC by Christopher Nicholson-Sauls
Modified: 2013-11-16 22:49 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 Christopher Nicholson-Sauls 2012-04-07 17:15:16 UTC
Given the code:

----------
module bug;

struct S { this ( this ) {} }
struct Z { const( S )[ int ] broken; }
void main () {
	foreach ( i,x ; Z().broken ) {}
}
----------

The compiler correctly errors, but does not provide enough information in the error message:
> bug.d(3): Error: function bug.S.__postblit () is not callable using argument types ()
> Error: *&this is not mutable
> Error: this is not mutable
> Error: this is not mutable

While correct, it does not reference the line with the foreach, which is what triggers the problematic postblit.  The fix is obvious: redefine postblit as this(const this); but it isn't always obvious when looking at hundreds of lines of code.  I know, because I just dealt with it myself, and spent at least an hour figuring out what was triggering it so I could decide whether the fix was appropriate.

Maybe all postblits should be this(const this) in the first place?