delegate passed in annotation struct cannot be invoked.
Stefan Koch via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 29 13:07:00 PST 2016
On Thursday, 29 December 2016 at 20:55:43 UTC, Alexandru Ermicioi
wrote:
> Given code below:
> import std.stdio;
>
> struct Annotation {
> public int delegate(int) dg;
> }
>
> void main() {
> import std.traits;
>
> __traits(getAttributes, Cls)[0].dg(20).writeln;
> }
>
> @Annotation(delegate int(int d) {
> return d;
> })
> class Cls {
>
> void method() {
>
> }
> }
>
> Dmd will complain with following statement for the delegate
> passed in annotation:
> src/app.d(13,13): Error: delegate app.__dgliteral6 is a nested
> function and cannot be accessed from D main.
>
> GDC will just throw internal compiler exception:
> src/app.d: In function ‘D main’:
> src/app.d:20:2: internal compiler error: in
> get_frame_for_symbol, at d/d-codegen.cc:3981
> __traits(getAttributes, Cls)[0].dg(20).writeln;
> ^
>
> LDC will not argue, and compile it flawlessly, and return 20 as
> expected.
>
> So the question, is the dmd error correct behavior?
> If so, how the delegate is nested, and what is context that it
> is nested in?
>
> DMD version is: v2.072.1
> LDC version is: v1.1.0 based on v2.071.2 and LLVM 3.8.1
> GDC version is: 6.2.1 20161215
It's a delegate and not function.
Therefore it will get a frame-ptr regardless, without checking if
it is needed or not, or if there is a frame to point to.
Since there is no frame to point to you get the error.
At least this is my guess.
Make the delegate a function and the error should disappear.
More information about the Digitalmars-d-learn
mailing list