Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Jun 13, 2024
1 parent 0913c0c commit cbd79c8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
[]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cbd79c8

Please sign in to comment.