Fable icon indicating copy to clipboard operation
Fable copied to clipboard

Unexpected results for nested options with Option.orElse

Open IanManske opened this issue 3 years ago • 0 comments

Description

For nested options (i.e. Option<Option<_>>) where the innermost option is None, Option.orElse does not behave as expected. Instead of returning the second arguement option as is, it is unwrapped and the inner option is returned. This occurs because Option.orElse is compiled into JS using defaultArg. This same issue exists for Option.orElseWith.

Repo code

REPL

Expected and actual results

Expected:

(Some None) |> Option.orElse (Some (Some "never")) // = Some None
// the expected JS representation is: Some { value: undefined }

Actual:

(Some None) |> Option.orElse (Some (Some "never")) // = None
// the actual JS representation: undefined

Related information

  • Fable version: 3.7.10 (REPL), also tested on 3.7.17

IanManske avatar Aug 05 '22 21:08 IanManske