Bug 9162 – [tdpl] Non-static structs should have access to outer lexical scope
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-15T11:40:00Z
Last change time
2012-12-17T00:03:42Z
Keywords
pull, rejects-valid, TDPL
Assigned to
nobody
Creator
hsteoh
Comments
Comment #0 by hsteoh — 2012-12-15T11:40:31Z
The following is adapted from Walter's "Voldemort Types" article:
import std.stdio;
auto makeVoldemort(int x) {
struct Voldemort {
@property int value() { return x; }
// Compile error:
}
return Voldemort();
}
void main() {
auto v = makeVoldemort(123);
writeln(v.value);
}
Compiler output:
test.d(5): Error: function test.makeVoldemort.Voldemort.value cannot access frame of function test.makeVoldemort
According to TDPL, ยง7.1.9 (p.263): <quote>Nested structs embed the magic "frame pointer" that allows them to access outer values such as a and b in the example above."</quote>
Comment #1 by hsteoh — 2012-12-15T11:48:42Z
Also from that paragraph in TDPL:
"If you want to define a nested struct without that baggage, just prefix struct with static in the definition of Local, which makes Local a regular struct and consequently prevents it from accessing a and b."
Comment #2 by bugzilla — 2012-12-15T14:51:29Z
This fails:
auto makeVoldemort(int x) {
struct Voldemort {
@property int value() { return x; }
}
return Voldemort();
}
This works:
auto makeVoldemort(int x) {
struct Voldemort {
int value() { return x; }
}
return Voldemort();
}
So it's a problem with @property.
Comment #3 by js.mdnq — 2012-12-15T23:43:35Z
When using a normal method instead of a property I then get the error: "Internal Error: ..\ztc\cod2.c 4727" on release build. Debug build does not return this error. 2.060.
Comment #4 by bugzilla — 2012-12-16T01:07:31Z
(In reply to comment #3)
> When using a normal method instead of a property I then get the error:
> "Internal Error: ..\ztc\cod2.c 4727" on release build. Debug build does not
> return this error. 2.060.
Current head does not return errors on normal method.