Bug 2506 – Can't initialize const member in ctor if it is accessed via this.member syntax
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-12-10T14:16:00Z
Last change time
2015-06-09T01:20:25Z
Keywords
diagnostic, rejects-valid
Assigned to
bugzilla
Creator
2korden
Comments
Comment #0 by 2korden — 2008-12-10T14:16:48Z
struct Integer
{
this(int i)
{
this.i = i; // fails: Error: this.i is not mutable
}
// this(int ii)
// {
// i = ii; // ok, but I want member and argument names to match
// }
const int i;
}
Comment #1 by gide — 2008-12-11T03:54:48Z
Both ctors do not compile in DMD 2.021. Also the error message doesn't have a line number, added diagnostic to keywords.
struct Integer {
this(int ii) {
i = ii; // Error: this is not mutable
}
const int i;
}
Comment #2 by 2korden — 2008-12-11T20:59:45Z
The bug was reported against DMD2.020 and it latter example *does* successfully compile. Must be a regression.