Skip to content

Generic aliases can cause iterator instantiation to not compile in 1.4.0+ #20268

@beef331

Description

@beef331

What happened?

Using generic aliases in the following way causes iterators instantiation to fail. Looking into it it's due to the Candidate's bindings not pointing to the generic parameters. No clue how to fix it.

type
  RemoteRef*[T] = object
  JoinedRef*[T] = RemoteRef[T]
  MySeqInternal[T] = object
  SpiSeq[T] = JoinedRef[MySeqInternal[T]]

proc doThing*[T](spiSeq: SpiSeq[T]): T = discard default(T)

discard doThing(default(SpiSeq[byte])) # Fine

iterator items*[T](spiSeq: SpiSeq[T]): T = discard default(T) # Errors
iterator items*[T](spiSeq: SpiSeq[T], val: T): T = discard default(T) # Compiles

for i in items(default(SpiSeq[byte])):
  discard

for i in items(default(SpiSeq[byte]), 0):
  discard

Nim Version

Before 1.4 it worked. All versions after it fails instantiation

Current Standard Output Logs

test.nim(13, 15) template/generic instantiation of `items` from here
test.nim(11, 17) Error: cannot instantiate: 'T'

Expected Standard Output Logs

Compile

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions