Enums with Inline Subclass
mark_mcs
mark at mnetcs.com
Wed Nov 13 20:46:25 UTC 2019
I spend most of my time in java land but try to sneak in some D
code whenever possible. One pattern that comes in handy is to use
Java enums as states in a finite state machine (good for XML
parsers). Given that D supports enums with custom base types, I
was curious to see if this pattern would translate.
The code looks like this:
interface A
{
void process();
}
enum Test : A
{
Value1 = new class A {
override void process() { writeln("Value1"); }
},
Value2 = new class A {
override void process() { writeln("Value2"); }
}
}
void main()
{
Test.Value1.process();
}
It's syntactically valid but you get linker errors. Seems the
compiler doesn't generate the vtable for the inline classes:
undefined reference to `_D3app4Test12__anonclass16__vtblZ'
undefined reference to `_D3app4Test12__anonclass17__ClassZ
My question is: should this be possible? Is this a grammar bug or
a codegen bug?
More information about the Digitalmars-d
mailing list