Repository navigation
Write newer C# operators and readonly struct members as the source declares them - #110
Merged
Merged
Conversation
…clares them
- C# 14 compound assignment operators, `void operator +=(Money other)`, the instance `++` and `--`, their
checked forms, and `explicit operator checked int` were written by their metadata names (`op_…`).
- A struct property whose getter alone is readonly, as every auto-property getter is, was written
`readonly int X { readonly get; set; }`: readonly on the property is for when every accessor is.
A readonly setter was not read at all.
- A params span was written `scoped params`, which C# rejects; params spans are scoped without saying so.
The Roslyn oracle now also checks readonly on methods and accessors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A survey of C# 12–14 features, read through the reader, the writer, the parser and the Roslyn oracle, found three things written wrong:
void operator +=(Money other),%=,>>>=and the rest), the instancevoid operator ++()and--, theircheckedforms, andexplicit operator checked intcame out under their metadata names, such asop_CheckedAdditionAssignment. The parser reads them all back; a++without a parameter is the instance one.int X { get; set; }was writtenreadonly int X { readonly get; set; }. Property-levelreadonlynow means what C# means by it: every accessor is readonly, which C# writes on the property. Areadonly setwas not read at all.params ReadOnlySpan<string> partswas writtenscoped params ReadOnlySpan<string>, which C# rejects (CS9350). A params span is scoped without saying so; the reader leaves that impliedscopedout, and the writer putsparamsfirst if a model has both.The rest of the survey reads right, matches Roslyn and round-trips: params collections,
allows ref struct,[Experimental],[OverloadResolutionPriority], InlineArray, ref structs implementing interfaces, partial properties and events,field-backed properties, primary constructors,ref readonlyparameters, record structs and static abstract/virtual interface members. They are now all in the newmodernwriter sample.Verified:
readonlyon methods and accessors, for structs that are not readonly.mise run ciis green locally.++as always static fails the model round trip;scopedfails the oracle on CoreLib, System.Text.Json and System.Collections.Immutable.🤖 Generated with Claude Code