dotnet / dotnet/csharpstandard

7.2.5 Deviations from grammar ambiguities

Open
#91 3 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

> If a sequence of tokens can be parsed (in context) as a _simple-name_ (§12.7.3), _member-access_ (§12.7.5), or _pointer-member-access_ (§23.6.3) ending with a _type-argument-list_ (§9.4.2), the token immediately following the closing `>` token is examined. If it is one of
>         `( ) ] : ; , . ? == !=`
> then the _type-argument-list_ is retained as part of the _simple-name_, _member-access_, or _pointer-member-access_ and any other possible parse of the sequence of tokens is discarded. Otherwise, the _type-argument-list_ is not considered part of the _simple-name_, _member-access_, or _pointer-member-access_, even if there is no other possible parse of the sequence of tokens.

In practice, both Roslyn and Mono successfully parse:

``` C#
using System;

class C
{
public static bool operator ^(Action a, C b)
{
return true;
}

void Foo()
{
var x = Foo ^ this;
}
}
```

and

``` C#
using System;

class C
{
public static bool operator |(Action a, C b)
{
return true;
}

void Foo()
{
var x = Foo | this;
}
}
```

Mono also allows other operators (although Roslyn rejects them):

``` C#
using System;

class C
{
public static bool operator +(Action a, C b)
{
return true;
}

void Foo()
{
var x = Foo + this;
}
}
```

Should we update the spec, or just leave these as implementation quirks?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.