Skip to content

Commit

Permalink
fix(compiler): adding a guard on compileLetMutSet if we are passed so…
Browse files Browse the repository at this point in the history
…mething that isn't a symbol as the name of the variable
  • Loading branch information
SuperFola committed May 27, 2024
1 parent 5cd4c4e commit c7d2b75
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- `arkscript --version` and `arkscript --help` now output ArkScript version with the commit hash
- `void Value::toString(std::ostream&, VM&)` now becomes `std::string Value::toString(VM&)`
- removed `Node::operator<<` to replace it with `Node::debugPrint`
- fixed a bug in the compiler where one could pass a non symbol to `let`, `mut` or `set`, resulting in a compiler crash

### Removed
- removed unused `NodeType::Closure`
Expand Down
3 changes: 3 additions & 0 deletions src/arkreactor/Compiler/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ namespace Ark

void Compiler::compileLetMutSet(const Keyword n, const Node& x, const int p)
{
if (const auto sym = x.constList()[1]; sym.nodeType() != NodeType::Symbol)
throwCompilerError(fmt::format("Expected a symbol, got a {}", typeToString(sym)), sym);

const std::string name = x.constList()[1].string();
uint16_t i = addSymbol(x.constList()[1]);
if (n != Keyword::Set)
Expand Down
2 changes: 2 additions & 0 deletions tests/errors/compiler/let_no_sym.ark
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(let foo (fun () ()))
(let (foo a b) 5)
6 changes: 6 additions & 0 deletions tests/errors/compiler/let_no_sym.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
At ( @ 2:7
1 | (let foo (fun () ()))
2 | (let (foo a b) 5)
| ^
3 |
let needs a symbol

0 comments on commit c7d2b75

Please sign in to comment.