dotnet/roslyn

EnC does not work in init accessors

开放

#48,632 创建于 2020年10月15日

 (2 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-InteractiveConcept-Continuous Improvementhelp wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

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.

贡献者指南