diff --git a/compiler/modules/importer.nim b/compiler/modules/importer.nim index 8a5c76566e0..abe707924f9 100644 --- a/compiler/modules/importer.nim +++ b/compiler/modules/importer.nim @@ -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] diff --git a/tests/lang_stmts/importstmt/timport_relative.nim b/tests/lang_stmts/importstmt/timport_relative.nim new file mode 100644 index 00000000000..02533c454d4 --- /dev/null +++ b/tests/lang_stmts/importstmt/timport_relative.nim @@ -0,0 +1,7 @@ +discard """ + description: "Regression test for relative imports" +""" + +import ./[mbar] +import ./[mbaz, mfoo] +import ./[mqux1 as mqux] \ No newline at end of file