@@ -2091,11 +2091,49 @@ public void fullArrayListTest() throws IOException {
20912091 assertEquals (count , 2 );
20922092
20932093 assertFalse (compiled .contains ("ArrayList_nextFreeIndex_" ));
2094+ // In checked mode, virtual method calls should go through dispatch.
2095+ assertTrue (compiled .contains ("dispatch_ArrayList" ));
2096+ }
2097+
2098+ @ Test
2099+ public void fullArrayListTestUncheckedDispatch () throws IOException {
2100+ test ().withStdLib ().uncheckedDispatch ().executeProg ().executeTests ().file (new File (TEST_DIR + "arrayList.wurst" ));
2101+
2102+ String compiled = Files .toString (
2103+ new File (TEST_OUTPUT_PATH + "GenericsWithTypeclassesTests_fullArrayListTestUncheckedDispatch_no_opts.jim" ),
2104+ Charsets .UTF_8 );
2105+
2106+ // In unchecked dispatch mode, monomorphic ArrayList<T>.get should be lowered directly.
2107+ assertTrue (compiled .contains ("ArrayList_get" ));
2108+ assertFalse (compiled .contains ("dispatch_ArrayList" ));
20942109 }
20952110
20962111 @ Test
20972112 public void fullReactiveGenericDispatchTest () throws IOException {
20982113 test ().withStdLib ().executeProg ().executeTests ().file (new File (TEST_DIR + "reactiveGenericsDispatch.wurst" ));
2114+
2115+ String compiled = Files .toString (
2116+ new File (TEST_OUTPUT_PATH + "GenericsWithTypeclassesTests_fullReactiveGenericDispatchTest_no_opts.jim" ),
2117+ Charsets .UTF_8 );
2118+
2119+ // In checked mode, polymorphic interface calls are dispatched and guarded.
2120+ assertTrue (compiled .contains ("dispatch_ReactiveSource_ReactiveSource_subscribe" ));
2121+ assertTrue (compiled .contains ("Nullpointer exception when calling ReactiveSource.subscribe" ));
2122+ assertTrue (compiled .contains ("Called ReactiveSource.subscribe on invalid object." ));
2123+ }
2124+
2125+ @ Test
2126+ public void fullReactiveGenericDispatchTestUncheckedDispatch () throws IOException {
2127+ test ().withStdLib ().uncheckedDispatch ().executeProg ().executeTests ().file (new File (TEST_DIR + "reactiveGenericsDispatch.wurst" ));
2128+
2129+ String compiled = Files .toString (
2130+ new File (TEST_OUTPUT_PATH + "GenericsWithTypeclassesTests_fullReactiveGenericDispatchTestUncheckedDispatch_no_opts.jim" ),
2131+ Charsets .UTF_8 );
2132+
2133+ // ReactiveSource is polymorphic, so dispatch remains, but safety checks should be removed.
2134+ assertTrue (compiled .contains ("dispatch_ReactiveSource_ReactiveSource_subscribe" ));
2135+ assertFalse (compiled .contains ("Nullpointer exception when calling ReactiveSource.subscribe" ));
2136+ assertFalse (compiled .contains ("Called ReactiveSource.subscribe on invalid object." ));
20992137 }
21002138
21012139 @ Test
0 commit comments