Skip to content

Conflict between stew.init and blsCurve.init #9

@mratsim

Description

@mratsim

It seems like the init scheme here is a too general (with auto) and causes issue with bls curve init from status-im/nim-blscurve#26

template init*(lvalue: var auto) =
mixin init
lvalue = init(type(lvalue))
template init*(lvalue: var auto, a1: auto)=
mixin init
lvalue = init(type(lvalue), a1)
template init*(lvalue: var auto, a1, a2: auto) =
mixin init
lvalue = init(type(lvalue), a1, a2)
template init*(lvalue: var auto, a1, a2, a3: auto) =
mixin init
lvalue = init(type(lvalue), a1, a2, a3)

proc init*[T: SigKey|VerKey|Signature](obj: var T,
                                       data: openarray[byte]): bool {.inline.} =
  ## Initialize ``SignatureKey``, ``VerificationKey`` or ``Signature`` from
  ## raw binary representation ``data``.
  ##
  ## Procedure returns ``true`` on success and ``false`` otherwise.
  when T is SigKey:
    result = obj.x.fromBytes(data)
  else:
    result = obj.point.fromBytes(data)

The error thrown is especially hard to debug

../beacon_chain/spec/crypto.nim(195, 7) template/generic instantiation from here
../beacon_chain/spec/crypto.nim(186, 18) template/generic instantiation from here
../beacon_chain/spec/crypto.nim(125, 21) Error: expression '
buffer = init(type(buffer), a.blob)' has no type (or is ambiguous)

corresponding to this line:

  let success = buffer.init(a.blob)

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