nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

import os + use of paramCount and paramStr in config.nims causes "ambiguous call' error #12835

Closed kaushalmodi closed 4 years ago

kaushalmodi commented 4 years ago

In config.nims, when the os module is imported and paramCount and/or paramStr are used, we get the "ambiguous call" error (because these two are defined in both system and os.

Example config.nims

import os # commenting this out fixes the error
# import os except paramCount, paramStr # this also does not give that error

task temp123, "Temp task":
  let
    numParams = paramCount()
  for i in 1 .. numParams:
    echo paramStr(i)

Current Output

/home/kmodi/sandbox/nim/aoc2019/config.nims(3, 6) template/generic instantiation of `task` from here
/home/kmodi/sandbox/nim/aoc2019/config.nims(5, 27) Error: ambiguous call; both system.paramCount() [declared in /home/kmodi/usr_local/apps/6/nim/devel/lib/system/nimscript.nim(65, 6)] and os.paramCount() [declared in /home/kmodi/usr_local/apps/6/nim/devel/lib/pure/os.nim(2613, 8)] match for: ()

Expected Output

No error

Workaround

Additional Information

$ nim -v
Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2019-12-05
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 3fbb3bfd3f440c059d6290c12834a38a61da98f2
active boot switches: -d:release

This used to work at some point (probably around Nim 19.x).

genotrance commented 4 years ago

We have to do the same thing in nimble as well today.

https://github.com/nim-lang/nimble/blob/master/src/nimblepkg/nimscriptwrapper.nim#L118

nc-x commented 4 years ago

Not a bug? Even outside of nimscript, name clashes are possible and you need to use qualified names.

kaushalmodi commented 4 years ago

Even outside of nimscript, name clashes are possible and you need to use qualified names.

Is this a slightly different case though?

The name clashes are understood when the they happen among two or more user-imported modules.

In this case, it happens between the implicitly imported system and user imported os.

I believe there was already an internal way in the packages to determine if an stdlib module is imported in a NimScript. If so, something special can probably done to prevent this name clash on doing import os.

SolitudeSF commented 4 years ago

os defines param* as error for nimscript and other targets. Error: unhandled exception: paramCount is not implemented on Nintendo Switch [OSError] this is clearly not right.

nc-x commented 4 years ago

@kaushalmodi https://github.com/nim-lang/Nim/pull/12860

Please send similar PR for any more such issue :)

kaushalmodi commented 4 years ago

@nc-x Thank you for working on a PR to fix this!

I would have liked to send a PR to fix this myself, but looking at your PR, I don't think I would have been able to make those fixes myself. But I am always trying ..

nc-x commented 4 years ago

@kaushalmodi the original PR was much simpler. It just removed the proc declarations from os.nim for nimscript. And it passed all the tests, unlike now :)