Skip to content

seq[int].T is int should compile (and be true) according to spec; also fails with type seq2[T] = T  #8433

Open
@timotheecour

Description

@timotheecour
import typetraits

when defined(case_ok):
  # ok
  block:
    type seq2[T] = (T,int)
    echo seq2[int].T
    doAssert seq2[int].T is int
  block:
    type seq2[T] = (T,)
    echo seq2[int].T
  block:
    type seq2[T] = int
    echo seq2[int].T
  block:
    type seq2[T] = object
      discard
    echo seq2[int].T

when defined(case2):
  type seq2[T] = T
  # Error: undeclared field: 'T'
  echo seq2[int].T

when defined(case_seq):
  # Error: undeclared field: 'T'
  echo seq[int].T

this breaks generic code and user defined concepts isSeq that check whether some type is a seq[T] for some T

  • likewise for other magic types in system.nim

NOTE: this should be feasible according to (my interpretation of) docs:

Procs written with the implicitly generic style will often need to refer to the type parameters of the matched generic type. They can be easily accessed using the dot syntax:
type Matrix[T, Rows, Columns] = object
proc [](m: Matrix, row, col: int): Matrix.T =

in any case it's useful

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions