summaryrefslogtreecommitdiff
path: root/chapter22/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'chapter22/src/main')
-rw-r--r--chapter22/src/main/java/com/seaofnodes/simple/node/SubNode.java10
1 files changed, 5 insertions, 5 deletions
diff --git a/chapter22/src/main/java/com/seaofnodes/simple/node/SubNode.java b/chapter22/src/main/java/com/seaofnodes/simple/node/SubNode.java
index 6dbd55cb..2c4fed39 100644
--- a/chapter22/src/main/java/com/seaofnodes/simple/node/SubNode.java
+++ b/chapter22/src/main/java/com/seaofnodes/simple/node/SubNode.java
@@ -32,11 +32,11 @@ public class SubNode extends ArithNode {
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 )