Skip to content

[BS v7] Record keys "method" or "match" not encoded or decoded properly #43

@ryb73

Description

@ryb73

In BuckleScript >= 7, records that contain fields named "match" or "method" will not be properly encoded or decoded by decco. This is not a problem in BuckleScript < 7.

open TestUtils;

[@decco]
type t = {
    method: int,
    match: int,
};

testEncode(
    "encode",
    { method: 1, match: 1 },
    t_encode, {|{"method":1,"match":1}|}
);

Js.Json.parseExn({|{"method":1,"match":1}|})
|> testGoodDecode("decode", t_decode, _, { method: 1, match: 1 });
 FAIL  lib/js/test/__tests__/ReasonNonKeywords.js
  ● encode

    expect(received).toBe(expected) // Object.is equality

    Expected: "{\"method\":1,\"match\":1}"
    Received: "{\"method_\":1,\"match_\":1}"

      at affirm (node_modules/@glennsl/bs-jest/lib/js/src/jest.js:72:40)
      at Object.<anonymous> (node_modules/@glennsl/bs-jest/lib/js/src/jest.js:249:11)

  ● decode

    thrown: Array [
      Array [
        "Failure",
        -2,
      ],
      "Decode error: Not a number (.method_)",
    ]

      18 | 
      19 | function testGoodDecode(name, decode, json, expected) {
    > 20 |   return Jest.test(name, (function (param) {
         |               ^
      21 |                 var match = Curry._1(decode, json);
      22 |                 if (match.tag) {
      23 |                   var match$1 = match[0];

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Object.test (node_modules/@glennsl/bs-jest/lib/js/src/jest.js:248:3)
      at Object.testGoodDecode (lib/js/test/TestUtils.js:20:15)
      at Object.<anonymous> (lib/js/test/__tests__/ReasonNonKeywords.js:64:11)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions