dotnet/roslyn

EnC does not work in init accessors

Aperta

#48.632 aperta il 15 ott 2020

 (2 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-InteractiveConcept-Continuous Improvementhelp wanted

Metriche repository

Star
 (20.414 stelle)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

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.

Guida contributor