-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: import current dir relative modules (#1432)
## Summary Attempts to import modules using relative import with multiple module syntax like `import ./[foo, bar]` no longer result in an error. Fixes: #1430 ## Details `./some_dir/[foo]` worked because the AST resulted in an `infix` node for the second directory separator `/` , but a `prefix` node when using `./[foo]` , `importEval` now takes this into account. A test has been included along with the fix. Along with this change some preexisting import statement tests were adjusted away from using `when false` to flag known issues to the builtin testament functionality of the `knownissue` field. --------- Co-authored-by: zerbina <[email protected]>
- Loading branch information
Showing
4 changed files
with
54 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
discard """ | ||
description: "Regression test for relative imports" | ||
""" | ||
|
||
# relative to current directory | ||
import ./[mbar] | ||
import ./[mbaz, mfoo] | ||
import ./[mqux1 as mqux] | ||
import ./mqux2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/lang_stmts/importstmt/ttyped_import_nimskull757_knownissues.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |