diff options
-rw-r--r-- | changelogs/changelog_2_0_0.md | 2 | ||||
-rw-r--r-- | compiler/options.nim | 7 | ||||
-rw-r--r-- | tests/import/t22065.nim | 5 |
3 files changed, 13 insertions, 1 deletions
diff --git a/changelogs/changelog_2_0_0.md b/changelogs/changelog_2_0_0.md index 42c25946a..76f1a2c92 100644 --- a/changelogs/changelog_2_0_0.md +++ b/changelogs/changelog_2_0_0.md @@ -260,6 +260,8 @@ - `strutils.split` and `strutils.rsplit` now forbid an empty separator. +- Relative imports will not resolve to stdlib anymore, e.g. `import ./tables` now reports an error properly. + ## Standard library additions and changes [//]: # "Changes:" diff --git a/compiler/options.nim b/compiler/options.nim index 7e9e37384..082caedf1 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -910,6 +910,7 @@ proc findFile*(conf: ConfigRef; f: string; suppressStdlib = false): AbsoluteFile proc findModule*(conf: ConfigRef; modulename, currentModule: string): AbsoluteFile = # returns path to module var m = addFileExt(modulename, NimExt) + var hasRelativeDot = false if m.startsWith(pkgPrefix): result = findFile(conf, m.substr(pkgPrefix.len), suppressStdlib = true) else: @@ -923,7 +924,11 @@ proc findModule*(conf: ConfigRef; modulename, currentModule: string): AbsoluteFi else: # If prefixed with std/ why would we add the current module path! let currentPath = currentModule.splitFile.dir result = AbsoluteFile currentPath / m - if not fileExists(result): + if m.startsWith('.') and not fileExists(result): + result = AbsoluteFile "" + hasRelativeDot = true + + if not fileExists(result) and not hasRelativeDot: result = findFile(conf, m) patchModule(conf) diff --git a/tests/import/t22065.nim b/tests/import/t22065.nim new file mode 100644 index 000000000..dfd87a107 --- /dev/null +++ b/tests/import/t22065.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "cannot open file: ./sugar" +""" + +import ./sugar \ No newline at end of file |