Skip to content

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

Open
@ire4ever1190

Description

@ire4ever1190

Nim Version

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

git hash: 7e8a650
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)

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