class grammar

Adam D. Ruppe destructionator at gmail.com
Fri May 7 18:28:29 UTC 2021


On Friday, 7 May 2021 at 18:07:45 UTC, Nick wrote:
> The class grammar, as defined in the D language specification 
> ([Classes](https://dlang.org/spec/grammar.html#classes)), seems 
> to imply that a class can inherit from a fundamental type. 
> Explicitly, the specification says that a 'SuperClass' is a 
> 'BasicType'. And a 'FundamentalType' is a 'BasicType'.

I think the grammar allows it to parse, but then defers the error 
till later.

There's a lot of things that are too generic for the parser to 
reject, but don't match the semantics later.

Like it the grammar only allowed a ClassOrInterface... it'd have 
to know what `X` is before it is parsed which is problematic.

> Error: class `test.A` base type must be `class` or `interface`, 
> not `int`

Notice that this is not a parse error, but rather a semantic 
check later on, which is consistent with that grammar.

The parser accepts it, then later on, a future pass of the 
compiler resolves what the word actually means and then says 
"wait a bit that is a sentence sure, but it doesn't actually make 
sense".


More information about the Digitalmars-d-learn mailing list