Voldemort structs no longer work?

Iain Buclaw ibuclaw at ubuntu.com
Sat Dec 15 10:50:34 PST 2012


On Saturday, 15 December 2012 at 18:38:29 UTC, H. S. Teoh wrote:
> With latest git dmd:
>
> 	auto makeVoldemort(int x) {
> 		struct Voldemort {
> 			@property int value() { return x; }
> 		}
> 		return Voldemort();
> 	}
> 	void main() {
> 		auto v = makeVoldemort();
> 		writeln(v.value);
> 	}
>
> Compile error:
>
> 	test.d(3): Error: function test.makeVoldemort.Voldemort.value 
> cannot access frame of function test.makeVoldemort
>
> Changing 'struct' to 'class' works. Is this deliberate, or is 
> it a bug?
> It is certainly inconsistent with Walter's article on Voldemort 
> types,
> which uses structs as examples.
>
>
> T

Pretty certain it's deliberate.  No closure is created for nested 
structs to access it's parent, complying with it's POD behaviour.

Regards,
Iain.


More information about the Digitalmars-d mailing list