dotnet/roslyn

EnC does not work in init accessors

Open

#48,632 opened on Oct 15, 2020

View on GitHub
 (2 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-InteractiveConcept-Continuous Improvementhelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

Version Used:

Version 16.9.0 Preview 1.0 [30614.203.main]

Steps to Reproduce:

During debugging update

class C
{
   public int F { get => 1; init /*breakpoint here*/{ } }

  public static void Main() => new C() { F = 1; }
}

to

class C
{
   public int F { get => 1; init /*breakpoit here*/{ Console.WriteLine(1); } }

  public static void Main() => new C() { F = 1; }
}

and step.

Expected Behavior:

Change applied.

Actual Behavior:

Change not applied.

It should also be possible to change set to init and vice versa if the accessor has an explicit body (i.e. the compiler does not generate backing field). The modifier of the generated backing field is different between set and init (readonly for init) - I believe the runtime does not support updating it, but we should double-check if it's true. If not we can allow changing set to init and vice versa also for auto-props.

Contributor guide