Skip to content

Commit

Permalink
Fix #1895: casting anon rec, parent interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Dec 23, 2019
1 parent 8739faa commit 193d185
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/Fable.Transforms/FSharp2Fable.Util.fs
Expand Up @@ -244,14 +244,17 @@ module Helpers =
| None -> false
| _ -> false

let rec getAllInterfaceMembers (ent: FSharpEntity) =
seq {
yield! ent.MembersFunctionsAndValues
for parent in ent.DeclaredInterfaces do
match tryDefinition parent with
| Some(e, _) -> yield! getAllInterfaceMembers e
| None -> ()
}

let rec isInterfaceEmpty (ent: FSharpEntity) =
ent.MembersFunctionsAndValues.Count = 0
&& (if ent.DeclaredInterfaces.Count > 0 then
ent.DeclaredInterfaces |> Seq.forall (fun ifc ->
match tryDefinition ifc with
| Some(e, _) -> isInterfaceEmpty e
| None -> true)
else true)
getAllInterfaceMembers ent |> Seq.isEmpty

/// Test if the name corresponds to this interface or anyone in its hierarchy
let rec testInterfaceHierarcy interfaceFullname interfaceType =
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Replacements.fs
Expand Up @@ -1124,7 +1124,7 @@ let fableCoreLib (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp
| NewAnonymousRecord(_, exprs, fieldNames, _, _),
[_; (_,DeclaredType(ent, []))] when ent.IsInterface ->
// TODO: Check also if there are extra fields in the record not present in the interface?
(None, ent.MembersFunctionsAndValues |> Seq.filter (fun memb -> memb.IsPropertyGetterMethod))
(None, FSharp2Fable.Helpers.getAllInterfaceMembers ent |> Seq.filter (fun memb -> memb.IsPropertyGetterMethod))
||> Seq.fold (fun err memb ->
match err with
| Some _ -> err
Expand Down
File renamed without changes.

0 comments on commit 193d185

Please sign in to comment.