Skip to content

C# fields in SRTP support - #19417

Open
vzarytovskii wants to merge 1 commit into
dotnet:mainfrom
vzarytovskii:dev/vlza/csharp-class-fields-srtp
Open

vzarytovskii wants to merge 1 commit into
dotnet:mainfrom
vzarytovskii:dev/vlza/csharp-class-fields-srtp

Conversation

@vzarytovskii

@vzarytovskii vzarytovskii commented Mar 10, 2026 •

Copy link
Copy Markdown
Member

Implements fsharp/fslang-suggestions#1323

SRTP property constraints now pick up public .NET fields: instance, static, inherited, generic and const ones, so 'T.MaxValue works for primitives too. We only use a field when nothing else matches, so existing code resolves the same way. Setting a readonly or const field gives you a proper error, obsolete fields warn, and volatile fields get the volatile. prefix. FSharp.Core never uses this.

Also, both under preview:

  • Direct access to volatile .NET fields gets the volatile. prefix
  • This is a fix of existing long standing issue - you can now write x.Prop <- v through an SRTP setter constraint

@github-actions

This comment was marked as outdated.

This comment was marked as resolved.

@vzarytovskii
vzarytovskii force-pushed the dev/vlza/csharp-class-fields-srtp branch from 0716cbc to eeb5b48 Compare March 17, 2026 12:26
@dotnet dotnet deleted a comment from ViktorHofer Mar 17, 2026
T-Gro

This comment was marked as outdated.

@github-actions github-actions Bot added the AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files label Aug 4, 2026
@github-actions github-actions Bot added the ⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen label Aug 14, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment was marked as off-topic.

SRTP property constraints now pick up public .NET fields: instance, static, inherited, generic and const ones, so 'T.MaxValue works for primitives too. We only use a field when nothing else matches, so existing code resolves the same way. Setting a readonly or const field gives you a proper error, obsolete fields warn, and volatile fields get the volatile. prefix. FSharp.Core never uses this.

Also, both under preview:
- direct access to volatile .NET fields gets the volatile. prefix
- you can write x.Prop <- v through an SRTP setter constraint
@vzarytovskii
vzarytovskii force-pushed the dev/vlza/csharp-class-fields-srtp branch from eeb5b48 to 82fcec7 Compare November 12, 2026 11:18
@vzarytovskii

Copy link
Copy Markdown
Member Author

@T-Gro PTAL, I've finally found time to finish it and fix the annoying setter syntax for whole SRTP.

@vzarytovskii
vzarytovskii enabled auto-merge (squash) November 12, 2026 13:54

This branch has not been deployed

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

Labels

⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

3 participants