Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnC: Renaming a property with initializer doesn't work as expected #69216

Open
tmat opened this issue Jul 25, 2023 · 1 comment · Fixed by #69774
Open

EnC: Renaming a property with initializer doesn't work as expected #69216

tmat opened this issue Jul 25, 2023 · 1 comment · Fixed by #69774

Comments

@tmat
Copy link
Member

tmat commented Jul 25, 2023

Rename property A to B and update it's use in top-level code while not updating C.F.
The property A should be deleted (the getter should throw) but it is not.

Before:

using System;

var c = new C();
Console.WriteLine(c.A);
c.F();

Console.WriteLine();

class C
{
    public int A { get; } = 1;

    public void F()
    {
        Console.WriteLine(A);
    }
}

After:

using System;

var c = new C();
Console.WriteLine(c.B);  // updated use
c.F();

Console.WriteLine();

class C
{
    public int B { get; } = 1;  // renamed

    public void F()
    {
        Console.WriteLine(A);
    }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 25, 2023
@tmat
Copy link
Member Author

tmat commented Jul 25, 2023

The compiler emits get_B even though it's not included in the semantic edits (only the top-level code and ctor are)

Method 'Program.<Main>$' (0x06000005)
  Locals: C (#18b/1:b)
{
  // Code size       32 (0x20)
  .maxstack  1
  IL_0000:  newobj     'C..ctor' (0x06000009)
  IL_0005:  stloc.0
  IL_0006:  ldloc.0
  IL_0007:  callvirt   'C.get_B' (0x0600000e/1:3)
  IL_000c:  call       'System.Console.WriteLine' (0x0a000019/1:3)
  IL_0011:  nop
  IL_0012:  ldloc.0
  IL_0013:  callvirt   'C.F' (0x06000008)
  IL_0018:  nop
  IL_0019:  call       'System.Console.WriteLine' (0x0a00001a/1:4)
  IL_001e:  nop
  IL_001f:  ret
}

Method 'C..ctor' (0x06000009)
{
  // Code size       15 (0xf)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldc.i4.1
  IL_0002:  stfld      '<B>k__BackingField' (0x04000004/1:1)
  IL_0007:  ldarg.0
  IL_0008:  call       'System.Object..ctor' (0x0a00001b/1:5)
  IL_000d:  nop
  IL_000e:  ret
}

Method 'C.get_B' (0x0600000e/1:3)
{
  // Code size        7 (0x7)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldfld      '<B>k__BackingField' (0x04000004/1:1)
  IL_0006:  ret
}

@arkalyanms arkalyanms removed the untriaged Issues and PRs which have not yet been triaged by a lead label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants