Bug 9256 – A purity-related error message in case of member access
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-01-01T20:55:00Z
Last change time
2013-11-17T03:40:46Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-01-01T20:55:15Z
struct Foo {
int x;
}
void main() pure {
int y = Foo.x;
}
With DMD 2.061 gives this error message:
test.d(5): Error: pure nested function 'main' cannot access mutable data 'x'
But I think a better error message should be something like:
test.d(5): Error: need 'this' to access member x
Comment #1 by bearophile_hugs — 2013-01-01T20:57:36Z
See also:
struct Foo {
int x;
}
void main() pure {
int y = Foo.x.max;
}
test3.d(5): Error: pure nested function 'main' cannot access mutable data 'x'
But I think this problem is elsewhere in Bugzilla.
Comment #2 by yebblies — 2013-11-16T22:09:46Z
Now gives both:
testx.d(5): Error: pure nested function 'main' cannot access mutable data 'x'
testx.d(5): Error: need 'this' for 'x' of type 'int'
Good enough?
Comment #3 by bearophile_hugs — 2013-11-17T03:40:46Z
(In reply to comment #2)
> Now gives both:
>
> testx.d(5): Error: pure nested function 'main' cannot access mutable data 'x'
> testx.d(5): Error: need 'this' for 'x' of type 'int'
>
> Good enough?
It's good enough, issue closed.