Skip to content

generic types parameter asserts the compiler (#2) #22647

@dagan-deon

Description

@dagan-deon

Description

proc c0(n: static int): int = 8
proc c1(n: static int): int = n div 2
proc c2(n: static int): int = n * 2

type
  a[N: static int] = object
    f0 : array[N, int]

  b[N: static int] = object
    f0 : a[c0(N)]  # does not work
    f1 : a[c1(N)]  # does not work
    f2 : a[c2(N)]  # does not work
    f3 : a[N * 2]  # does not work
    f4 : a[N]      # works

proc p[N: static int](x : a[N]) = echo x.f0[0]
proc p[N: static int](x : b[N]) =
  x.f0.p()
  x.f1.p()
  x.f2.p()
  x.f3.p()
  x.f4.p()

var x: b[4]
x.p()

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-09-05
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 8f7aedb
active boot switches: -d:release

Current Output

......................................................................assertions.nim(34)       raiseAssert
Error: unhandled exception: int128.nim(66, 11) `arg.sdata(3) == -1` out of range [AssertionDefect]

shell returned 1

Expected Output

No response

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions