diff options
Diffstat (limited to 'chapter16/src/main')
| -rw-r--r-- | chapter16/src/main/java/com/seaofnodes/simple/node/SubNode.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/chapter16/src/main/java/com/seaofnodes/simple/node/SubNode.java b/chapter16/src/main/java/com/seaofnodes/simple/node/SubNode.java index a433ca90..237e40ed 100644 --- a/chapter16/src/main/java/com/seaofnodes/simple/node/SubNode.java +++ b/chapter16/src/main/java/com/seaofnodes/simple/node/SubNode.java @@ -42,11 +42,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 ) |
