Bug 3329 – Static constructors not allowed in interfaces
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2009-09-18T07:32:00Z
Last change time
2014-04-18T09:12:04Z
Assigned to
nobody
Creator
dhasenan
Comments
Comment #0 by dhasenan — 2009-09-18T07:32:04Z
Interfaces can have const fields, which are implicitly static. They can have static fields that are not const.
Let's take this example (from ANTLR):
interface Token
{
const int EOF = -1;
static Token EOF_TOKEN;
static this ()
{
EOF_TOKEN = new CommonToken(EOF);
}
}
This produces an error saying that _staticCtor1 is not abstract.
The workaround is to move the static constructor out of the interface. This is not problematic; it is merely inconsistent.
Comment #1 by yebblies — 2011-06-12T14:28:28Z
This compiles successfully: static constructors are now allowed in interfaces (dmd1.068 & dmd2.053)