diff options
Diffstat (limited to 'chapter20/src/main')
| -rw-r--r-- | chapter20/src/main/java/com/seaofnodes/simple/node/SubNode.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/chapter20/src/main/java/com/seaofnodes/simple/node/SubNode.java b/chapter20/src/main/java/com/seaofnodes/simple/node/SubNode.java index 299f33b8..034f2fb1 100644 --- a/chapter20/src/main/java/com/seaofnodes/simple/node/SubNode.java +++ b/chapter20/src/main/java/com/seaofnodes/simple/node/SubNode.java @@ -46,11 +46,11 @@ public class SubNode extends Node { Type t1 = lhs._type; Type t2 = rhs._type; - if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==0 ) - return lhs; - - if( t1.isConstant() && t1 instanceof TypeInteger i && i.value()==0 ) - return new MinusNode(rhs); + // Keep invalid operands for type checking. + if( t1 instanceof TypeInteger x && t2 instanceof TypeInteger y ) { + if( y.isConstant() && y.value()==0 ) return lhs; + if( x.isConstant() && x.value()==0 ) return new MinusNode(rhs); + } // x - (-y) is x+y if( rhs instanceof MinusNode minus ) |
