Skip to content

Commit 9f2eb9d

Browse files
author
Steffen Märcker
committed
Fix type error due to mutating ast element
1 parent 802a5a6 commit 9f2eb9d

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

prism/src/parser/ast/Expression.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,21 @@ public String getResultName()
7575
* when evaluated during model checking?
7676
*/
7777
public abstract boolean returnsSingleValue();
78-
79-
// Override version of deepCopy() from superclass ASTElement (to reduce casting).
8078

79+
// Override version of deepCopy() from superclass (to reduce casting).
8180
@Override
8281
public Expression deepCopy()
8382
{
8483
return (Expression) super.deepCopy();
8584
}
8685

86+
// Override version of clone() from superclass (to reduce casting).
87+
@Override
88+
public Expression clone()
89+
{
90+
return (Expression) super.clone();
91+
}
92+
8793
// Utility methods:
8894

8995
/**

prism/src/parser/visitor/Simplify.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ public Object visitNow(ExpressionBinaryOp e) throws PrismLangException
9393
return e.getOperand2();
9494
if (Expression.isDouble(e.getOperand2()) && e.getOperand2().evaluateDouble() == 0.0) {
9595
// Need to be careful that type is preserved
96-
e.getOperand1().setType(e.getType());
97-
return e.getOperand1();
96+
Expression op = e.getOperand1().clone();
97+
op.setType(e.getType());
98+
return op;
9899
}
99100
if (Expression.isDouble(e.getOperand1()) && e.getOperand1().evaluateDouble() == 0.0) {
100101
// Need to be careful that type is preserved
101-
e.getOperand2().setType(e.getType());
102-
return e.getOperand2();
102+
Expression op = e.getOperand2().clone();
103+
op.setType(e.getType());
104+
return op;
103105
}
104106
break;
105107
case ExpressionBinaryOp.MINUS:
@@ -113,8 +115,9 @@ public Object visitNow(ExpressionBinaryOp e) throws PrismLangException
113115
}
114116
if (Expression.isDouble(e.getOperand2()) && e.getOperand2().evaluateDouble() == 0.0) {
115117
// Need to be careful that type is preserved
116-
e.getOperand1().setType(e.getType());
117-
return e.getOperand1();
118+
Expression op = e.getOperand1().clone();
119+
op.setType(e.getType());
120+
return op;
118121
}
119122
if (Expression.isDouble(e.getOperand1()) && e.getOperand1().evaluateDouble() == 0.0) {
120123
ExpressionUnaryOp simplified = new ExpressionUnaryOp(ExpressionUnaryOp.MINUS, e.getOperand2());
@@ -130,13 +133,15 @@ public Object visitNow(ExpressionBinaryOp e) throws PrismLangException
130133
return e.getOperand2();
131134
if (Expression.isDouble(e.getOperand2()) && e.getOperand2().evaluateDouble() == 1.0) {
132135
// Need to be careful that type is preserved
133-
e.getOperand1().setType(e.getType());
134-
return e.getOperand1();
136+
Expression op = e.getOperand1().clone();
137+
op.setType(e.getType());
138+
return op;
135139
}
136140
if (Expression.isDouble(e.getOperand1()) && e.getOperand1().evaluateDouble() == 1.0) {
137141
// Need to be careful that type is preserved
138-
e.getOperand2().setType(e.getType());
139-
return e.getOperand2();
142+
Expression op = e.getOperand2().clone();
143+
op.setType(e.getType());
144+
return op;
140145
}
141146
if (Expression.isInt(e.getOperand2()) && e.getOperand2().evaluateInt() == 0) {
142147
// Need to be careful that type is preserved

0 commit comments

Comments
 (0)