Skip to content

Commit a0973fa

Browse files
committed
evaluator: Fix crash when passing void value as attribute value
1 parent 282ae3c commit a0973fa

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

lib/source/pl/core/ast/ast_node_attribute.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,30 @@ namespace pl::core::ast {
128128

129129
std::string getAttributeValueAsString(const auto &value, Evaluator *evaluator) {
130130
auto literalNode = value->evaluate(evaluator);
131-
auto literal = static_cast<ASTNodeLiteral*>(literalNode.get());
131+
auto literal = dynamic_cast<ASTNodeLiteral*>(literalNode.get());
132+
if (literal == nullptr) {
133+
err::E0002.throwError("Void expression used as attribute value", { }, literalNode->getLocation());
134+
}
132135

133136
return literal->getValue().toString(true);
134137
}
135138

136139
u128 getAttributeValueAsInteger(const auto &value, Evaluator *evaluator) {
137140
auto literalNode = value->evaluate(evaluator);
138-
auto literal = static_cast<ASTNodeLiteral*>(literalNode.get());
141+
auto literal = dynamic_cast<ASTNodeLiteral*>(literalNode.get());
142+
if (literal == nullptr) {
143+
err::E0002.throwError("Void expression used as attribute value", { }, literalNode->getLocation());
144+
}
139145

140146
return literal->getValue().toUnsigned();
141147
}
142148

143149
std::string getAttributeValueAsFunctionName(const auto &value, const Attributable *attributable, Evaluator *evaluator) {
144150
auto literalNode = value->evaluate(evaluator);
145-
auto literal = static_cast<ASTNodeLiteral*>(literalNode.get());
151+
auto literal = dynamic_cast<ASTNodeLiteral*>(literalNode.get());
152+
if (literal == nullptr) {
153+
err::E0002.throwError("Void expression used as attribute value", { }, literalNode->getLocation());
154+
}
146155

147156
auto result = literal->getValue().toString(true);
148157

0 commit comments

Comments
 (0)