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

Template calls with no parentheses have type None if proc has the same name #13209

Closed
metagn opened this issue Jan 20, 2020 · 6 comments
Closed

Comments

@metagn
Copy link
Collaborator

metagn commented Jan 20, 2020

Even when the proc has parameters.

Example

proc typing(a: int) =
  echo a

template typing =
  echo "foo"

typing

Current Output

/usercode/in.nim(7, 1) Error: expression 'typing' is of type 'None' and has to be discarded

Expected Output

foo

The typing statement is of node kind OpenSymChoice

$ nim -v
Nim Compiler Version 1.0.4
@SolitudeSF
Copy link
Contributor

SolitudeSF commented Jan 20, 2020

you still need to call the template with ()
nvm

@metagn
Copy link
Collaborator Author

metagn commented Jan 20, 2020

No

@Araq
Copy link
Member

Araq commented Jan 20, 2020

There is no rule in the spec that says "for a choice of symbols, pick the template because templates can be called without ()". And such a rule would be terrible. You overloaded it, you must resolve it, don't make the compiler guess, you might as well might have meant the proc's address.

@Araq Araq closed this as completed Jan 20, 2020
@metagn
Copy link
Collaborator Author

metagn commented Jan 21, 2020

I was just thinking in a void context with no discard, the template wins. But I can see how annoying that would be to implement. The error message took a while for me to decipher though. This isn't as confusing, but demonstrates the lack of information:

proc foo(a: int) = echo a
proc foo(a: string) = echo a

let y = foo

/usercode/in.nim(4, 5) Error: invalid type: 'None' for let

Do I open a seperate issue for this?

@Araq
Copy link
Member

Araq commented Jan 21, 2020

Yes, please.

@metagn
Copy link
Collaborator Author

metagn commented Jan 21, 2020

#6359 reported it already

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

No branches or pull requests

3 participants