Bug 2610 – const/invariant(immutable) class don't have constructor
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-01-24T01:03:00Z
Last change time
2015-06-09T01:21:02Z
Keywords
rejects-valid
Assigned to
nobody
Creator
rayerd.wiz
Comments
Comment #0 by rayerd.wiz — 2009-01-24T01:03:42Z
>type a.d
immutable class A {
string s;
this() {// error
s = "hoge";
}
}
>dmd a
Error: cannot implicitly convert expression (this) of type immutable(A) to a.A
Comment #1 by nfxjfg — 2010-05-18T11:22:08Z
You closed this bug as fixed, but what was the resolution?
Comment #2 by bearophile_hugs — 2010-05-18T11:53:01Z
This code compiles and runs fine on dmd v.2.046.
immutable class A {
string s;
this() {
s = "hoge";
}
}
void main() {
A a = new A;
}
Comment #3 by rayerd.wiz — 2010-05-18T19:59:09Z
(In reply to comment #1)
> You closed this bug as fixed, but what was the resolution?
Sorry. I should have written a reason.
(In reply to comment #2)
> This code compiles and runs fine on dmd v.2.046.
>
> immutable class A {
> string s;
> this() {
> s = "hoge";
> }
> }
> void main() {
> A a = new A;
> }
Thanks!