Skip to content

Commit

Permalink
Fix culture-dependent ToString in illink tests (dotnet#96172)
Browse files Browse the repository at this point in the history
We should be emitting the double/float string using invariant culture to avoid failures like this on cultures where decimal point is comma:

```
Expected:
    ldc.r8 2.5
    ret
Actual:
    ldc.r8 2,5
    ret
```
  • Loading branch information
akoeplinger authored Dec 19, 2023
1 parent 1884956 commit d873a06
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Mono.Cecil;
Expand Down Expand Up @@ -628,13 +629,13 @@ static string FormatInstruction (Instruction instr)

case Code.Ldc_R4:
if (instr.Operand is float fvalue)
return $"{instr.OpCode.ToString ()} {fvalue.ToString ()}";
return $"{instr.OpCode.ToString ()} {fvalue.ToString (CultureInfo.InvariantCulture)}";

throw new NotImplementedException (instr.Operand.GetType ().ToString ());

case Code.Ldc_R8:
if (instr.Operand is double dvalue)
return $"{instr.OpCode.ToString ()} {dvalue.ToString ()}";
return $"{instr.OpCode.ToString ()} {dvalue.ToString (CultureInfo.InvariantCulture)}";

throw new NotImplementedException (instr.Operand.GetType ().ToString ());

Expand Down

0 comments on commit d873a06

Please sign in to comment.