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

Allow ctor parameters to exactly match property name #38959

Merged
merged 9 commits into from
Jul 15, 2020

Conversation

steveharter
Copy link
Member

Supports the new C# "record" type as well as C# anonymous types.

Fixes #38539

@steveharter steveharter added this to the 5.0.0 milestone Jul 8, 2020
@steveharter steveharter requested a review from layomia July 8, 2020 21:27
@steveharter steveharter requested a review from jozkee as a code owner July 8, 2020 21:27
@steveharter steveharter self-assigned this Jul 8, 2020
@@ -36,14 +36,14 @@ internal sealed partial class JsonClassInfo

// All of the serializable parameters on a POCO constructor keyed on parameter name.
// Only paramaters which bind to properties are cached.
public volatile Dictionary<string, JsonParameterInfo>? ParameterCache;
public Dictionary<string, JsonParameterInfo>? ParameterCache;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't need volatile since they are not accessed by other threads until initialization is complete.

@steveharter
Copy link
Member Author

Needed to remove usage of C# 9.0 'record' usage in tests due to CI failure in dotnet-runtime-perf leg:
Serialization\ConstructorTests\ConstructorTests.Exceptions.cs(156,37): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported

Assert.Equal(5, objType.GetProperty("Prop").GetValue(newObj));
}

/* Enable when C# 9.0 'records' feature works in CI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we file an issue to track this?

cc @safern do you know when we'll enable this in CI?

Copy link
Member Author

@steveharter steveharter Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears the performance CI leg for some reason is not using the same compiler\SDK as the other tests.

#39081

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@safern @DrewScoggins the "IsExternalInit" failures are occurring with the tests using the "record" type:

Net472

Serialization\ConstructorTests\ConstructorTests.Exceptions.cs(155,37): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported [F:\workspace\_work\1\s\src\libraries\System.Text.Json\tests\System.Text.Json.Tests.csproj]
##[error]Serialization\ConstructorTests\ConstructorTests.Exceptions.cs(155,37): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported
Serialization\ConstructorTests\ConstructorTests.Exceptions.cs(168,60): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported [F:\workspace\_work\1\s\src\libraries\System.Text.Json\tests\System.Text.Json.Tests.csproj]
##[error]Serialization\ConstructorTests\ConstructorTests.Exceptions.cs(168,60): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported
Serialization\ConstructorTests\ConstructorTests.Exceptions.cs(168,74): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported [F:\workspace\_work\1\s\src\libraries\System.Text.Json\tests\System.Text.Json.Tests.csproj]
##[error]Serialization\ConstructorTests\ConstructorTests.Exceptions.cs(168,74): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported

Copy link
Member

@safern safern Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like IsExternalInit (Which the record keyword is translated to use that) doesn't exist in net472, so we should probably make these tests just be included on NetCoreAppCurrent.

cc: @jaredpar @stephentoub are there any plans on supporting record in downlevel TFMs? Maybe by an autogenerated internal type by the compiler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@safern

we should probably make these tests just be included on NetCoreAppCurrent.

Do you mean #if NETCOREAPP?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah or splitting the test file into two test files and include the netcoreapp one whenever TargetFramework == $(NetCoreAppCurrent)

@@ -251,10 +337,11 @@ public Parameterized_ClassWithUnicodeProperty(int a\u0467)
}

[Fact]
[ActiveIssue("JsonElement needs to support Path")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously fixed -- the issue wasn't with JsonElement but in logic setting the current property.

@steveharter
Copy link
Member Author

CI looks good except several Jobs (performance- and installer-related) are queued and not running even though ~4 hours in CI.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jsonserializer and record types with "primary" constructor
4 participants