Skip to content

Commit

Permalink
Fix prototype of anonymous records
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Feb 21, 2019
1 parent 6a96779 commit 0b7fcd3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/fable-library/Types.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Record.prototype.CompareTo = function(other) {
};

export function anonRecord(o) {
return Object.assign(Object.create(Record), o);
return Object.assign(Object.create(Record.prototype), o);
}

export const FSharpRef = declare(function FSharpRef(contents) {
Expand Down
8 changes: 0 additions & 8 deletions src/quicktest/QuickTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,3 @@ let testCaseAsync msg f =
// to Fable.Tests project. For example:
// testCase "Addition works" <| fun () ->
// 2 + 2 |> equal 4

let makeAnonRec() =
{| X = 5; Y = "Foo"; F = fun x y -> x + y |}

testCase "Anonymous records work" <| fun () ->
let r = makeAnonRec()
sprintf "Tell me %s %i times" r.Y (r.F r.X 3)
|> equal "Tell me Foo 8 times"
5 changes: 5 additions & 0 deletions tests/Main/RecordTypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ let tests =
let r = makeAnonRec()
sprintf "Tell me %s %i times" r.Y (r.F r.X 3)
|> equal "Tell me Foo 8 times"
let x = {| Foo = "baz"; Bar = 23 |}
let y = {| Foo = "baz" |}
x = {| y with Bar = 23 |} |> equal true
// x = {| y with Baz = 23 |} |> equal true // Doesn't compile
x = {| y with Bar = 14 |} |> equal false
#endif

testCase "Recursive record does not cause issues" <| fun () ->
Expand Down

0 comments on commit 0b7fcd3

Please sign in to comment.