-
Notifications
You must be signed in to change notification settings - Fork 5k
Add sourcegen support for required & init-only properties. #79828
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
Add sourcegen support for required & init-only properties. #79828
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsUpdates the source generator to include support for public class MyPoco
{
public required int X { get; set; }
public int Y { get; init; }
} The source generator will now generate metadata treating ObjectWithParameterizedConstructorCreator = static (args) => new MyPoco() { X = (int)args[0], Y = (int)args[1] } Fix #58770.
|
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerContext.cs
Show resolved
Hide resolved
@@ -243,13 +243,13 @@ public async Task TestJsonPathDoesNotFailOnMultiThreads() | |||
await Task.WhenAll(tasks); | |||
} | |||
|
|||
private async void TestIdTask() | |||
private async Task TestIdTask() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removes any async void
declarations per https://learn.microsoft.com/en-us/archive/msdn-magazine/2013/march/async-await-best-practices-in-asynchronous-programming#avoid-async-void
7559955
to
9a61644
Compare
The test failures appear to be impacting release builds of wasm only. I'm able to reproduce the failures locally, and all seem related to an issue in which |
Sounds like the options configuration/instances might not be flowing through properly following the change to move the fast-path decision logic to the context (or just how the context/options are being instantiated). Since individual runs pass my mind also goes to threading issues with the options caching optimizations added in .NET 7. Not sure if these were considered but wanted to mention. |
Had the same thought, but the errors keep popping up even with global caching disabled. Something stranger than that is happening. I've been able to isolate the test failures to using the Steps to reproduce (on WSL) : ./build.sh -os Browser -configuration Release &&
./dotnet.sh build -t:Test src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Tests.csproj \
-p:TargetOS=Browser -p:TargetArchitecture=wasm -p:Configuration=Release |
PR blocked until #79943 can be addressed. |
9a61644
to
81986b9
Compare
Given that #79943 has been fixed, rebasing changes to see if it resolves CI issues. |
Updates the source generator to include support for
required
andinit
properties. This is done by piggybacking on the existing parameteric constructor infrastructure using property initializer syntax. For example, given the following type:The source generator will now generate metadata treating
X
andY
as pseudo-constructor parameters and emit a delegate as follows:Fix #58770.