Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Object initializers do not allow fieldlike events #4694

Closed
gafter opened this issue Aug 20, 2015 · 1 comment
Closed

Object initializers do not allow fieldlike events #4694

gafter opened this issue Aug 20, 2015 · 1 comment

Comments

@gafter
Copy link
Member

gafter commented Aug 20, 2015

Reproduce using the following test (already in Roslyn, but Skipped)

[Fact]
public void ObjectInitializerFieldlikeEvent()
{
var source = @"
public delegate void D();
public struct MemberInitializerTest
{
public event D z;
public static void Main()
{
var i = new MemberInitializerTest() { z = null };
}
}";
var compVerifier = CompileAndVerify(source, expectedOutput: "");
}

EXPECTED: test passes

ACTUAL:
error CS1913: Member 'z' cannot be initialized. It is not a field or property.

Migrated from TFS/DevDiv 529272

@gafter
Copy link
Member Author

gafter commented Mar 20, 2017

According to the spec

An object initializer consists of a sequence of member initializers, enclosed by { and } tokens and separated by commas. Each member_initializer designates a target for the initialization. An identifier must name an accessible field or property of the object being initialized

As you can see, fieldlike events are not supported by the language spec.

We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages.

If you are still interested in this issue (I note that there have been zero comments since its initial posting), please open an issue on the appropriate repo.

See also #18002 for a general discussion of closing and/or moving language issues out of this repo.

@gafter gafter closed this as completed Mar 20, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants