Skip to content

Commit

Permalink
[mcs] Use InvariantCulture for GetValueAsLiteral() in constant.cs
Browse files Browse the repository at this point in the history
Without it mcs would've printed the following error for code like `const int val = 1.42f`
on a system where the decimal separator is not the dot, e.g. German:

```
test.cs(3,18): error CS0031: Constant value `1,42' cannot be converted to a `int'
```
  • Loading branch information
akoeplinger committed Oct 17, 2016
1 parent 297c257 commit 51245ed
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mcs/mcs/constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec t
catch
{
ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
GetValue ().ToString (), target.GetSignatureForError ());
GetValueAsLiteral (), target.GetSignatureForError ());
}
}

Expand Down Expand Up @@ -1697,7 +1697,7 @@ public override object GetValue ()

public override string GetValueAsLiteral ()
{
return Value.ToString ();
return Value.ToString (CultureInfo.InvariantCulture);
}

public override long GetValueAsLong ()
Expand Down Expand Up @@ -1820,7 +1820,7 @@ public override object GetValue ()

public override string GetValueAsLiteral ()
{
return Value.ToString ();
return Value.ToString (CultureInfo.InvariantCulture);
}

public override long GetValueAsLong ()
Expand Down Expand Up @@ -2021,7 +2021,7 @@ public override object GetValue ()

public override string GetValueAsLiteral ()
{
return Value.ToString () + "M";
return Value.ToString (CultureInfo.InvariantCulture) + "M";
}

public override long GetValueAsLong ()
Expand Down

0 comments on commit 51245ed

Please sign in to comment.