Added a new test to CompilerTest: referencing instance fields or methods from JSNI in an uninstantiable type causes ICEs.

Review by: bobv (postmortem)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1909 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java b/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
index 6640fd0..211e416 100644
--- a/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
@@ -20,19 +20,12 @@
 
 import junit.framework.Assert;
 
-// CHECKSTYLE_OFF
-
 /**
- * TODO: doc me
+ * Miscellaneous tests of the Java to JavaScript compiler.
  */
+@SuppressWarnings("unused")
 public class CompilerTest extends GWTTestCase {
 
-  public static class Foo {
-    public int bar(int i) {
-      return 0;
-    }
-  }
-
   private abstract static class Apple implements Fruit {
   }
 
@@ -143,16 +136,22 @@
 
   private static int sideEffectChecker;
 
+  private static native void accessUninstantiableField(UninstantiableType u) /*-{
+    u.@com.google.gwt.dev.jjs.test.CompilerTest$Uninstantiable::field;
+  }-*/;
+
+  private static native void accessUninstantiableMethod(UninstantiableType u) /*-{
+    u.@com.google.gwt.dev.jjs.test.CompilerTest$Uninstantiable::returnNull()();
+  }-*/;
+
   private static String barShouldInline() {
     return "bar";
   }
 
   private static void foo(String string) {
-    Object o = string;
   }
 
   private static void foo(Throwable throwable) {
-    Object o = throwable;
   }
 
   private static native String jsniReadSideEffectCauser5() /*-{
@@ -391,6 +390,8 @@
     }
   }-*/;
 
+  // CHECKSTYLE_OFF
+
   public void testEmptyStatements() {
     boolean b = false;
 
@@ -417,6 +418,8 @@
       ;
   }
 
+  // CHECKSTYLE_ON
+
   public native void testEmptyStatementsNative() /*-{
     var b = false;
 
@@ -483,7 +486,7 @@
   }
 
   /**
-   * Issue #615: Internal Compiler Error
+   * Issue #615: Internal Compiler Error.
    */
   public void testImplicitNull() {
     boolean b;
@@ -672,10 +675,11 @@
 
       Foo(int i) {
         this.i = i;
-        if (i == 0)
+        if (i == 0) {
           return;
-        else if (i == 1)
+        } else if (i == 1) {
           return;
+        }
         return;
       }
     }
@@ -710,7 +714,8 @@
   public void testSwitchStatement() {
     switch (0) {
       case 0:
-        int test; // used to cause an ICE
+        // Once caused an ICE.
+        int test;
         break;
     }
   }
@@ -741,8 +746,7 @@
   }
 
   public void testSwitchStatementEmpty() {
-    Foo foo = new Foo();
-    switch (foo.bar(0)) {
+    switch (0) {
     }
   }
 
@@ -831,6 +835,22 @@
     assertEquals(-7, x);
   }
 
+  public void testUninstantiableNativeAccess() {
+    UninstantiableType u = null;
+
+    try {
+      accessUninstantiableField(u);
+      fail("Expected JavaScriptException");
+    } catch (JavaScriptException expected) {
+    }
+
+    try {
+      accessUninstantiableMethod(u);
+      fail("Expected JavaScriptException");
+    } catch (JavaScriptException expected) {
+    }
+  }
+
   private boolean returnFalse() {
     return false;
   }