-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix bugs with generation for ctor param default values #62798
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsFixes source gen issue where invalid code is generated by JSON source-gen when supporting default ctor param values, preventing successful app compilation. cc @333fred
|
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
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.
Some questions, but otherwise LGTM.
...braries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
c435ff0
to
100156a
Compare
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
return ToCSharpKeyword(@bool); | ||
default: | ||
// Assume this is a number. | ||
return $"({typeRef})({value.ToString()})"; |
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.
This doesn't need to use invariant culture? What if the current culture is one that uses something other than -
for a negative sign?
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.
Updated to use invariant culture and avoid generating invalid C#. I plan to figure out some testing for this scenario in a follow up.
cc @ericstj on whether the dotnet/arcade implementations has similar localization concerns - https://github.com/dotnet/arcade/blob/0cd94b1d02c03377d99f3739beb191591f6abee5/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Attributes.cs#L313
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.
cc @safern. It does special case certain types and use invariant culture, but not all (including int). It's possible it has the issue but we don't notice since it's only used when folks run genapi which tends to be done by devs on english systems who review the diff it generates.
I'm a bit surprised we have to write this much ourselves. Does Roslyn have an API to give us the formatted default value?
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.
I see @stephentoub pointed this out here: #62798 (comment)
Nice! @safern take note, GenAPI could use this.
src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1665097854 |
@layomia backporting to release/6.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix bugs with generation for ctor param default values
.git/rebase-apply/patch:109: trailing whitespace.
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Double.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Float.cs
M src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Float.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Double.cs
Auto-merging src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix bugs with generation for ctor param default values
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
* Fix bugs with generation for ctor param default values * Address review feedback * Address feedback
Fixes source gen issue where invalid code is generated by JSON source-gen when supporting default ctor param values, preventing successful app compilation.
Fixes #62766.
Candidate for 6.0.x servicing fix.
cc @333fred