Skip to content

Commit

Permalink
Fix #1895: anonymous record !! casting warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Sep 4, 2019
1 parent 3f17b1d commit bb39da2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Fable.Transforms/Replacements.fs
Expand Up @@ -270,6 +270,15 @@ let (|IEnumerable|IEqualityComparer|Other|) = function
| _ -> Other
| _ -> Other

let (|NewAnonymousRecord|_|) e =
let rec inner bindings = function
// The F# compiler may create some bindings of expression arguments to fix https://github.com/dotnet/fsharp/issues/6487
| Let(newBindings, body) -> inner (bindings @ newBindings) body
| Value(NewRecord(exprs, AnonymousRecord fieldNames, genArgs), r) ->
Some(List.rev bindings, exprs, fieldNames, genArgs, r)
| _ -> None
inner [] e

let coreModFor = function
| BclGuid -> "String"
| BclDateTime -> "Date"
Expand Down Expand Up @@ -1116,17 +1125,15 @@ let fableCoreLib (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp
| "op_BangHat", [arg] -> Some arg
| "op_BangBang", [arg] ->
match arg, i.GenericArgs with
| Value(NewRecord(exprs, Fable.AnonymousRecord fieldNames, _),_),
| 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.fold (fun err memb ->
(None, ent.MembersFunctionsAndValues |> Seq.filter (fun memb -> memb.IsPropertyGetterMethod))
||> Seq.fold (fun err memb ->
match err with
| Some _ -> err
| None ->
let expectedType =
if memb.IsPropertyGetterMethod then memb.ReturnParameter.Type
else memb.FullType
|> makeType com
let expectedType = memb.ReturnParameter.Type |> makeType com
Array.tryFindIndex ((=) memb.DisplayName) fieldNames
|> function
| None ->
Expand All @@ -1149,8 +1156,7 @@ let fableCoreLib (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp
| Some errMsg ->
addWarning com ctx.InlinePath r errMsg
Some arg
| None ->
List.zip (Array.toList fieldNames) exprs |> objExpr t |> Some
| None -> Some arg
| _ -> Some arg
| "op_Dynamic", [left; memb] -> getExpr r t left memb |> Some
| "op_DynamicAssignment", [callee; prop; MaybeLambdaUncurriedAtCompileTime value] ->
Expand Down

0 comments on commit bb39da2

Please sign in to comment.