Skip to content

Commit e878fe7

Browse files
committed
fix: 'and' and 'or' now check that they are given valid nodes, producing outputs
1 parent 1016fef commit e878fe7

5 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,14 @@ namespace Ark::internal
620620
node.string(),
621621
x.constList().size() - 1),
622622
x);
623+
const auto name = node.string(); // and / or
623624

625+
if (!nodeProducesOutput(x.list()[1]))
626+
buildAndThrowError(
627+
fmt::format(
628+
"Can not use `{}' inside a `{}' expression, as it doesn't return a value",
629+
x.list()[1].repr(), name),
630+
x.list()[1]);
624631
compileExpression(x.list()[1], p, false, false);
625632

626633
const auto label_shortcircuit = IR::Entity::Label(m_current_label++);
@@ -629,6 +636,12 @@ namespace Ark::internal
629636

630637
for (std::size_t i = 2, end = x.constList().size(); i < end; ++i)
631638
{
639+
if (!nodeProducesOutput(x.list()[i]))
640+
buildAndThrowError(
641+
fmt::format(
642+
"Can not use `{}' inside a `{}' expression, as it doesn't return a value",
643+
x.list()[i].repr(), name),
644+
x.list()[i]);
632645
compileExpression(x.list()[i], p, false, false);
633646
if (i + 1 != end)
634647
page(p).emplace_back(shortcircuit_entity);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(print (or 1 (mut x 3)))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
In file tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.ark:1
2+
1 | (print (or 1 (mut x 3)))
3+
| ^~~~~~~~
4+
2 |
5+
Can not use `(mut x 3)' inside a `or' expression, as it doesn't return a value
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(print (or (let x 1) 1))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
In file tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.ark:1
2+
1 | (print (or (let x 1) 1))
3+
| ^~~~~~~~
4+
2 |
5+
Can not use `(let x 1)' inside a `or' expression, as it doesn't return a value

0 commit comments

Comments
 (0)