delegate passed in annotation struct cannot be invoked.
Alexandru Ermicioi via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 29 12:55:43 PST 2016
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
More information about the Digitalmars-d-learn
mailing list