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

Mark backing fields as CompilerGenerated (fixes serialization of fields in FSI multiemit) #13494

Merged
merged 4 commits into from
Jul 12, 2022

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented Jul 11, 2022

This adds CompilerGeneratedAttribute to the backing fields used for records and anon records. These fields should have always been labelled compiler generated: they are not intended for direct use from C# or other languages and have compiler-generated names.

This only really matters when these fields are public, as CompilerGenerated is, for example, an indication to serialization frameworks to ignore the field. But it's reasonable to set it even for fields that are private.

For example this fixes #13493. When F# Interactive multiemit is on, some backing fields need to become public at the IL level because they can be accessed by any number of later assembly fragments. This confuses serialization frameworks which see a public field and serialize it in addition to the public properties. Marking the backing fields as CompilerGenerated has the effect of making the serialization frameworks ignore the field, which is correct.

The tests cover roundtrip serialization/deserialization for records and anonymous records using both Newtownsoft and System.Text.Json. We use the "printing" tests as this is really the only tests where we force multiple fragments into F# Interactive, thus testing multi-emit.

@vzarytovskii vzarytovskii merged commit 205b9a8 into dotnet:main Jul 12, 2022
vzarytovskii added a commit that referenced this pull request Jul 12, 2022
* ValRepInfoForDisplay added for improved quick info for functions defined in expressions

* Update

* Update QuickInfoTests.fs

* Update QuickInfoTests.fs

* Update

* add identifier analysis script (#13486)

* add identifier analysis script

* add identifier analysis script

* Update fantomas alpha 11 (#13481)

* Allow lower-case DU cases when RequireQualifiedAccess is specified (#13432)

* Allow lower-case DU cases when RequireQualifiedAccess is specified

* Fix PR suggestions and Add more testing

* Protect feature under preview version

* Add a NotUpperCaseConstructorWithoutRQA warning to be raised in lang version preview

* Fix formatting

* regularize some names (#13489)

* normalize some names

* format code

* fix build

* Subtraction of two chars, new conversions, and fixes for dynamic operator invocations and QuotationToExpression (#11681)

Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com>
Co-authored-by: Don Syme <dsyme@users.noreply.github.com>

* Mark backing fields as CompilerGenerated (fixes serialization of fields in FSI multiemit) (#13494)

Co-authored-by: Don Syme <donsyme@fastmail.fm>
Co-authored-by: Peter Semkin <petersemkin@duck.com>
Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
Co-authored-by: Florian Verdonck <florian.verdonck@outlook.com>
Co-authored-by: Petr Semkin <psfinaki@users.noreply.github.com>
Co-authored-by: Edgar Gonzalez <edgar.gonzalez@fundourselves.com>
Co-authored-by: Hadrian Tang <hadrianwttang@outlook.com>
Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com>
Co-authored-by: Kevin Ransom (msft) <codecutter@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect serialization using fsi and Newtonsoft on dotnet 6.0.3xx
2 participants