@@ -5183,10 +5183,9 @@ namespace Microsoft.FSharp.Core
51835183 when 'T : nativeint = let x = ( # " " value : nativeint #) in x.ToString()
51845184 when 'T : unativeint = let x = ( # " " value : unativeint #) in x.ToString()
51855185
5186- // Integral types can be enum:
5187- // It is not possible to distinguish statically between Enum and (any type of) int. For signed types we have
5188- // to use IFormattable::ToString, as the minus sign can be overridden. Using boxing we'll print their symbolic
5189- // value if it's an enum, e.g.: 'ConsoleKey.Backspace' gives "Backspace", rather than "8")
5186+ // These rules for signed integer types will no longer be used when built with a compiler version that
5187+ // supports `when 'T : Enum`, but we must keep them to remain compatible with compiler versions that do not.
5188+ // Once all compiler versions that do not understand `when 'T : Enum` are out of support, these four rules can be removed.
51905189 when 'T : sbyte = ( box value :?> IFormattable) .ToString( null , CultureInfo.InvariantCulture)
51915190 when 'T : int16 = ( box value :?> IFormattable) .ToString( null , CultureInfo.InvariantCulture)
51925191 when 'T : int32 = ( box value :?> IFormattable) .ToString( null , CultureInfo.InvariantCulture)
@@ -5228,8 +5227,17 @@ namespace Microsoft.FSharp.Core
52285227 let inline string ( value : 'T ) =
52295228 defaultString value
52305229
5231- // Special handling for enums whose underlying type is a signed integral type.
5232- // The runtime value may be outside the defined members of the enum, and the negative sign may be overridden.
5230+ // Special handling is required for enums, since:
5231+ //
5232+ // - The runtime value may be outside the defined members of the enum.
5233+ // - Their underlying type may be a signed integral type.
5234+ // - The negative sign may be overridden.
5235+ //
5236+ // For example:
5237+ //
5238+ // string DayOfWeek.Wednesday → "Wednesday"
5239+ // string (enum<DayOfWeek> -3) → "-3" // The negative sign is culture-dependent.
5240+ // string (enum<DayOfWeek> -3) → "⁒3" // E.g., the negative sign for the current culture could be overridden to "⁒".
52335241 when 'T : Enum = let x = ( # " " value : 'T #) in x.ToString() // Use 'T to constrain the call to the specific enum type.
52345242
52355243 // For compilers that understand `when 'T : Enum`, we can safely make a constrained call on the integral type itself here.
0 commit comments