Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
timotheecour opened this issue Jul 25, 2018 · 3 comments
Labels

Comments

@timotheecour
Copy link
Member

timotheecour commented Jul 25, 2018

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

@timotheecour timotheecour changed the title seq[int].T is int should compile (and be true), same as user defined generic types seq[int].T is int should compile (and be true) according to spec; also fails with type seq2[T] = T Jul 25, 2018
@zah zah added the Generics label Aug 3, 2018
@timotheecour
Copy link
Member Author

timotheecour commented Aug 3, 2018

@zah actually I kind of dislike this feature MyGeneric.T : it's convenient but can cause hijacking issues in case T is in scope and result doesn't match user expectations. Could a macro achieve same goal (and fix this issue as well as #8459), maybe using same tricks as I used in #8531 for undistinct macro?
eg: extractGeneric(MyGeneric, T)

@zah
Copy link
Member

zah commented Aug 5, 2018

Can you clarify what these hijacking issues are?

@timotheecour
Copy link
Member Author

sent out a PR (which in fact provides better workaround for this issue) and moved discussion there: #8554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants