Issue 24229 - Parser accepts fundamental types as primary expressions without dot identifier
Summary: Parser accepts fundamental types as primary expressions without dot identifier
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2023-11-05 19:46 UTC by basile-z
Modified: 2024-11-09 10:24 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 basile-z 2023-11-05 19:46:02 UTC
The rule for having a type like int, char, etc. as expression is, according to https://dlang.org/spec/expression.html#primary_expressions

```ebnf
FundamentalType "." Identifier
```

so the following code should not parse

```d
ubyte[] v()
{
    ubyte[] buffer;
    buffer ~= char; // here the rhs
    return buffer;
}

enum ubyte a = v()[0];       
```

but instead it does and ends up with a semantic-time error.
Comment 1 Nick Treleaven 2024-11-08 15:41:57 UTC
> instead it does and ends up with a semantic-time error

Is that a problem? That was intentional to fix issue 9848. Though that also meant things like this work:

alias T = int;
pragma(msg, int[T]);

Before dmd 2.102 that was a parse error.
Comment 2 basile-z 2024-11-09 10:24:32 UTC
It's not a problem but the specs need to be updated.