summaryrefslogtreecommitdiff
path: root/chapter11/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter11/src/test/java')
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter10Test.java13
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java2
2 files changed, 14 insertions, 1 deletions
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index 6969358d..3e97e8e7 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -6,6 +6,19 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class Chapter10Test {
+ @Test public void testDeadReferenceReturn() {
+ for( String body : new String[] {
+ "return new S; return 0;",
+ "if(1) return new S; else return 0;"
+ } ) {
+ String src = "struct S { int x; }; " + body;
+ var stop = new Parser(src).parse().iterate();
+ org.junit.Assert.assertTrue(body,
+ stop.ret().expr()._type instanceof com.seaofnodes.simple.type.TypeMemPtr);
+ }
+ }
+
+
// Issue #246: null-check guards start in Chapter 10; arrays arrive in Chapter 15.
private static final String NULLABLE_POINT_SOURCE = """
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java b/chapter11/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
index 01d471bf..8ff33436 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
@@ -26,7 +26,7 @@ public class PrintTestSupport {
ins.put(n,n._inputs.toArray(new Node[0]));
outs.put(n,n._outputs.toArray(new Node[0]));
hashes.put(n,hash.getInt(n));
- if( n instanceof CFGNode cfg ) depths.put(n,cfg._idepth);
+ if( n instanceof CFGNode cfg ) depths.put(n,(int)cfg._idepth);
}
print.run();
for( Node n : nodes ) {