dotnet/roslyn

Renaming an identifier should undo implicit property naming

オープン

#54,571 opened on 2021/07/02

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-IDEConcept-Continuous ImprovementFeature - Renamehelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

Version Used: Visual Studio Enterprise 2019 Version 16.9.4 C# Tools 3.9.0-6.21160.10+59eedc33d35754759994155ea2f4e1012a9951e3 Steps to Reproduce:

  1. Instantiate an anonymous type with an implicit property name (new { K })
  2. Rename the identifier referenced in the instantiation

Expected Behavior: The instantiation would use the explicit property name instead of implicit property naming, in order to preserve the definition of the anonymous type

Actual Behavior: Implicit property naming is still used, changing the definition of the anonymous type

Example:

int K = 0;
var x = new { K };
int y = x.K;

After renaming K -> Q

int Q = 0;
var x = new { Q };
int y = x.K;               // This is now a compile error

Expected behavior after renaming K -> Q

int Q = 0;
var x = new { K = Q };
int y = x.K;               // This works fine

In this example, the compiler catches the error. But this could result in silent bugs in use cases such as such as MVC where an anonymously typed value can be translated to a JSON response object.

コントリビューターガイド