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

[release/9.0] Update field references in property accessors #108222

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 25, 2024

Backport of #108219, #108225, and #108413 to release/9.0

Rename or qualify field references in property accessors to avoid conflict with field keyword in C# compiler preview.

With the .NET 9 C# compiler, when compiling with -langversion:preview, field references within property accessors are treated as referring to a synthesized backing field for the property rather than to another symbol named field that may be in scope.

The change here is to rename existing fields and locals to retain the original intent.

/cc @stephentoub @cston

Customer Impact

  • Customer reported
  • Found internally

The issue was found by compiling dotnet/runtime with the updated .NET 9 C# compiler.

No expected customer impact.

Regression

  • Yes
  • No

[If yes, specify when the regression was introduced. Provide the PR or commit if known.]

Testing

[How was the fix verified? How was the issue missed previously? What tests were added?]

Risk

Low risk. The change is a rename of locals and fields only.

IMPORTANT: If this backport is for a servicing release, please verify that:

  • The PR target branch is release/X.0-staging, not release/X.0.

  • If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

@NikolaMilosavljevic
Copy link
Member

@MichalStrehovsky @cston is this ready for review and inclusion in 9.0 release? Does this backport include all changes made in main, in #108219?

Source-build is failing (in stage 2) with the following errors - are all of those fixed with these pending changes: dotnet/source-build#4639

/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs(477,26): warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead. [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs(478,32): warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead. [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs(141,29): warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead. [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs(147,29): warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead. [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs(152,29): warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead. [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs(468,26): warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead. [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs(469,32): warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead. [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs(477,32): error CS1061: 'TypeDesc' does not contain a definition for 'IsStatic' and no accessible extension method 'IsStatic' accepting a first argument of type 'TypeDesc' could be found (are you missing a using directive or an assembly reference?) [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs(478,38): error CS1061: 'TypeDesc' does not contain a definition for 'FieldType' and no accessible extension method 'FieldType' accepting a first argument of type 'TypeDesc' could be found (are you missing a using directive or an assembly reference?) [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs(141,35): error CS1061: 'bool' does not contain a definition for 'IsLiteral' and no accessible extension method 'IsLiteral' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?) [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs(147,35): error CS1061: 'bool' does not contain a definition for 'IsStatic' and no accessible extension method 'IsStatic' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?) [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs(152,29): error CS1929: 'bool' does not contain a definition for 'GetEffectiveVisibility' and the best extension method overload 'EffectiveVisibilityExtensions.GetEffectiveVisibility(EcmaMethod)' requires a receiver of type 'Internal.TypeSystem.Ecma.EcmaMethod' [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs(468,32): error CS1061: 'TypeDesc' does not contain a definition for 'IsStatic' and no accessible extension method 'IsStatic' accepting a first argument of type 'TypeDesc' could be found (are you missing a using directive or an assembly reference?) [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
/vmr/src/runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs(469,38): error CS1061: 'TypeDesc' does not contain a definition for 'FieldType' and no accessible extension method 'FieldType' accepting a first argument of type 'TypeDesc' could be found (are you missing a using directive or an assembly reference?) [/vmr/src/runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj]
    7 Warning(s)
    7 Error(s)

@cston
Copy link
Member

cston commented Sep 30, 2024

@MichalStrehovsky @cston is this ready for review and inclusion in 9.0 release? Does this backport include all changes made in main, in #108219?

Source-build is failing (in stage 2) with the following errors - are all of those fixed with these pending changes: dotnet/source-build#4639

This change should include all the changes from #108219, and it looks like the errors above should be fixed with these changes.

Note, there were some additional errors in main that were not fixed in #108219, but do not appear in the errors above: see follow-up PRs #108225, #108413.

@NikolaMilosavljevic
Copy link
Member

@cston, @stephentoub who owns this backport? This is blocking source-build stage 2 builds and is needed for 9.0 release.

@stephentoub
Copy link
Member

@cston, @stephentoub who owns this backport? This is blocking source-build stage 2 builds and is needed for 9.0 release.

@cston will be updating it with the additional PRs / commits from main.

cston and others added 2 commits October 3, 2024 13:34
* Update field references in property accessors

* Update field references

* Use @

* Rename field

---------

Co-authored-by: Stephen Toub <[email protected]>
@cston cston requested a review from marek-safar as a code owner October 3, 2024 21:50
@stephentoub stephentoub added the Servicing-consider Issue for next servicing release review label Oct 10, 2024
@stephentoub stephentoub added this to the 9.0.0 milestone Oct 10, 2024
@stephentoub stephentoub added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 10, 2024
@stephentoub stephentoub merged commit 226c034 into release/9.0 Oct 10, 2024
139 of 144 checks passed
@stephentoub stephentoub deleted the backport/pr-108219-to-release/9.0 branch October 10, 2024 15:56
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants