Skip to content

Commit

Permalink
feat(name resolution): prevent name collisions with builtins when res…
Browse files Browse the repository at this point in the history
…olving namespaces
  • Loading branch information
SuperFola committed Dec 12, 2024
1 parent bdc50a0 commit a57c872
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ namespace Ark::internal
{
auto [allowed, fqn] = m_scope_resolver.canFullyQualifyName(symbol.string());

if (m_language_symbols.contains(fqn) && symbol.string() != fqn)
{
throw CodeError(
fmt::format(
"Symbol `{}' was resolved to `{}', which is also a builtin name. Either the symbol or the package it's in needs to be renamed to avoid conflicting with the builtin.",
symbol.string(), fqn),
symbol.filename(),
symbol.line(),
symbol.col(),
symbol.repr());
}
if (!allowed)
{
std::string message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(import package.list :reverse)

(print (reverse [1 2 3]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
At reverse @ 3:9
1 | (import package.list :reverse)
2 |
3 | (print (reverse [1 2 3]))
| ^~~~~~~
4 |
Symbol `reverse' was resolved to `list:reverse', which is also a builtin name. Either the symbol or the package it's in needs to be renamed to avoid conflicting with the builtin.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(let reverse (fun (l) l))

0 comments on commit a57c872

Please sign in to comment.