D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2652 - DeclDef grammar is wrong
Summary: DeclDef grammar is wrong
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL: http://www.digitalmars.com/d/2.0/modu...
Keywords: spec
Depends on: 2651
Blocks:
  Show dependency treegraph
 
Reported: 2009-02-08 22:26 UTC by Jerry Quinn
Modified: 2015-06-09 01:21 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jerry Quinn 2009-02-08 22:26:00 UTC
As described, the DeclDef grammar allows Invariant and UnitTest at module scope.  The compiler only permits them within classes, structs, and unions, which seems more correct to me.  Given that and bug 2651, I think the grammar should be modified as:

Module:
	DeclDefs

DeclDefs:
	DeclDef
	DeclDef DeclDefs

DeclDef:
	AttributeSpecifier
	ImportDeclaration
	EnumDeclaration
	ClassDeclaration
	InterfaceDeclaration
	AggregateDeclaration
	Declaration
	UnitTest
	StaticConstructor
	StaticDestructor
	DebugSpecification
	VersionSpecification
	MixinDeclaration
	;

ClassBodyDeclaration:
	AggregateDeclDef
	Constructor
	Destructor
	ClassAllocator
	ClassDeallocator

StructBodyDeclaration:
	AggregateDeclDef
	StructAllocator
	StructDeallocator
	StructConstructor
	StructPostblit
	StructDestructor

AggregateDeclDef:
	DeclDef
	Invariant
	UnitTest
Comment 1 Derek Parnell 2009-02-08 23:51:05 UTC
Unit tests are correctly permitted at the module level. A unit test can be used to test free functions as well as class/struct methods.
Comment 2 Jerry Quinn 2009-02-09 07:46:23 UTC
(In reply to comment #1)
> Unit tests are correctly permitted at the module level. A unit test can be used
> to test free functions as well as class/struct methods.

Yes, I see that now.  I'm now thinking that to make the distinction in the grammar you need two different versions of AttributeSpecifier - one for module scope that references DeclDef and another for class/struct scope where invariant is allowed.

ClassBodyDeclaration and StructBodyDeclaration still need to reference some kind of DeclDef, though.