@@ -217,6 +217,7 @@ let (|Nameof|_|) com ctx = function
217217 | IdentExpr ident -> Some ident.DisplayName
218218 | Get(_, ByKey( ExprKey( StringConst prop)), _, _) -> Some prop
219219 | Get(_, ByKey( FieldKey fi), _, _) -> Some fi.Name
220+ | Get(_, FieldIndex( fieldName, _), _, _) -> Some fieldName
220221 | NestedLambda( args, Call( IdentExpr ident, info, _, _), None) ->
221222 if List.sameLength args info.Args && List.zip args info.Args |> List.forall ( fun ( a1 , a2 ) ->
222223 match a2 with IdentExpr id2 -> a1.Name = id2.Name | _ -> false )
@@ -696,24 +697,47 @@ let isCompatibleWithJsComparison = function
696697// * `.GetHashCode` called directly defaults to identity hash (for reference types except string) if not implemented.
697698// * `LanguagePrimitive.PhysicalHash` creates an identity hash no matter whether GetHashCode is implemented or not.
698699
699- let getEntityHashMethod ( ent : Entity ) =
700- if ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType then " Util" , " hashSafe"
700+ let getEntityHashMethod ( com : ICompiler ) ( ent : Entity ) =
701+ if ( ent.IsFSharpUnion || ent.IsFSharpRecord) then
702+ if com.Options.EraseUnions
703+ then " Util" , " structuralHash"
704+ else " Util" , " hashSafe"
705+ elif ent.IsValueType
706+ then " Util" , " hashSafe"
701707 else " Util" , " identityHash"
702708
709+ let getEntityEqualsMethod ( com : ICompiler ) ( ent : Entity ) =
710+ if ( ent.IsFSharpUnion || ent.IsFSharpRecord) then
711+ if com.Options.EraseUnions
712+ then " Util" , " equals"
713+ else " Util" , " equalsSafe"
714+ elif ent.IsValueType
715+ then " Util" , " equalsSafe"
716+ else " Util" , " equals"
717+
718+ let getEntityCompareMethod ( com : ICompiler ) ( ent : Entity ) =
719+ if ( ent.IsFSharpUnion || ent.IsFSharpRecord) then
720+ if com.Options.EraseUnions
721+ then " Util" , " compare"
722+ else " Util" , " compareSafe"
723+ elif ent.IsValueType
724+ then " Util" , " compareSafe"
725+ else " Util" , " compare"
726+
703727let identityHashMethod ( com : ICompiler ) = function
704728 | Boolean | Char | String | Number _ | Enum _ | Option _ | Tuple _ | List _
705729 | Builtin ( BclInt64 | BclUInt64 | BclDecimal | BclBigInt)
706730 | Builtin ( BclGuid | BclTimeSpan | BclDateTime | BclDateTimeOffset)
707731 | Builtin ( FSharpSet _ | FSharpMap _ | FSharpChoice _ | FSharpResult _) ->
708732 " Util" , " structuralHash"
709- | DeclaredType( ent, _) -> com.GetEntity( ent) |> getEntityHashMethod
733+ | DeclaredType( ent, _) -> com.GetEntity( ent) |> getEntityHashMethod com
710734 | _ -> " Util" , " identityHash"
711735
712736let structuralHashMethod ( com : ICompiler ) = function
713737 | MetaType -> " Reflection" , " getHashCode"
714738 | DeclaredType( ent, _) ->
715739 let ent = com.GetEntity( ent)
716- if not ent.IsInterface then getEntityHashMethod ent
740+ if not ent.IsInterface then getEntityHashMethod com ent
717741 else " Util" , " structuralHash"
718742 | _ -> " Util" , " structuralHash"
719743
@@ -742,10 +766,8 @@ let rec equals (com: ICompiler) ctx r equal (left: Expr) (right: Expr) =
742766 Helper.LibCall( com, coreModFor bt, " equals" , Boolean, [ left; right], ?loc= r) |> is equal
743767 | DeclaredType( ent, _) ->
744768 let ent = com.GetEntity( ent)
745- if ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType then
746- Helper.LibCall( com, " Util" , " equalsSafe" , Boolean, [ left; right], ?loc= r) |> is equal
747- else
748- Helper.LibCall( com, " Util" , " equals" , Boolean, [ left; right], ?loc= r) |> is equal
769+ let moduleName , methodName = getEntityEqualsMethod com ent
770+ Helper.LibCall( com, moduleName, methodName, Boolean, [ left; right], ?loc= r) |> is equal
749771 | Array t ->
750772 let f = makeComparerFunction com ctx t
751773 Helper.LibCall( com, " Array" , " equalsWith" , Boolean, [ f; left; right], ?loc= r) |> is equal
@@ -770,10 +792,8 @@ and compare (com: ICompiler) ctx r (left: Expr) (right: Expr) =
770792 Helper.LibCall( com, coreModFor bt, " compare" , Number Int32, [ left; right], ?loc= r)
771793 | DeclaredType( ent, _) ->
772794 let ent = com.GetEntity( ent)
773- if ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType then
774- Helper.LibCall( com, " Util" , " compareSafe" , Number Int32, [ left; right], ?loc= r)
775- else
776- Helper.LibCall( com, " Util" , " compare" , Number Int32, [ left; right], ?loc= r)
795+ let moduleName , methodName = getEntityCompareMethod com ent
796+ Helper.LibCall( com, moduleName, methodName, Number Int32, [ left; right], ?loc= r)
777797 | Array t ->
778798 let f = makeComparerFunction com ctx t
779799 Helper.LibCall( com, " Array" , " compareWith" , Number Int32, [ f; left; right], ?loc= r)
0 commit comments