Fix NoSuchMethod exception in UnifyAST due to unresolved method references.

GwtAstBuilder must resolve the method reference to point to
the right declaring class, e.g.

class A {
   public void m() {}
}

class B extends A {
}

B:m() needs to be resolved to A::m() at AST building time in
order for UnifyAST to stitch compilation units together.

Change-Id: I2833e13473bc35945055040d2f318244d012a98d
Bug-Link: https://github.com/gwtproject/gwt/issues/9307
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
index ace1e31..f8f9beb 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
@@ -1725,6 +1725,9 @@
        * [x] denotes optional, depending on context of whether outer this scope is needed.
        */
 
+      // Resolve the reference expression to make sure the declaring class of the method is resolved
+      // to the right type.
+      x.resolve(blockScope);
       // Calculate what type this reference is going to bind to, and what single abstract method
       TypeBinding binding = x.expectedType();
       MethodBinding samBinding = binding.getSingleAbstractMethod(blockScope, false).original();
diff --git a/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java b/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java
index ab750a8..913c2b6 100644
--- a/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java
+++ b/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java
@@ -1370,5 +1370,15 @@
     assertSame("c", callFromJSNI(function));
     String[] pars = new String[] {"a", "b", "c"};
     assertSame("a", function.f(0, pars));
- }
+  }
+
+  @FunctionalInterface
+  interface ToString {
+    String apply(StringBuilder t);
+  }
+
+  public void testMethodReferenceImplementedInSuperclass() {
+    ToString toString = StringBuilder::toString;
+    assertEquals("Hello", toString.apply(new StringBuilder("Hello")));
+  }
 }
diff --git a/user/test/com/google/gwt/dev/jjs/test/Java8Test.java b/user/test/com/google/gwt/dev/jjs/test/Java8Test.java
index a521bf2..2f0a8f4 100644
--- a/user/test/com/google/gwt/dev/jjs/test/Java8Test.java
+++ b/user/test/com/google/gwt/dev/jjs/test/Java8Test.java
@@ -268,6 +268,10 @@
     assertFalse(isGwtSourceLevel8());
   }
 
+  public void testMethodReferenceImplementedInSuperclass() {
+    assertFalse(isGwtSourceLevel8());
+  }
+
   private boolean isGwtSourceLevel8() {
     return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA8) >= 0;
   }