Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

UoM ToString returns random values #19435

Closed

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

Activity

  1. added theissue type on Mar 16, 2026
  2. added this to the Backlog milestone on Mar 16, 2026
  3. added
    Area-Compiler-CodeGen
    on Mar 16, 2026
  4. self-assigned this
    on Mar 16, 2026
  5. added
    Impact-High
    and removed on Mar 16, 2026
  6. T-Gro commented on Mar 16, 2026

    @T-Gro
    Member

    @kerams : Intuition was correct.

    The MethInfoWithModifiedReturnType (what was used to have ToString return a non nullable string ) case in BuildMethodCall was recursively
    calling BuildMethodCall again, which re-invoked TakeObjAddrForMethodCall on
    already-addressed object arguments. This created double-indirection
    (byref<byref>) for value types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-Compiler-CodeGenBugImpact-High

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions