Skip to content

Commit

Permalink
Prevent reading into undefined variable in pedantic mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SingularityT3 committed Apr 11, 2024
1 parent a674ef3 commit 03a48d7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/nodes/io/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "line_util.h"

extern bool pedantic;

OutputNode::OutputNode(const Token &token, std::vector<Node*> &&nodes)
: Node(token), nodes(std::move(nodes))
{}
Expand Down Expand Up @@ -74,6 +76,7 @@ std::unique_ptr<NodeResult> InputNode::evaluate(PSC::Context &ctx) {
const SimpleVariableSource *simpleSource = dynamic_cast<const SimpleVariableSource*>(resolver.get());
if (simpleSource == nullptr) throw e;
if (ctx.isIdentifierType(simpleSource->getToken())) throw e;
if (pedantic) throw PSC::PedanticError(simpleSource->getToken(), "Reading input into undefined variable");

var = new PSC::Variable(simpleSource->getName(), PSC::DataType::STRING, false, &ctx);
ctx.addVariable(var);
Expand Down

0 comments on commit 03a48d7

Please sign in to comment.