Skip to content

Type mismatch on init of static[T] object with T being a static[U] #11142

Closed
@mratsim

Description

The following works:

type
  MyObjParam = object
    x: int

  MyObj[P: static MyObjParam] = object
    y: int

const P = MyObjParam(x: 2)
let Q = MyObj[P](y: 2)
echo Q

But the following fails

type
  MyObjParam[N: static int] = object
    x: int

  MyObj[P: static MyObjParam] = object
    y: int

const P = MyObjParam[256](x: 2)
let Q = MyObj[P](y: 2)
echo Q

The error is:

Error: cannot instantiate MyObj
got: <static[MyObjParam[256]]((x: 2))>
but expected: <P>

I expect the issue rootcause is closely related to #9679.

Use case: I'm trying to implement a bigint backend for an elliptic curve crypto library. Everything is done modulo a bigint that is known at compile-time. The types are like this:

type
  # https://github.com/status-im/nim-constantine/blob/master/constantine/bigints.nim
  BigInt*[bits: static int] = object
    limbs*: array[bits.wordsRequired, Word]
  
  # https://github.com/status-im/nim-constantine/blob/master/constantine/field_fp.nim
  Fp*[P: static BigInt] = object
    ## P is a prime number
    ## All operations on a field are modulo P
    value: type(P)

I expect that @andreaferretti would also like to use this in Emmy

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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