Skip to content

Commit cff6266

Browse files
Nullable.ValueNullable.GetValueOrDefault (#17504)
* We are already checking `Nullable.HasValue` before accessing `Nullable.Value`, so it is safe to call `Nullable.GetValueOrDefault`, which does not do an additional check, unlike `Nullable.Value`.
1 parent 6fac9b9 commit cff6266

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/FSharp.Core/option.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module Option =
148148
[<CompiledName("OfNullable")>]
149149
let inline ofNullable (value: System.Nullable<'T>) =
150150
if value.HasValue then
151-
Some value.Value
151+
Some (value.GetValueOrDefault())
152152
else
153153
None
154154

@@ -338,7 +338,7 @@ module ValueOption =
338338
[<CompiledName("OfNullable")>]
339339
let inline ofNullable (value: System.Nullable<'T>) =
340340
if value.HasValue then
341-
ValueSome value.Value
341+
ValueSome (value.GetValueOrDefault())
342342
else
343343
ValueNone
344344

0 commit comments

Comments
 (0)