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

Given proc and type from two different modules named the same thing, Nim prefers the type #9156

Open
AlexMax opened this issue Oct 2, 2018 · 3 comments

Comments

@AlexMax
Copy link

AlexMax commented Oct 2, 2018

a.nim

type
  foo* = object
    x: int
    y: int

b.nim

type
  testing* = object
    z: int

proc foo*(t: testing) =
  echo "doink!"

c.nim

import a, b

var x: testing
x.foo

If you then compile c, this results in an error like:

c.nim(4, 2) Error: type mismatch: got <testing> but expected 'foo = object'

It looks to me that given the ambiguous identifier foo, nim prioritizes the type over the proc.

This is unexpected behavior. Usually, if you have a naming conflict between two modules (for example, two procs or two types named the same thing), you get the following error message:

c.nim(3, 9) Error: ambiguous identifier: 'foo' --use a.foo or b.foo

And of course, if you try defining a type and a proc with the same name in a single module, you get another error.

c.nim(6, 6) Error: redefinition of 'foo'; previous declaration here: c.nim(2, 2)

So for consistency's sake, it seems like Nim should error if there's a naming conflict between a type and a proc in two different modules.

EDIT: It's worth mentioning that you don't really encounter this issue if you follow NEP1. Still, not everything does.

@dom96
Copy link
Contributor

dom96 commented Oct 3, 2018

This is a bug, but please follow NEP1, it's there for a reason.

@metagn
Copy link
Collaborator

metagn commented Aug 25, 2024

Works now and in 2.0

Araq pushed a commit that referenced this issue Aug 30, 2024
closes #1969, closes #7547, closes #7737, closes #11838, closes #12283,
closes #12714, closes #12720, closes #14053, closes #16118, closes
#19670, closes #22645

I was going to wait on these but regression tests even for recent PRs
are turning out to be important in wide reaching PRs like #24010.

The other issues with the working label felt either finnicky (#7385,
#9156, #12732, #15247), excessive to test (#12405, #12424, #17527), or I
just don't know what fixed them/what the issue was (#16128: the PR link
gives a server error by Github, #12457, #12487).
@metagn
Copy link
Collaborator

metagn commented Sep 16, 2024

It looks to me that given the ambiguous identifier foo, nim prioritizes the type over the proc.

The opposite is true in case of calls, in this case the foo in x.foo is treated like a regular expression which makes a symchoice since #23123 and overload resolution on symchoices only considers routines (this also happens in normal calls if type symbols are ambiguous). But this isn't mentioned in the spec, this should be done if a test is added for this, or maybe reconsidered.

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

No branches or pull requests

3 participants