Skip to content

Commit

Permalink
fixed issue in the interpreter where values assigned in decls were no…
Browse files Browse the repository at this point in the history
…t converted to the defined type
  • Loading branch information
lausdahl committed Sep 16, 2024
1 parent ad798d7 commit 4e1702b
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,17 @@ public Value caseAVariableDeclaration(AVariableDeclaration node, Context questio

Value initialValue = node.getInitializer() == null ? new UndefinedValue() : node.getInitializer().apply(this, question);

if (initialValue.isNumeric()) {
if (initialValue.deref().isNumeric()) {
Class<? extends Value> targetValueType = typeValueMappings.get(node.getType().getClass());

if (targetValueType != null) {

//we need to upcast all values explicitly here
NumericValue upcasted = ((NumericValue) initialValue).upCast((Class<? extends NumericValue>) targetValueType);
NumericValue upcasted = ((NumericValue) initialValue.deref()).upCast((Class<? extends NumericValue>) targetValueType);

if (upcasted == null) {
throw new InterpreterException(
String.format("Initializer value could not be upcasted. In ", initialValue.toString()) + "initializer is " +
String.format("Initializer value could not be upcasted. In ", initialValue.deref().toString()) + "initializer is " +
"specified: " + node.getName() + " in " + node);
}
initialValue = upcasted;
Expand Down

0 comments on commit 4e1702b

Please sign in to comment.