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

[typetraits] echo A[B] prints differently depending on unrelated code #8569

Closed
timotheecour opened this issue Aug 8, 2018 · 5 comments · Fixed by #11678
Closed

[typetraits] echo A[B] prints differently depending on unrelated code #8569

timotheecour opened this issue Aug 8, 2018 · 5 comments · Fixed by #11678

Comments

@timotheecour
Copy link
Member

timotheecour commented Aug 8, 2018

import typetraits

type
  C[T] = object

type MyInt = int
type C2=C

when defined(case1):
  echo C2[int]   # C2[system.int]
  echo C2[MyInt] # C2[system.int]

when defined(case2):
  echo C2[MyInt]  # C2[t01_resolveTypeName2.MyInt]
  echo C2[int]    # C2[t01_resolveTypeName2.MyInt]

# EDIT: using `name` instead of `$` doesn't make a difference, unlike test case for related issue https://github.com/nim-lang/Nim/issues/7976#issuecomment-395246665
when defined(case3):
  echo C2[MyInt].name #C2[t01_resolveTypeName2.MyInt]
  echo C2[int].name #C2[t01_resolveTypeName2.MyInt]

when defined(case4):
  echo C2[int].name #C2[system.int]
  echo C2[MyInt].name #C2[system.int]

NOTE: related to, but probably not identical, to #8570, see note there

@andreaferretti
Copy link
Collaborator

(you don't have to prefix all issues with BUG, that's kind of the point of an issue tracker :-D)

@timotheecour timotheecour changed the title BUG [typetraits] echo A[B] prints differently depending on unrelated code [typetraits] echo A[B] prints differently depending on unrelated code Aug 8, 2018
@timotheecour
Copy link
Member Author

timotheecour commented Aug 8, 2018

Note: #7976 seems super related to this [EDIT] ; it's not an actual duplicate because:

  • this issue is for generics, whereas other one for tuple
  • in this issue, using name vs $ makes no difference, but for other one it makes the bug disappear

@jangko
Copy link
Contributor

jangko commented Aug 15, 2018

looks like both of this issue and #7976 have something in common:

and I think it might also plaguing macros.getTypeXXX family.

@Araq
Copy link
Member

Araq commented Aug 15, 2018

@jangko Well the compiler is allowed to cache generic instantiations ignoring type aliases. I don't think it's that bad, macro code that uses getType and friends needs to be written in a robust way.

@mratsim
Copy link
Collaborator

mratsim commented Oct 2, 2018

I find it quite hard to just write getType macro code, see https://github.com/nim-lang/Nim/issues/7719 / nim-lang/RFCs#44, making it robust is very hard, see for example this stress test: #8531 (comment).

Araq pushed a commit that referenced this issue Aug 31, 2019
…8569 #8083  #8570 (#11678)

* nested typeToString
* typeToString: preferResolved
* add test
* fix test
* preferMixed
* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants