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

Inconsistent compilation error between generic procs: proc x[T]() vs. proc y(T: type) #15760

Closed
jangko opened this issue Oct 28, 2020 · 1 comment · Fixed by #22581
Closed

Comments

@jangko
Copy link
Contributor

jangko commented Oct 28, 2020

Example

type
  Banana = object
  SpecialBanana = object
  
proc getName(_: type Banana): string = "Banana"
proc getName(_: type SpecialBanana): string = "SpecialBanana"

proc x[T]() = 
  const n = getName(T) # this one works
  echo n
  
proc y(T: type) =
  const n = getName(T) # this one failed to compile
  echo n

x[SpecialBanana]()
y(SpecialBanana)

Current Output

F:\projects\bug\special_banana.nim(17, 2) template/generic instantiation of `y` from here
F:\projects\bug\special_banana.nim(13, 21) Error: cannot evaluate at compile time: T

Expected Output

SpecialBanana
SpecialBanana

I consider both x and y as generic proc, but the compiler seems evaluate y too eagerly / too early.

@metagn
Copy link
Collaborator

metagn commented Oct 29, 2020

This seems like a such a simple bug, are there similar other issues? The workaround here is to use typeof T as one would expect

metagn added a commit to metagn/Nim that referenced this issue Aug 29, 2023
metagn added a commit to metagn/Nim that referenced this issue Aug 29, 2023
Araq pushed a commit that referenced this issue Aug 30, 2023
* handle typedesc params in VM

fixes #15760

* add test

* fix getType(typedesc) test
narimiran pushed a commit that referenced this issue Sep 11, 2023
* handle typedesc params in VM

fixes #15760

* add test

* fix getType(typedesc) test

(cherry picked from commit 2e4e2f8)
narimiran pushed a commit that referenced this issue Sep 18, 2023
* handle typedesc params in VM

fixes #15760

* add test

* fix getType(typedesc) test

(cherry picked from commit 2e4e2f8)
narimiran pushed a commit that referenced this issue Sep 18, 2023
* handle typedesc params in VM

fixes #15760

* add test

* fix getType(typedesc) test

(cherry picked from commit 2e4e2f8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants