Skip to content

Change to string function behaviour with enums in FSharp.Core 10.0.100 #19145

@rob-earwaker

Description

@rob-earwaker

When using .NET 9 SDK or earlier, the string function returns the enum case name for FSharp.Core versions < 10. When upgrading to FSharp.Core 10.0.100, the string function returns the enum's integer value as a string.

Repro steps

  1. New .NET 9 F# console app with the following lines:
    let enumValue = System.ConsoleColor.DarkBlue
    printfn $"string:     '{string enumValue}'"
    printfn $"ToString(): '{enumValue.ToString()}'"
  2. Pin FSharp.Core version to 9.0.303.
  3. Add global.json with SDK version set to 9.0.308.
  4. dotnet run produces:
    string:     'DarkBlue'
    ToString(): 'DarkBlue'
  5. Update FSharp.Core version to 10.0.100.
  6. dotnet run produces:
    string:     '1'
    ToString(): 'DarkBlue'

Project used to reproduce behaviour above: FSharp.String.TestApp.zip

Expected behavior

string function returns the enum case name, i.e. the equivalent of calling the ToString() method.

Actual behavior

string function returns the enum case's integer value as a string.

Known workarounds

One of the following:

  • Use the ToString()method directly
  • Use an earlier version of FSharp.Core
  • Use the .NET 10 SDK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions