@@ -48,8 +48,15 @@ type FsUnionCase(uci: FSharpUnionCase) =
4848 |> Helpers.tryFindAtt Atts.compiledName
4949 |> Option.map ( fun ( att : FSharpAttribute ) -> att.ConstructorArguments.[ 0 ] |> snd |> string)
5050
51+ static member FullName ( uci : FSharpUnionCase ) =
52+ // proper full compiled name (instead of uci.FullName)
53+ uci.XmlDocSig
54+ |> Naming.replacePrefix " T:Microsoft.FSharp." " FSharp."
55+ |> Naming.replacePrefix " T:" " "
56+
5157 interface Fable.UnionCase with
5258 member _.Name = uci.Name
59+ member _.FullName = FsUnionCase.FullName uci
5360 member _.CompiledName = FsUnionCase.CompiledName uci
5461 member _.UnionCaseFields = uci.UnionCaseFields |> Seq.mapToList ( fun x -> upcast FsField( x))
5562
@@ -437,8 +444,8 @@ module Helpers =
437444 Some ( makeRange fsExpr.Range)
438445
439446 let isErasedTypeDef ( com : Compiler ) ( tdef : FSharpEntity ) =
440- com.Options.EraseTypes
441- && ( tdef.IsFSharpUnion || tdef.IsFSharpRecord) // || tdef.IsValueType)
447+ com.Options.EraseTypes && tdef.IsFSharp
448+ && ( tdef.IsFSharpUnion || tdef.IsFSharpRecord || tdef.IsValueType || tdef.IsByRef )
442449 && not ( tdef.TryFullName = Some Types.reference) // no F# refs
443450 && not ( hasAttribute Atts.customEquality tdef.Attributes)
444451 && not ( hasAttribute Atts.customComparison tdef.Attributes)
@@ -691,52 +698,33 @@ module Patterns =
691698 | _ -> None
692699 else None
693700
694- [<RequireQualifiedAccess>]
695- type EraseKind =
696- | AsValue
697- | AsTuple
698- | AsNamedTuple
699- | AsStringEnum of CaseRules
700-
701- let (| OptionUnion | ListUnion | ErasedUnion | DiscriminatedUnion |)
702- ( com : Compiler , NonAbbreviatedType typ : FSharpType , unionCase : FSharpUnionCase ) =
703-
701+ let (| OptionUnion | ListUnion | ErasedUnion | ErasedUnionCase | StringEnum | DiscriminatedUnion |)
702+ ( NonAbbreviatedType typ : FSharpType , unionCase : FSharpUnionCase ) =
704703 let getCaseRule ( att : FSharpAttribute ) =
705704 match Seq.tryHead att.ConstructorArguments with
706705 | Some(_, (:? int as rule)) -> enum < CaseRules>( rule)
707706 | _ -> CaseRules.LowerFirst
708707
709- let getEraseKind ( tdef : FSharpEntity ) ( att : FSharpAttribute ) =
710- match unionCase.UnionCaseFields.Count with
711- | 0 -> EraseKind.AsStringEnum( getCaseRule att)
712- | 1 -> EraseKind.AsValue
713- | _ -> EraseKind.AsTuple
714-
715- match tryDefinition typ with
716- | None -> failwith " Union without definition"
717- | Some( tdef, fullName) ->
718- match defaultArg fullName tdef.CompiledName with
719- | Types.valueOption
720- | Types.option -> OptionUnion( typ.GenericArguments.[ 0 ])
721- | Types.list -> ListUnion( typ.GenericArguments.[ 0 ])
722- | _ ->
723- unionCase.Attributes |> Seq.tryPick ( fun att ->
724- match att.AttributeType.TryFullName with
725- | Some Atts.erase ->
726- Some ( ErasedUnion( EraseKind.AsTuple, tdef, typ.GenericArguments))
727- | _ -> None)
728- |> Option.orElseWith ( fun () ->
708+ unionCase.Attributes |> Seq.tryPick ( fun att ->
709+ match att.AttributeType.TryFullName with
710+ | Some Atts.erase -> Some ErasedUnionCase
711+ | _ -> None)
712+ |> Option.defaultWith ( fun () ->
713+ match tryDefinition typ with
714+ | None -> failwith " Union without definition"
715+ | Some( tdef, fullName) ->
716+ match defaultArg fullName tdef.CompiledName with
717+ | Types.valueOption
718+ | Types.option -> OptionUnion typ.GenericArguments.[ 0 ]
719+ | Types.list -> ListUnion typ.GenericArguments.[ 0 ]
720+ | _ ->
729721 tdef.Attributes |> Seq.tryPick ( fun att ->
730722 match att.AttributeType.TryFullName with
731- | Some Atts.erase
732- | Some Atts.stringEnum ->
733- let kind = getEraseKind tdef att
734- Some ( ErasedUnion( kind, tdef, typ.GenericArguments))
735- | _ -> None))
736- |> Option.defaultWith ( fun () ->
737- if isErasedType com typ
738- then ErasedUnion( EraseKind.AsNamedTuple, tdef, typ.GenericArguments)
739- else DiscriminatedUnion( tdef, typ.GenericArguments))
723+ | Some Atts.erase -> Some ( ErasedUnion( tdef, typ.GenericArguments, getCaseRule att))
724+ | Some Atts.stringEnum -> Some ( StringEnum( tdef, getCaseRule att))
725+ | _ -> None)
726+ |> Option.defaultValue ( DiscriminatedUnion( tdef, typ.GenericArguments))
727+ )
740728
741729 let (| ContainsAtt | _ |) ( fullName : string ) ( ent : FSharpEntity ) =
742730 tryFindAtt fullName ent.Attributes
@@ -868,7 +856,8 @@ module TypeHelpers =
868856 Fable.LambdaType( argType, returnType)
869857 elif t.IsAnonRecordType then
870858 let genArgs = makeGenArgs ctxTypeArgs t.GenericArguments
871- Fable.AnonymousRecordType( t.AnonRecordTypeDetails.SortedFieldNames, genArgs)
859+ let fields = t.AnonRecordTypeDetails.SortedFieldNames
860+ Fable.AnonymousRecordType( fields, genArgs)
872861 elif t.HasTypeDefinition then
873862// No support for provided types when compiling FCS+Fable to JS
874863#if ! FABLE_ COMPILER
@@ -1068,7 +1057,6 @@ module Util =
10681057 | None -> None
10691058 Fable.TryCatch( body, catchClause, finalizer, r)
10701059
1071-
10721060 let matchGenericParamsFrom ( memb : FSharpMemberOrFunctionOrValue ) ( genArgs : Fable.Type seq ) =
10731061 let matchGenericParams ( genArgs : Fable.Type seq ) ( genParams : FSharpGenericParameter seq ) =
10741062 Seq.zip ( genParams |> Seq.map genParamName) genArgs
@@ -1177,7 +1165,8 @@ module Util =
11771165
11781166 let isErasedEntity ( com : Compiler ) ( ent : Fable.Entity ) =
11791167 match ent with
1180- | :? FsEnt as fsEnt -> Helpers.isErasedTypeDef com fsEnt.FSharpEntity
1168+ | :? FsEnt as fsEnt ->
1169+ Helpers.isErasedTypeDef com fsEnt.FSharpEntity
11811170 | _ -> false
11821171
11831172 let isErasedOrStringEnumEntity ( ent : Fable.Entity ) =
0 commit comments