Nim
Nim copied to clipboard
Multiple types in a type section that are recursive and make use of static int in their definition fail compilation
Nim Version
Applies to or tried on the following:
Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-05-27
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: 241edaf0c0dc8a7e6a67abb16cb9796bf2f16c4a
active boot switches: -d:release
and
Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-05-02
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: f56568d851eb7f859e6e355495c2be28ac9819e9
active boot switches: -d:release
Description
This fails to compile:
type
P[dim: static int] = ref object
pv: seq[MP[typeof(dim)]]
PH[dim: static int] = ref object
discard
MP[dim: static int] = object
v: float
pfoo: seq[ref P[dim]]
phfoo: seq[ref PH[dim]]
var x = new(P[2])
echo x.pv
Compiles if the static ints are removed. Both versions compile on stable (tried on 2.2.4).
Current Output
Error: undeclared identifier: 'dim'
Expected Output
@[]
Known Workarounds
None
Additional Information
No response
typeof for statics gives the base type (in this case int) since #24718. Weird error still, #24745 might be related.
The version without typeof() gives a type expected warning for all versions.