Fix floating point arguments being parsed as multiple parameters due to culture-specific formatting#2962
Merged
Fix floating point arguments being parsed as multiple parameters due to culture-specific formatting#2962
Conversation
…ents Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
…or numeric formatting Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
…to culture-specific formatting Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [Arguments] creates wrong number of parameters with double floating point parameters
Fix floating point arguments being parsed as multiple parameters due to culture-specific formatting
Aug 20, 2025
Owner
|
@copilot We should still append the numeric representer in the emitted code. E.g. |
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Contributor
Author
Added numeric suffixes to the emitted code: |
This was referenced Oct 1, 2025
This was referenced Oct 8, 2025
This was referenced Oct 16, 2025
This was referenced Oct 24, 2025
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.
This PR fixes an issue where floating point arguments in
[Arguments]attributes were incorrectly parsed as multiple parameters instead of single values, causingArgumentException: Expected exactly 1 argument, but got 2errors.Root Cause
The issue occurred when floating point numbers were formatted using culture-specific decimal separators. In cultures like German (
de-DE) and French (fr-FR), the decimal separator is a comma (,) instead of a period (.). This caused:1.1to be formatted as"1,1"["1", "1"]Example of the Issue
Solution
Updated three critical formatting methods to use
CultureInfo.InvariantCulturefor all numeric types:TestNameFormatter.FormatArgumentValue()- Ensures test names display consistentlyTypedConstantFormatter.FormatPrimitive()- Ensures source generator output is culture-independentTypedConstantParser.FormatPrimitive()- Ensures argument parsing is culture-independentThe fix ensures that floating point numbers are always formatted with period (
.) as the decimal separator, regardless of the user's locale settings.Additionally, the emitted code now includes proper numeric type suffixes for clarity and correctness:
dfor double values (e.g.,1.1d)ffor float values (e.g.,1.1f)mfor decimal values (e.g.,1.23m)Lfor long values (e.g.,123L)ULfor ulong values (e.g.,123UL)Ufor uint values (e.g.,123U)Testing
Verified the fix works correctly across multiple cultures:
1.1→"1.1d"✅1.1→"1.1d"✅ (previously"1,1")1.1→"1.1d"✅ (previously"1,1")All
ArgumentsAttributeinstances now correctly maintain exactly one argument value regardless of culture, and the emitted code includes proper numeric type suffixes.Fixes #2961.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.