Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Can't access generic parameters in a generic alias that don't appear in aliased type

Open ire4ever1190 opened this issue 7 months ago • 1 comments

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64] Compiled at 2025-02-28 Copyright (c) 2006-2025 by Andreas Rumpf

git hash: 7e8a650729e9434574c46350aece7609e5465253 active boot switches: -d:release

Description

When accessing a generic field from a generic alias it only allows accessing what it aliases.

import std/options

type
  Foo[D: static int; T] = T
  Bar[D] = Option[D]
  Bizz = Foo[9, string]
  Buzz = Foo[9, Option[string]]

echo Bar[string].D # undeclared field: 'D'
echo Bizz.D # 9
echo Buzz.D # undeclared field: 'D'

The Foo example is a bit more useful since it allows you to attach metadata to types without needing to resort to macros.

Current Output

test.nim(9, 17) Error: undeclared field: 'D'
test.nim(11, 10) Error: undeclared field: 'D'

Expected Output

string
9
9

Known Workarounds

No response

Additional Information

I've tracked the issue down to when it calls readTypeParameter it just skips past the alias if both are generics and so the fields on the alias cant be accessed (unless they share the same name)

ire4ever1190 avatar Mar 20 '25 10:03 ire4ever1190