From 83802a81f1721987828b1a2d101a228ef0bc35f7 Mon Sep 17 00:00:00 2001 From: ncave <777696+ncave@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:12:36 -0700 Subject: [PATCH] Fixed #3915 --- src/Fable.Transforms/FSharp2Fable.Util.fs | 9 +++++++-- src/Fable.Transforms/Rust/Fable2Rust.fs | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Fable.Transforms/FSharp2Fable.Util.fs b/src/Fable.Transforms/FSharp2Fable.Util.fs index e03de5f1b..6c4ad9db6 100644 --- a/src/Fable.Transforms/FSharp2Fable.Util.fs +++ b/src/Fable.Transforms/FSharp2Fable.Util.fs @@ -1075,8 +1075,13 @@ module Patterns = let (|UnionCaseTesterFor|_|) (memb: FSharpMemberOrFunctionOrValue) = match memb.DeclaringEntity with | Some ent when ent.IsFSharpUnion -> - // if memb.IsUnionCaseTester then // TODO: this currently fails, use when fixed - if memb.IsPropertyGetterMethod && memb.LogicalName.StartsWith("get_Is") then + // if memb.IsUnionCaseTester then // insufficient, could be an interface member + if + memb.IsPropertyGetterMethod + && not memb.IsDispatchSlot + && not memb.IsOverrideOrExplicitInterfaceImplementation + && memb.LogicalName.StartsWith("get_Is") + then let unionCaseName = memb.LogicalName |> Naming.replacePrefix "get_Is" "" ent.UnionCases |> Seq.tryFind (fun uc -> uc.Name = unionCaseName) else diff --git a/src/Fable.Transforms/Rust/Fable2Rust.fs b/src/Fable.Transforms/Rust/Fable2Rust.fs index 11e55adb4..ca896736f 100644 --- a/src/Fable.Transforms/Rust/Fable2Rust.fs +++ b/src/Fable.Transforms/Rust/Fable2Rust.fs @@ -1245,6 +1245,11 @@ module Util = else mkGenericPathExpr (splitNameParts ident.Name) None + let isThisArgumentIdentExpr (expr: Fable.Expr) = + match expr with + | Fable.IdentExpr ident -> ident.IsThisArgument + | _ -> false + // let transformExprMaybeIdentExpr (com: IRustCompiler) ctx (expr: Fable.Expr) = // match expr with // | Fable.IdentExpr ident when ident.IsThisArgument -> @@ -1602,7 +1607,9 @@ module Util = let prepareRefForPatternMatch (com: IRustCompiler) ctx typ (name: string option) fableExpr = let expr = com.TransformExpr(ctx, fableExpr) - if (name.IsSome && isRefScoped ctx name.Value) || (isInRefType com typ) then + if isThisArgumentIdentExpr fableExpr then + expr + elif (name.IsSome && isRefScoped ctx name.Value) || (isInRefType com typ) then expr elif shouldBeRefCountWrapped com ctx typ |> Option.isSome then expr |> makeAsRef @@ -4576,7 +4583,7 @@ module Util = let isIgnoredMember (memb: Fable.MemberFunctionOrValue) = ent.IsFSharpExceptionDeclaration // to filter out compiler-generated exception equality let isInterfaceMember (memb: Fable.MemberFunctionOrValue) = - memb.IsDispatchSlot + (memb.IsDispatchSlot || memb.IsOverrideOrExplicitInterfaceImplementation) && (memb.DeclaringEntity |> Option.bind com.TryGetEntity |> Option.map (fun ent -> ent.IsInterface)