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

[TODO] type outType = type(10) prints as int literal(10) instead of int #8704

Closed
timotheecour opened this issue Aug 21, 2018 · 4 comments · Fixed by #11678
Closed

[TODO] type outType = type(10) prints as int literal(10) instead of int #8704

timotheecour opened this issue Aug 21, 2018 · 4 comments · Fixed by #11678

Comments

@timotheecour
Copy link
Member

timotheecour commented Aug 21, 2018

# [`type outType = type(10)` prints as `int literal(10)` instead of `int` · Issue #8704 · nim-lang/Nim](https://github.com/nim-lang/Nim/issues/8704)
import typetraits

when defined(case1):
  type outType = type(10)
when defined(case2):
  let x=10
  type outType = type(x)

doAssert int is outType
doAssert outType is int

echo outType.name # BUG: int literal(10)
echo outType # BUG: int literal(10)

echo int.name # ok: int

# BUG: int literal(10) => this one could be due to `https://github.com/nim-lang/Nim/issues/8569` (compiler reuses whatever cached type name was previously found)
echo int

the 1st bug (echo outType.name shown as int literal(10)) looks new
it happens with case1; doesn't happen with case2 (ie only happens with litterals)

the subsequent ones could be due to #8569

@mratsim
Copy link
Collaborator

mratsim commented Aug 21, 2018

Maybe we need a typemod magic (for type modifier), that can catch:

  • literals
  • static
  • lent
  • var

and maybe it can be extended to parameters constraints like {call} as well.

@timotheecour
Copy link
Member Author

timotheecour commented Oct 24, 2018

maybe the new typeof @Araq introduced could be extended to do that?

proc typeof*(x: untyped; mode: TypeOfMode = typeOfIter)

@krux02
Copy link
Contributor

krux02 commented Aug 19, 2019

This is not a bug, it is a feature. The type of 10 is actually an integer literal that knows it's value at compile time. You could complain thet int literal(10) is an ugly name to represent this type though.

@krux02 krux02 closed this as completed Aug 19, 2019
@timotheecour
Copy link
Member Author

timotheecour commented Aug 20, 2019

@krux02 but that feature seems buggy, for example this code prints:

iterator (): int literal(10){.inline, noSideEffect, gcsafe, locks: 0.}

instead of:

iterator (): int {.inline, noSideEffect, gcsafe, locks: 0.}
iterator fun(): auto =
  var x = 12
  yield 10
  yield 20
  yield x

echo type(fun)

here's another case; I fail to see the logic / consistency:

  • int is the only type that behaves this way; eg, float or int32 don't behave like that
  • echo type(10) is different from type T = type(10); echo T
  echo type(10)
  type T = type(10)
  echo T
  echo type(10.2)
  type T2 = type(10.2)
  echo T2

prints:

int
int literal(10)
float64
float64

@timotheecour timotheecour changed the title type outType = type(10) prints as int literal(10) instead of int [TODO] type outType = type(10) prints as int literal(10) instead of int Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants