@@ -1484,17 +1484,18 @@ let nullables (com: ICompiler) (_: Context) r (t: Type) (i: CallInfo) (thisArg:
14841484 | " get_HasValue" , Some c -> makeEqOp r c ( makeNull()) BinaryUnequal |> Some
14851485 | _ -> None
14861486
1487- // See fable-library/Option.ts for more info on how options behave in Fable runtime
1488- let options ( com : ICompiler ) ( _ : Context ) r ( t : Type ) ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
1487+ let options isStruct ( com : ICompiler ) ( _ : Context ) r ( t : Type ) ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
14891488 match i.CompiledName, thisArg with
1489+ | " get_None" , _ -> NewOption( None, t.Generics.Head, isStruct) |> makeValue r |> Some
1490+ | " Some" , _ -> NewOption( List.tryHead args, t.Generics.Head, isStruct) |> makeValue r |> Some
14901491 | " get_Value" , Some c -> getOptionValue r t c |> Some
14911492 | " get_IsSome" , Some c -> Test( c, OptionTest true , r) |> Some
14921493 | " get_IsNone" , Some c -> Test( c, OptionTest false , r) |> Some
14931494 | _ -> None
14941495
1495- let optionModule ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( _ : Expr option ) ( args : Expr list ) =
1496+ let optionModule isStruct ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( _ : Expr option ) ( args : Expr list ) =
14961497 match i.CompiledName, args with
1497- | " None" , _ -> NewOption( None, t, false ) |> makeValue r |> Some
1498+ | " None" , _ -> NewOption( None, t, isStruct ) |> makeValue r |> Some
14981499 | " GetValue" , [ c] -> getOptionValue r t c |> Some
14991500 | " IsSome" , [ c] -> Test( c, OptionTest true , r) |> Some
15001501 | " IsNone" , [ c] -> Test( c, OptionTest false , r) |> Some
@@ -2708,10 +2709,11 @@ let private replacedModules =
27082709 Types.queue, bclType
27092710 Types.iset, hashSets
27102711 Types.idisposable, disposables
2711- Types.option, options
2712- Types.valueOption, options
2712+ Types.option, options false
2713+ Types.valueOption, options true
27132714 " System.Nullable`1" , nullables
2714- " Microsoft.FSharp.Core.OptionModule" , optionModule
2715+ " Microsoft.FSharp.Core.OptionModule" , optionModule false
2716+ " Microsoft.FSharp.Core.ValueOption" , optionModule true
27152717 " Microsoft.FSharp.Core.ResultModule" , results
27162718 Types.bigint, bigints
27172719 " Microsoft.FSharp.Core.NumericLiterals.NumericLiteralI" , bigints
@@ -2892,7 +2894,7 @@ let tryType = function
28922894 Some( getNumberFullName false kind info, f, [])
28932895 | String -> Some( Types.string, strings, [])
28942896 | Tuple( genArgs, _) as t -> Some( getTypeFullName false t, tuples, genArgs)
2895- | Option( genArg, _ ) -> Some( Types.option, options, [ genArg])
2897+ | Option( genArg, isStruct ) -> Some( Types.option, options isStruct , [ genArg])
28962898 | Array( genArg,_) -> Some( Types.array, arrays, [ genArg])
28972899 | List genArg -> Some( Types.list, lists, [ genArg])
28982900 | Builtin kind ->
0 commit comments