Skip to content

Commit

Permalink
fix relative import of modules from current dir
Browse files Browse the repository at this point in the history
includes a test
  • Loading branch information
saem committed Aug 24, 2024
1 parent 8a6fa58 commit b1bae64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
24 changes: 23 additions & 1 deletion compiler/modules/importer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,29 @@ proc evalImport*(c: PContext, n: PNode): PNode =
var hasError = false

for it in n.sons:
if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
if it.kind == nkPrefix and it.len == 2 and it[1].kind == nkBracket:
let
sep = it[0]
impTmpl =
block:
let t = newNodeI(nkPrefix, it.info, 2)
t[0] = sep
t
## `impTmpl` is copied/instanced in a loop below including setting
## the second child

for x in it[1]:
let imp = copyTree(impTmpl)

# transform `./[a as b] to `./a as b`
imp[1] =
if x.kind == nkInfix and x[0].ident.s == "as":
x[1]
else:
x

hasError = impMod(c, imp, x.info, result).kind == nkError or hasError
elif it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
let
sep = it[0]
dir = it[1]
Expand Down
7 changes: 7 additions & 0 deletions tests/lang_stmts/importstmt/timport_relative.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
discard """
description: "Regression test for relative imports"
"""

import ./[mbar]
import ./[mbaz, mfoo]
import ./[mqux1 as mqux]

0 comments on commit b1bae64

Please sign in to comment.