Skip to content

Regression from Nim 1.6 to Nim 2.0/devel with generic object and templates #22490

@tersec

Description

@tersec

Description

proc log2trunc(x: uint64): int =
  if x == 0: int(0) else: int(0)
template maxChunkIdx(T: typedesc): int64 = 0'i64
template layer(vIdx: int64): int = log2trunc(0'u64)
type HashList[T] = object
  indices: array[int(layer(maxChunkIdx(T))), int]

This compiles on Nim 1.6, but not on either Nim 2.0 or devel.

Nim Version

Nim Compiler Version 1.6.15 [Linux: amd64]
Compiled at 2023-08-16
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: a2521b1dc7efc775b6cf9a299b51eee44fbd3e81
active boot switches: -d:release
Nim Compiler Version 2.0.1 [Linux: amd64]
Compiled at 2023-08-16
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 037f536e7ee25c4baf23dff8a4525825c506442c
active boot switches: -d:release
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-08-16
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: ade75a148332e670244a719202f7f0337d2e469a
active boot switches: -d:release

Current Output

a.nim(6, 27) Error: type mismatch
Expression: layer(maxChunkIdx(T))
  [1] maxChunkIdx(T): typeof(maxChunkIdx(T))

Expected one of (first mismatch at [position]):
[1] template layer(vIdx: int64): int

Expected Output

No response

Possible Solution

No response

Additional Information

No response

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