Contextual return types for expression-bodied members #16044

Closed
SLaks opened this Issue Dec 21, 2016 · 7 comments

Comments

Projects
None yet
6 participants
@SLaks
Contributor

SLaks commented Dec 21, 2016

class C {
	partial A => new partial();
	async B => new async();
}

class partial {}
class async {}

The first line compiles; the second one does not.

Why not?
Why is async different from partial?

http://tryroslyn.azurewebsites.net/#b:master/f:>ilr/MYGwhgzhAEDC0G8BQBIADmATgFwJZhGgEFoBeAPmgDsBTAd2gx3xAAoBKAblUgE8rg0AEJlKtBnwEduAXyRJQkGEzwFEcxVGiTBCGUA=

@DavidArno

This comment has been minimized.

Show comment
Hide comment
@DavidArno

DavidArno Dec 21, 2016

async is in scope as a keyword in this example as it could be the start of an async B F( ... method declaration.

DavidArno commented Dec 21, 2016

async is in scope as a keyword in this example as it could be the start of an async B F( ... method declaration.

@alrz

This comment has been minimized.

Show comment
Hide comment
@alrz

alrz Dec 21, 2016

Contributor

@DavidArno So is partial in partial methods. Note that it will compile in other cases,

async M() => new async();
async M { get => new async(); }
Contributor

alrz commented Dec 21, 2016

@DavidArno So is partial in partial methods. Note that it will compile in other cases,

async M() => new async();
async M { get => new async(); }
@DavidArno

This comment has been minimized.

Show comment
Hide comment
@DavidArno

DavidArno Dec 21, 2016

Oh, I forgot about partial methods. In that case it does indeed appear to be a parser inconsistency issue.

Oh, I forgot about partial methods. In that case it does indeed appear to be a parser inconsistency issue.

@gafter gafter added this to the 2.1 milestone Dec 21, 2016

@gafter

This comment has been minimized.

Show comment
Hide comment
@gafter

gafter Dec 21, 2016

Member

partial is a contextual keyword. The context is that the following token must be class, struct, or void.

async is a contextual keyword. It is treated as a keyword when it appears in a position that could be a member modifier.

They are different because they are specified to be different.

Member

gafter commented Dec 21, 2016

partial is a contextual keyword. The context is that the following token must be class, struct, or void.

async is a contextual keyword. It is treated as a keyword when it appears in a position that could be a member modifier.

They are different because they are specified to be different.

@gafter

This comment has been minimized.

Show comment
Hide comment
@gafter

gafter Dec 21, 2016

Member

The spec does say, however

contextual keywords can conflict with declared names. In such cases, the declared name takes precedence over the use of the identifier as a contextual keyword.

Member

gafter commented Dec 21, 2016

The spec does say, however

contextual keywords can conflict with declared names. In such cases, the declared name takes precedence over the use of the identifier as a contextual keyword.

@jcouv

This comment has been minimized.

Show comment
Hide comment
@jcouv

jcouv Apr 5, 2018

Member

Fix is in for 15.7 preview 4.

Member

jcouv commented Apr 5, 2018

Fix is in for 15.7 preview 4.

@jcouv jcouv closed this Apr 5, 2018

@jcouv

This comment has been minimized.

Show comment
Hide comment
@jcouv

jcouv Apr 5, 2018

Member

Thanks @alrz for the fix!

Member

jcouv commented Apr 5, 2018

Thanks @alrz for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment