From 8a6fa584e194fc1c24a1b19863a9ff0ee35ccb5c Mon Sep 17 00:00:00 2001 From: saem Date: Sat, 24 Aug 2024 16:07:01 -0700 Subject: [PATCH 1/4] existing import tests now properly use knownissue --- .../importstmt/ttyped_import_nimskull757.nim | 21 +------------ .../ttyped_import_nimskull757_knownissues.nim | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 tests/lang_stmts/importstmt/ttyped_import_nimskull757_knownissues.nim diff --git a/tests/lang_stmts/importstmt/ttyped_import_nimskull757.nim b/tests/lang_stmts/importstmt/ttyped_import_nimskull757.nim index 9c438428fda..4f9327d583d 100644 --- a/tests/lang_stmts/importstmt/ttyped_import_nimskull757.nim +++ b/tests/lang_stmts/importstmt/ttyped_import_nimskull757.nim @@ -39,23 +39,4 @@ outputTyped: import mqux3 except bar3 import mqux4 except bar4, baz4 # import as output might have issues, see below - import mqux5 as mqux6 - -when false: # knownIssue: `import except` doesn't preserve exclusion info - # test should check for output: - # ImportExceptStmt - # Sym "mqux3" - # Sym "bar3" - # ImportExceptStmt - # Sym "mqux4" - # Sym "bar4" - # Sym "baz4" - outputTyped: - import mqux3 except bar3 - import mqux4 except bar4, baz4 - -when false: # knownIssue: `Import as` doesn't preserve original identifier info - # not quite sure what the test should be yet, current behaviour might be - # acceptable, because the symbol decl can be introspected? - outputTyped: - import mqux5 as mqux6 \ No newline at end of file + import mqux5 as mqux6 \ No newline at end of file diff --git a/tests/lang_stmts/importstmt/ttyped_import_nimskull757_knownissues.nim b/tests/lang_stmts/importstmt/ttyped_import_nimskull757_knownissues.nim new file mode 100644 index 00000000000..033a0a08c47 --- /dev/null +++ b/tests/lang_stmts/importstmt/ttyped_import_nimskull757_knownissues.nim @@ -0,0 +1,31 @@ +discard """ + description: "Test import statements are properly analysed" + knownissue: "`import except` doesn't preserve exclusion info" + output: ''' +StmtList + ImportExceptStmt + Sym "mqux3" + Sym "bar3" + ImportExceptStmt + Sym "mqux4" + Sym "bar4" + Sym "baz4" +''' +""" + +import std/macros + +macro outputTyped(n: typed) = + let output = treeRepr n + quote: + echo `output` + +outputTyped: + import mqux3 except bar3 + import mqux4 except bar4, baz4 + +when false: # knownIssue: `Import as` doesn't preserve original identifier info + # not quite sure what the test should be yet, current behaviour might be + # acceptable, because the symbol decl can be introspected? + outputTyped: + import mqux5 as mqux6 \ No newline at end of file From b1bae64593612685da12b5cf7f0892e697d19e13 Mon Sep 17 00:00:00 2001 From: saem Date: Sat, 24 Aug 2024 16:07:55 -0700 Subject: [PATCH 2/4] fix relative import of modules from current dir includes a test --- compiler/modules/importer.nim | 24 ++++++++++++++++++- .../importstmt/timport_relative.nim | 7 ++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/lang_stmts/importstmt/timport_relative.nim 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 From 8fcb356a01175cbb2bcee1e41db094982b69f4c6 Mon Sep 17 00:00:00 2001 From: Saem Ghani Date: Sat, 24 Aug 2024 16:47:32 -0700 Subject: [PATCH 3/4] Update compiler/modules/importer.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/modules/importer.nim | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/compiler/modules/importer.nim b/compiler/modules/importer.nim index abe707924f9..396214a3c4f 100644 --- a/compiler/modules/importer.nim +++ b/compiler/modules/importer.nim @@ -378,25 +378,15 @@ proc evalImport*(c: PContext, n: PNode): PNode = for it in n.sons: 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] = + for x in it[1].items: + let imp = newTreeI(nkPrefix, it.info, + it[0], + # transform `./[a as b] to `./a as b` 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: From c1ab4998dff689204c776a53de3162003ddb8f1e Mon Sep 17 00:00:00 2001 From: saem Date: Sat, 24 Aug 2024 16:17:32 -0700 Subject: [PATCH 4/4] make the tests a bit more comprehensive --- tests/lang_stmts/importstmt/timport_relative.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lang_stmts/importstmt/timport_relative.nim b/tests/lang_stmts/importstmt/timport_relative.nim index 02533c454d4..d850993f37e 100644 --- a/tests/lang_stmts/importstmt/timport_relative.nim +++ b/tests/lang_stmts/importstmt/timport_relative.nim @@ -2,6 +2,8 @@ discard """ description: "Regression test for relative imports" """ +# relative to current directory import ./[mbar] import ./[mbaz, mfoo] -import ./[mqux1 as mqux] \ No newline at end of file +import ./[mqux1 as mqux] +import ./mqux2 \ No newline at end of file