Skip to content

Remove illegal NAOT cctor preinitialization#130203

Closed
MichalPetryka wants to merge 1 commit into
dotnet:mainfrom
MichalPetryka:patch-65
Closed

Remove illegal NAOT cctor preinitialization#130203
MichalPetryka wants to merge 1 commit into
dotnet:mainfrom
MichalPetryka:patch-65

Conversation

@MichalPetryka

Copy link
Copy Markdown
Contributor

Readonly instance fields are not hard immutable, they can be modified with init accessors, in raw IL or reflection.

cc @MichalStrehovsky @jkotas

Readonly instance fields are not hard immutable, they can be modified with init accessors, in raw IL or reflection.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 4, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@hez2010

hez2010 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

I don't see any wrong with this policy. The "readonly" here doesn't mean the ordinary instance readonly field. Instead, it stands for

  • static readonly fields (see StaticReadOnlyFieldPolicy)
  • fields that have no actual write operations after IL scanning, including reflection access (see ScannedReadOnlyPolicy)

So _readOnlyPolicy.IsReadOnly(field) should already only be true when the field is really readonly (i.e. no write access to it in the whole program). This is different from ordinary instance readonly field.

@jkotas

jkotas commented Jul 4, 2026

Copy link
Copy Markdown
Member

I do not think there is an issue as @hez2010 pointed out. If you believe that there is an issue, please share a repro that demonstrates it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants