Extracted from the closed PR #24539
Steps to Reproduce:
Run Microsoft.CodeAnalysis.CSharp.UnitTests.OverloadResolutionTests.GenericInferenceOnInErrTuples on a non-english machine.
Expected Behavior:
Test passes.
Actual Behavior:
Test fails for Diagnostics with a BoundTupleExpression because BoundTupleExpression.Display returns a localized string (e.g. German during the test run). BoundTupleExpression.Display should return a formattable string instead. There are some more tests that also fail. See the original PR for details.
History
The issue was discussed but not resolved in #24539. The relevant sections are:
@MaStr11
The diagnostic is created here and the argument is created via argument.Display
The problem here is that the BoundTupleExpression.Display uses a stringbuilder. So the argument is a text as opposed to a LocalizableErrorArgument. I don't see any straight forward way on how to resolve this. @AlekseyTs I would propose to revert my changes here and let the test fail on non english machines for now.
@AlekseyTs
It would be great if you could fix it because you can easily verify the effect, but it is up to you.
I think there is a simple fix for BoundTupleExpression.Display. Instead of building complete string, we can build a format string with argument markers and collect arguments in an array. Then we call to System.Runtime.CompilerServices.FormattableStringFactory.Create and return its result.
There is also an issue with
internal partial class BoundStackAllocArrayCreation
{
public override object Display
{
get { return string.Format(MessageID.IDS_StackAllocExpression.Localize().ToString(), ElementType, Count.Syntax); }
}
}
This one can be fixed by creating an object that is very similar to LocalizableErrorArgument, that calls Format after getting the string for requested culture.
Extracted from the closed PR #24539
Steps to Reproduce:
Run
Microsoft.CodeAnalysis.CSharp.UnitTests.OverloadResolutionTests.GenericInferenceOnInErrTupleson a non-english machine.Expected Behavior:
Test passes.
Actual Behavior:
Test fails for Diagnostics with a
BoundTupleExpressionbecauseBoundTupleExpression.Displayreturns a localized string (e.g. German during the test run). BoundTupleExpression.Display should return a formattable string instead. There are some more tests that also fail. See the original PR for details.History
The issue was discussed but not resolved in #24539. The relevant sections are:
@MaStr11
The diagnostic is created here and the argument is created via
argument.DisplayThe problem here is that the BoundTupleExpression.Display uses a stringbuilder. So the argument is a text as opposed to a
LocalizableErrorArgument. I don't see any straight forward way on how to resolve this. @AlekseyTs I would propose to revert my changes here and let the test fail on non english machines for now.@AlekseyTs
It would be great if you could fix it because you can easily verify the effect, but it is up to you.
I think there is a simple fix for BoundTupleExpression.Display. Instead of building complete string, we can build a format string with argument markers and collect arguments in an array. Then we call to System.Runtime.CompilerServices.FormattableStringFactory.Create and return its result.
There is also an issue with
This one can be fixed by creating an object that is very similar to LocalizableErrorArgument, that calls Format after getting the string for requested culture.