Skip to content

Commit

Permalink
fixed merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin521 committed Nov 8, 2024
1 parent 55f2fc6 commit c3d61e0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
"rollForward": true
}
}
}
}
3 changes: 3 additions & 0 deletions docs/release-notes/.FSharp.Core/9.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
### Added

### Changed
* String function changed to guarantee a non-null string return type ([PR #17809](https://github.com/dotnet/fsharp/pull/17809))


### Breaking Changes

4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="10.0.0-alpha.1.24554.1">
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="10.0.0-alpha.1.24556.1">
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
<Sha>e781442b88c4d939f06a94f38f24a5dc18c383d4</Sha>
<Sha>346f2ca639adb1b363592e27bf62aba52916ea3f</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<!-- Intermediate is necessary for source build. -->
Expand Down
15 changes: 10 additions & 5 deletions src/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,16 @@ namespace Microsoft.FSharp.Core
for m = 0 to len4 - 1 do
SetArray4D dst (src1+i) (src2+j) (src3+k) (src4+m) (GetArray4D src i j k m)

let inline defaultIfNull (defaultStr:string) x =
match x with
| null -> defaultStr
| nonNullString -> nonNullString

let inline anyToString nullStr x =
match box x with
| :? IFormattable as f -> f.ToString(null, CultureInfo.InvariantCulture)
| :? IFormattable as f -> defaultIfNull nullStr (f.ToString(null, CultureInfo.InvariantCulture))
| null -> nullStr
| _ -> x.ToString()
| _ -> defaultIfNull nullStr (x.ToString())

let anyToStringShowingNull x = anyToString "null" x

Expand Down Expand Up @@ -5200,8 +5205,8 @@ namespace Microsoft.FSharp.Core
when 'T : Guid = let x = (# "" value : Guid #) in x.ToString(null, CultureInfo.InvariantCulture)
when 'T struct =
match box value with
| :? IFormattable as f -> f.ToString(null, CultureInfo.InvariantCulture)
| _ -> value.ToString()
| :? IFormattable as f -> defaultIfNull "" (f.ToString(null, CultureInfo.InvariantCulture))
| _ -> defaultIfNull "" (value.ToString())

// other common mscorlib reference types
when 'T : StringBuilder =
Expand All @@ -5210,7 +5215,7 @@ namespace Microsoft.FSharp.Core

when 'T : IFormattable =
if value = unsafeDefault<'T> then ""
else let x = (# "" value : IFormattable #) in x.ToString(null, CultureInfo.InvariantCulture)
else let x = (# "" value : IFormattable #) in defaultIfNull "" (x.ToString(null, CultureInfo.InvariantCulture))

[<NoDynamicInvocation(isLegacy=true)>]
[<CompiledName("ToChar")>]
Expand Down
9 changes: 9 additions & 0 deletions tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModule2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,15 @@ type OperatorsModule2() =
let result = Operators.string 123.456M
Assert.AreEqual("123.456", result)

let result = Operators.string { new obj () with override _.ToString () = null }
Assert.AreEqual("", result)

let result = Operators.string { new obj () with override _.ToString () = Operators.string null }
Assert.AreEqual("", result)

let result = Operators.string { new IFormattable with override _.ToString (_, _) = null }
Assert.AreEqual("", result)

// Following tests ensure that InvariantCulture is used if type implements IFormattable

// safe current culture, then switch culture
Expand Down

0 comments on commit c3d61e0

Please sign in to comment.