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

Method syntax in templates doesn't find bound functions that aren't in scope in caller #20073

Closed
RedBeard0531 opened this issue Jul 22, 2022 · 3 comments · Fixed by #22076
Closed

Comments

@RedBeard0531
Copy link
Contributor

Example

a.nim:

# Note: neither of these are exported, but are available in module a
type Foo = object
proc foo(f: Foo) = discard

template works*() =
  var f: Foo
  foo(f)

template boom*() =
  bind foo # tried this, but doesn't help
  var f: Foo
  f.foo() # Error: attempting to call undeclared routine: 'foo'
  f.foo # Error: undeclared field: 'foo' for type a.Foo

b.nim:

import a

works()
boom()

Current Output

> nim r b
Hint: used config file '/home/mstearn/.choosenim/toolchains/nim-1.6.6/config/nim.cfg' [Conf]
Hint: used config file '/home/mstearn/.choosenim/toolchains/nim-1.6.6/config/config.nims' [Conf]
..........................................................
/home/mstearn/nim/realm/b.nim(4, 5) template/generic instantiation of `boom` from here
/home/mstearn/nim/realm/a.nim(11, 4) Error: attempting to call undeclared routine: 'foo'

(Also repros with devel)

Expected Output

should compile

Possible Solution

🤷

Additional Information

This seems to go back to pre 1.0 (I tried 1.2.0 and 0.20.0 in addition to 1.6.6 and devel)

> nim -v
Nim Compiler Version 1.6.6 [Linux: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 0565a70eab02122ce278b98181c7d1170870865c
active boot switches: -d:releas
@beef331
Copy link
Collaborator

beef331 commented Jul 22, 2022

Oddly a mixin instead of bind does make this work.

@metagn
Copy link
Collaborator

metagn commented Jul 23, 2022

If you look in the compiler this seems somewhat intentional.

The problem is it does the "inverse" of what normal calls do. See #20000 and #20004

@metagn
Copy link
Collaborator

metagn commented Jun 11, 2023

This might be different, for some reason both foos in the template body are resolved nkSyms, but during instantiation they revert to nkIdent

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

Successfully merging a pull request may close this issue.

3 participants