Skip to content

static[T] parameter cannot depend on generic type parameter #7209

@andreaferretti

Description

@andreaferretti

The following

type Modulo[A; M: static[A]] = distinct A

proc `$`[A; M: static[A]](x: Modulo[A, M]): string =
  $(A(x)) & " mod " & $(M)

proc modulo[A](a: A, M: static[A]): Modulo[A, M] = Modulo[A, M](a %% M)

proc `+`[A; M: static[A]](x, y: Modulo[A, M]): Modulo[A, M] =
  (A(x) + A(y)).modulo(M)

when isMainModule:
  echo (3.modulo(7) + 5.modulo(7))

does not compile, while I would expect it to print 1 mod 7. The error is

Error: cannot instantiate Modulo
got: <type A, M>
but expected: <A, M>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions