Skip to content

Test localization failures on non english machines: BoundTupleExpression.Display returns a string instead a FormattableString #24603

@MaStr11

Description

@MaStr11

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersBugResolution-FixedThe bug has been fixed and/or the requested behavior has been implementedTenet-LocalizationSome piece of UI isn’t localized, often due to hard-coding of strings or other visible elements.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions