dotnet/roslyn

EnC does not work in init accessors

Aberta

#48.632 aberto em 15 de out. de 2020

 (2 comentários) (0 reação) (0 responsável)C# (4.257 forks)batch import
Area-InteractiveConcept-Continuous Improvementhelp wanted

Métricas do repositório

Stars
 (20.414 estrelas)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (256 fundiu PRs em 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.

Guia do colaborador