Skip to content

Commit

Permalink
Generalize
Browse files Browse the repository at this point in the history
  • Loading branch information
bratseth committed Nov 9, 2024
1 parent 7bce1f0 commit ad127ba
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ protected void doVerify(VerificationContext context) {

private void setVariableType(DataType newType, VerificationContext context) {
DataType existingType = context.getVariable(varName);
if (existingType != null && ! newType.equals(existingType)) {
throw new VerificationException(this, "Cannot set variable '" + varName + "' to type " + newType.getName() +
": It is already set to type " + existingType.getName());
DataType mostGeneralType = newType;
if (existingType != null) {
if (existingType.isAssignableTo(newType))
mostGeneralType = newType;
else if (newType.isAssignableTo(existingType))
mostGeneralType = existingType;
else
throw new VerificationException(this, "Cannot set variable '" + varName + "' to type " + newType.getName() +
": It is already set to type " + existingType.getName());
}
context.setVariable(varName, newType);
context.setVariable(varName, mostGeneralType);
}

@Override
Expand Down

0 comments on commit ad127ba

Please sign in to comment.