Skip to content

Commit

Permalink
feat(name resolution): adding test on symbol import error
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFola committed Dec 13, 2024
1 parent 798a164 commit 14bb967
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
11 changes: 0 additions & 11 deletions include/Ark/Files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ namespace Ark::Utils
bytecode[i] = static_cast<uint8_t>(temp[i]);
return bytecode;
}

/**
* @brief Get the canonical relative path from a path
*
* @param path
* @return std::string
*/
inline std::string canonicalRelPath(const std::string& path)
{
return relative(std::filesystem::path(path)).generic_string();
}
}

#endif
4 changes: 2 additions & 2 deletions src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ namespace Ark::internal
if (!scope->get(sym, true).has_value())
throw CodeError(
fmt::format("ImportError: Can not import symbol {} from {}, as it isn't in the package", sym, namespace_.name),
node.filename(),
namespace_.ast->filename(),
namespace_.ast->line(),
namespace_.ast->col(),
sym);
"import");
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/arkreactor/Compiler/Package/ImportSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ namespace Ark::internal
.with_prefix = import.with_prefix,
.symbols = import.symbols,
.ast = std::make_shared<Node>(findAndReplaceImports(x).first) });
x.arkNamespace().ast->setPos(ast.line(), ast.col());
x.arkNamespace().ast->setFilename(ast.filename());
}
// we parsed an import node, return true in the pair to notify the caller
return std::make_pair(x, /* is_import= */ true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import package.b :test)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
At import @ 1:1
1 | (import package.b :test)
| ^~~~~~
2 |
ImportError: Can not import symbol test from b, as it isn't in the package

0 comments on commit 14bb967

Please sign in to comment.