Closed kaushalmodi closed 4 years ago
reduced example: nim e foo.nim
# foo.nim
import os
echo dirExists("/tmp")
This used to work at some point (probably around Nim 19.x).
when ? 1.0.0 gives same error and 0.19.0 gives Error: cannot 'importc' variable at compile time
however, this is annoying so I'm (hopefully) fixing it here: https://github.com/nim-lang/Nim/pull/14143
Also getEnv, existsEnv, putEnv, delEnv, getCurrentDir. The following procs are also the same idea in os and nimscript but are renamed: removeDir -> rmDir, removeFile -> rmFile, moveDir -> mvDir, moveFile -> mvFile, createDir -> mkDir, copyFile -> cpFile, copyDir -> cpDir.
They are renamed for a reason!
Yes, I advocate for that. I don't think any procs should be deleted from nimscript, I just think they should be moved to os
then import/exported. That will allow the renamed procs to be imported with an alias like from os import removeDir as rmDir
, then export rmDir
. This makes maintaining nimscript procs easier, you can find their declarations in the same place their compiled Nim versions are declared. Of course they aren't implemented there, but that's easy to clarify with a doc comment or a code comment in the when defined(nimscript)
branch.
The rmDir
set of operatings could be in a new module std / scripting
but shouldn't be part of os.nim, their design is based on the idea that you can have a "what if" emulation run that doesn't touch your FS.
@Araq Would a fix similar to https://github.com/nim-lang/Nim/commit/3d2459bdc0b6d6236a2cd9209ed81c965ee411a5 fix this too?
I think my fix mostly works. :-)
In
config.nims
, when theos
module is imported and one of these procs are used:existsDir
ordirExists
existsFile
orfileExists
findExe
we get the "ambiguous call" error (because these are defined in both
system
andos
.Example
config.nims
config.nims
in any directorynim temp123
Current Output
Expected Output
Outputs of the echo statements in the above example.
Workaround
import os except existsDir, dirExists, existsFile, fileExists, findExe
, orsystem.
qualifiers with the ambiguous identifiers.Additional Information
This issue is very closely related to https://github.com/nim-lang/Nim/issues/12835 .
This used to work at some point (probably around Nim 19.x).