Skip to content

Agree on type alias to decode int as Number instead of BigInt #232

@davidyuk

Description

@davidyuk

Was initially discussed in aeternity/aesophia#351

I propose to decode returned value to Number instead of BigInt if calldata finds a shortint (not sure about name) aliased to int while type resolving.

For example for the contract

contract C =
  type shortint = int
  record rec = { x: shortint }

  entrypoint f(s : shortint) : shortint =
    s * 42

  entrypoint f2() : rec =
    { x = 42 }

ACI would be

[
  {
    "contract": {
      "functions": [
        {
          "arguments": [
            {
              "name": "s",
              "type": "C.shortint"
            }
          ],
          "name": "f",
          "payable": false,
          "returns": "C.shortint",
          "stateful": false
        },
        {
          "arguments": [],
          "name": "f2",
          "payable": false,
          "returns": "C.rec",
          "stateful": false
        }
      ],
      "kind": "contract_main",
      "name": "C",
      "payable": false,
      "typedefs": [
        {
          "name": "shortint",
          "typedef": "int",
          "vars": []
        },
        {
          "name": "rec",
          "typedef": {
            "record": [
              {
                "name": "x",
                "type": "C.shortint"
              }
            ]
          },
          "vars": []
        }
      ]
    }
  }
]

And it looks like ACI preserves enough info to track int alias even in complex structures. Of course, this feature is not urgent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions