From e2ca36c5212469ee1d4f16e6c8391643e069b3a4 Mon Sep 17 00:00:00 2001 From: ncave <777696+ncave@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:22:00 -0700 Subject: [PATCH] Fixed #3658 --- src/Fable.Transforms/FSharp2Fable.fs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Fable.Transforms/FSharp2Fable.fs b/src/Fable.Transforms/FSharp2Fable.fs index 22a134c048..5e3dfff915 100644 --- a/src/Fable.Transforms/FSharp2Fable.fs +++ b/src/Fable.Transforms/FSharp2Fable.fs @@ -1474,20 +1474,33 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) appliedGenArgs fs |> addErrorAndReturnNull com ctx.InlinePath (makeRangeFrom fsExpr) } -let private isIgnoredNonAttachedMember (meth: FSharpMemberOrFunctionOrValue) = - Option.isSome meth.LiteralValue - || meth.Attributes +let private isIgnoredNonAttachedMember (memb: FSharpMemberOrFunctionOrValue) = + Option.isSome memb.LiteralValue + || memb.Attributes |> Seq.exists (fun att -> match att.AttributeType.TryFullName with | Some(Atts.global_ | Naming.StartsWith Atts.import _ | Naming.StartsWith Atts.emit _) -> true | _ -> false ) || ( - match meth.DeclaringEntity with + match memb.DeclaringEntity with | Some ent -> isGlobalOrImportedFSharpEntity ent | None -> false ) +let private isErasedUnionCaseTester (memb: FSharpMemberOrFunctionOrValue) = + // if memb.IsUnionCaseTester then // TODO: this currently fails, use when fixed + if memb.IsPropertyGetterMethod && memb.LogicalName.StartsWith("get_Is") then + // currently returns true for any tester if any union case is erased + // TODO: return true only when the tester's own union case is erased + match memb.DeclaringEntity with + | Some ent when ent.IsFSharpUnion -> + ent.UnionCases + |> Seq.exists (fun unionCase -> hasAttrib Atts.erase unionCase.Attributes) + | _ -> false + else + false + let private isCompilerGenerated (memb: FSharpMemberOrFunctionOrValue) (args: FSharpMemberOrFunctionOrValue list list) = memb.IsCompilerGenerated && memb.IsInstanceMember @@ -1905,6 +1918,9 @@ let private transformMemberDecl [] elif memb.IsImplicitConstructor then transformPrimaryConstructor com ctx memb args body + // Ignore union case testers for unions with erased union cases + elif isErasedUnionCaseTester memb then + [] // Ignore members generated by the F# compiler (for comparison and equality) elif isCompilerGenerated memb args then [] @@ -2047,8 +2063,8 @@ let rec private transformDeclarations (com: FableCompiler) ctx fsDecls = } ] | sub -> transformDeclarations com ctx sub - | FSharpImplementationFileDeclaration.MemberOrFunctionOrValue(meth, args, body) -> - transformMemberDecl com ctx meth args body + | FSharpImplementationFileDeclaration.MemberOrFunctionOrValue(memb, args, body) -> + transformMemberDecl com ctx memb args body | FSharpImplementationFileDeclaration.InitAction fe -> let ctx = { ctx with UsedNamesInDeclarationScope = HashSet() } let e = transformExpr com ctx [] fe |> run