Bug 9048 – Error: base classes expected instead of typeof when instantiating anonymous class
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-11-19T15:18:00Z
Last change time
2012-11-20T19:48:17Z
Assigned to
nobody
Creator
ogondza
Comments
Comment #0 by ogondza — 2012-11-19T15:18:45Z
Unlike, regular classes, anonymous classes seems to be impossible to instantiate when using typeof expression.
This works perfectly:
new typeof(this)();
new typeof(new Object())();
But these
new class typeof(this) {};
new class typeof(new Object()) {};
give (on v2.060)
Error: base classes expected instead of typeof
Error: { members } expected for anonymous class
Error: found 'typeof' when expecting ';' following statement
It can be worked around aliasing the type first and then instantiating anonymous class of the aliased type. However, for an anonymous class it is necessary to instantiate in one expression.
Comment #1 by timon.gehr — 2012-11-19T15:35:51Z
It is according to the language specification. It is the same parsing error as the one present in the following code:
class C{}
class D: typeof(new C){}
This is an enhancement.
Comment #2 by k.hara.pg — 2012-11-20T19:48:17Z
(In reply to comment #0)
> new class typeof(this) {};
> new class typeof(new Object()) {};
Using typeof in base class list is allowed in 2.061head, by fixing issue 1353.
*** This issue has been marked as a duplicate of issue 1353 ***