Skip to content

UoM ToString returns random values #19435

@kerams

Description

@kerams

Create an fsproj with <Nullable>enable</Nullable> and

module ReprExe.Program

open FSharp.Data.UnitSystems.SI.UnitNames

[<EntryPoint>]
let main argv =
    System.Console.Write (42<meter>.ToString ())
    0

then dotnet run (rather than running in VS)

Expected behavior

Prints 42

Actual behavior

PS D:\repr\ReprExe> dotnet run
-600316336
PS D:\repr\ReprExe> dotnet run
-1424497392
PS D:\repr\ReprExe> dotnet run
-1959269956
PS D:\repr\ReprExe> dotnet run
-34085460
PS D:\repr\ReprExe> dotnet run
-1411848676
PS D:\repr\ReprExe> dotnet run
-851778836

Decompiled

[EntryPoint]
public static int main(string[] argv)
{
	int num = 42;
	ref int ptr = ref num;
	Console.Write(ptr.ToString());
	return 0;
}

Suspicious ref. The ptr.ToString call is ValueType.ToString() (which is what F# normally emits for integers with UoM), so I am guessing this might be returning a memory address.

Known workarounds

string function or strip UoM first or remove <Nullable>enable</Nullable>.

Related information

  • Win 11
  • SDK 11.0.100-preview.2.26159.112
  • FSharp.Core 11.0.100-preview3.26159.112

Metadata

Metadata

Assignees

Labels

Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions