Skip to content

Cannot instantiate Future got: <T> but expected: <T> after bumping nim-chronos #963

@KonradStaniec

Description

@KonradStaniec

After bumping nim-chronos to latest version when trying to run make fluffy following error manifests:

/nimbus-eth1/fluffy/fluffy.nim(112, 27) template/generic instantiation of `installDiscoveryApiHandlers` from here
/nimbus-eth1/fluffy/rpc/rpc_discovery_api.nim(103, 12) template/generic instantiation of `rpc` from here
/nimbus-eth1/vendor/nim-json-rpc/json_rpc/rpcproxy.nim(92, 23) template/generic instantiation of `rpc` from here
/nimbus-eth1/vendor/nim-json-rpc/json_rpc/server.nim(19, 16) template/generic instantiation of `rpc` from here
/nimbus-eth1/vendor/nim-json-rpc/json_rpc/router.nim(158, 56) Error: cannot instantiate Future
got: <T>
but expected: <T>

Imo this error is composed of two parts:

  1. In https://github.com/status-im/nim-json-rpc/blob/master/json_rpc/router.nim#L150, correct return type for seq[Record] should be:
BracketExpr
  Ident "seq"
  Ident "Record"

but what really is there during compilation is:

Call
  OpenSymChoice
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
    Sym "[]"
  Sym "seq"
  Sym "Record"

Which makes me think we hit issue: nim-lang/Nim#11091

  1. Second part of the issue is most probably the fact that after Improve ram usage nim-chronos#243 , our async macro generates iterator which takes generic future as arguments i.e has paramater Future[T].
    New version:
    iterator nameIter(chronosInternalRetFuture: Future[T]): FutureBase
    Old version:
    iterator nameIter(): FutureBase {.closure.}

and we hit some type of the issue : nim-lang/Nim#19358

So even the issue 1 existed from what I can tell always, the old version of chronos macro was not affected, but after the update
correct type cannot be instantiated.

One workaround this is to introduce type alias:

type Records = seq[Record]

then everything builds successfully, of course it does not solve root cause.

I still do not have enough knowledge of the compiler to propose the fix to the root cause, but imo it would be nice if proper BracketExpr was generated in our rpc macro. Wdyt @zah @kdeme ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions