Repository navigation
fix: write negative int, short and enum constants with the invariant culture - #1040
Merged
DocSvartz merged 1 commit intoNov 23, 2026
Conversation
…culture
int, byte/sbyte/short/ushort and unnamed enum constants were written with
value.ToString(), so under fi-FI, sv-SE or nb-NO a negative value got the
U+2212 MINUS SIGN ("−5"), which is not valid C#.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
@menes97 Thanks! |
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.
Follow-up to #1035, which made
ExpressionTranslator.WriteValuewritedecimal,long,uintandulongconstants with the invariant culture. Three branches still usedvalue.ToString():int;byte/sbyte/short/ushort, written as((short)...);(Type)....The ICU data for Finnish, Swedish and Norwegian Bokmål sets
NegativeSignto U+2212 MINUS SIGN. Under fi-FI, sv-SE or nb-NO,Expression.Constant(-5).ToScript()therefore contains−5, which the C# compiler rejects. So code generated by Mapster.Tool or compiled by ExpressionDebugger breaks on those machines as soon as a mapping has a negative constant.The
intand short-integer branches now useConvert.ToString(value, CultureInfo.InvariantCulture). The unnamed-enum branch converts to the underlying type first and formats that with the invariant culture. As a side effect, a flags combination without a name now becomes its number instead of its"A, B"name list, which wasn't valid C# after a cast anyway.Test:
TestNegativeIntegerConstantsDoNotDependOnCurrentCulturesets fi-FI and checks-5,((short)-3)and(DayOfWeek)-2. It also checks that the output contains no U+2212.Assert.IsTrue failed. −5;This PR was prepared with AI assistance (Claude Code); I reviewed the change and ran the tests above.
🤖 Generated with Claude Code