Bug 7853 – Almost useless error message related to postblit with AA of const struct

Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-07T17:15:00Z
Last change time
2013-11-16T22:49:37Z
Keywords
diagnostic
Assigned to
nobody
Creator
ibisbasenji

Comments

Comment #0 by ibisbasenji — 2012-04-07T17:15:16Z
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?