Skip to content

new extension syntax crashes build with certain event syntax #78413

Closed as duplicate of#78042
@valbakhtin

Description

@valbakhtin

VS 2022 Preview 5

Steps to Reproduce:

  1. Create basic console app for .net
  2. set preview for the project
  3. add code:
public static class Program
{
    [STAThread]
    static void Main()
    {
    }
}
public class EventSender
{
    public EventSender(string name) => Name = name;
    public string Name { get; set; }

    public event EventHandler<EventArgs>? Event;
    public void FireEvent() => Event?.Invoke(this, EventArgs.Empty);
}

public static class Extensions
{
    extension(EventSender extendee)
    {
        public void Extend()
        {
            extendee.Event += (s, e) => 
            {
                // V---- not building
                //if (s is EventSender sender)
                //    Console.WriteLine(sender.Name);

                // V---- building
                Console.WriteLine((s as EventSender)?.Name);
            };
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions