Skip to content

Fundamental type with suffix not allowed in expression grammar #4155

@tim-dlang

Description

@tim-dlang

The following expressions are accepted by DMD, but not allowed by the grammar:

const e1 = int*.init;
const e2 = int[1].init;
const e3 = int*[0].init;

The grammar for PrimaryExpression only allows '(' or '.' after FundamentalType:

PrimaryExpression:
    ...
    FundamentalType . Identifier
    ...
    FundamentalType ( NamedArgumentListopt )
    ...

I assume DMD allows these expressions since this PR: dlang/dmd#14672
The parser contains the comment "defer error for better diagnostics", so maybe the new syntax is not allowed intentionally.

The new syntax is used by a test in druntime: https://github.com/dlang/dmd/blob/fb07d990466f185c2adb19d320627c2723d3978a/druntime/src/core/internal/traits.d#L625

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions