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

Symbol binding bug with generics and template #12683

Closed
Clyybber opened this issue Nov 19, 2019 · 5 comments · Fixed by #22564
Closed

Symbol binding bug with generics and template #12683

Clyybber opened this issue Nov 19, 2019 · 5 comments · Fixed by #22564

Comments

@Clyybber
Copy link
Contributor

This doesn't compile but probably should:

Example

module A.nim

import B
heh(0..40, "|")

module B.nim

import unicode
#  v---change to proc to make it compile
template toRune(s: string): Rune = s.runeAt(0)
#     v---works if not generic
proc heh*[T](x: Slice[T], chars: string) = discard chars.toRune

Current Output

Error: attempting to call undeclared routine: 'runeAt'

Expected Output

Hint: operation successful
$ nim -v
Nim Compiler Version 1.1.1 (#devel)
@mratsim
Copy link
Collaborator

mratsim commented Nov 19, 2019

Mentioned in the manual, you should not use method call syntax to invoke templates
https://nim-lang.org/docs/manual.html#templates-limitations-of-the-method-call-syntax

import unicode
#  v---change to proc to make it compile
template toRune(s: string): Rune =
  runeAt(s, 0)

#     v---works if not generic
proc heh*[T](x: Slice[T], chars: string) = discard chars.toRune

@Clyybber
Copy link
Contributor Author

But the compiler could do symbol lookup and typechecking at instantiation on the chars parameter just fine, because the char parameter is not a generic.
I guess this would require some kind of partial instantiation of the generics body.
Anyways this can and should work IMO.

@Araq Araq reopened this Nov 19, 2019
@Araq
Copy link
Member

Araq commented Nov 19, 2019

The limitations only affect untyped parameters.

@mratsim
Copy link
Collaborator

mratsim commented Nov 19, 2019

I guess with have to put that in the #8677 bucket along with its new friends #6387, #11800, #11811, #11947

@metagn
Copy link
Collaborator

metagn commented Aug 26, 2023

Seems to work in 2.0

metagn added a commit to metagn/Nim that referenced this issue Aug 27, 2023
closes nim-lang#12582, closes nim-lang#19552, closes nim-lang#2465, closes nim-lang#4596, closes nim-lang#15246,
closes nim-lang#12683, closes nim-lang#7889, closes nim-lang#4547, closes nim-lang#12415, closes nim-lang#2002,
closes nim-lang#1771, closes nim-lang#5121

The test for nim-lang#5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.
@Araq Araq closed this as completed in c19fd69 Aug 27, 2023
narimiran pushed a commit that referenced this issue Sep 18, 2023
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test

(cherry picked from commit c19fd69)
narimiran pushed a commit that referenced this issue Sep 18, 2023
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test

(cherry picked from commit c19fd69)
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.

4 participants