I need to institute a name+arity resolution process to be used when
name+arity+type resolution cannot be performed. There will still be
opportunity
for irreconcilable ambiguity using just name+arity, but it should happen
much
less often, and we can still fall back to emitting code that will simply
throw
an error.
http://code.google.com/p/ductilej/source/detail?r=57b938abe6
Added:
/src/org/ductilej/dtests/InferredReceiverTest.java
Modified:
/src/org/ductilej/detyper/Resolver.java
=======================================
--- /dev/null
+++ /src/org/ductilej/dtests/InferredReceiverTest.java Sat Jul 10 11:20:25
2010
@@ -0,0 +1,41 @@
+//
+// $Id$
+
+package org.ductilej.dtests;
+
+import org.junit.Test;
+import org.junit.Assert;
+import static org.junit.Assert.*;
+
+/**
+ * Tests various circumstances in which we must use heuristics to
determine whether a receiver is
+ * static.
+ */
+public class InferredReceiverTest
+{
+ public static class Tester {
+ public static String staticTest (String arg) {
+ return "static:" + arg;
+ }
+
+ public String test (String arg) {
+ return "non-static:" + arg;
+ }
+ }
+
+ @Test public void testSimpleStatic () {
+ assertEquals("static:foo", Tester.staticTest("foo"));
+ }
+
+ @Test public void testSimpleNonStatic () {
+ Object t = new Tester();
+ // TODO: we fail to resolve assertEquals() because t.test cannot
be resolved
+ assertEquals("non-static:foo", t.test("foo"));
+ }
+
+ @Test public void testArrayReceiver () {
+ Object[] ts = { new Tester() };
+ // TODO: we fail to resolve assertEquals() because ts[0].test
cannot be resolved
+ assertEquals("non-static:foo", ts[0].test("foo"));
+ }
+}
=======================================
--- /src/org/ductilej/detyper/Resolver.java Sun Jun 27 11:06:33 2010
+++ /src/org/ductilej/detyper/Resolver.java Sat Jul 10 11:20:25 2010
@@ -632,7 +632,8 @@
Symbol rsym = resolveSymbol(env, expr, Kinds.VAL|Kinds.TYP);
return (rsym.getKind() == ElementKind.CLASS) ? rsym : null;
case JCTree.APPLY:
- return null;
+ case JCTree.INDEXED:
+ return null; // these are necessarily non-static receivers
default:
Debug.warn("Unable to infer static receivership", "expr", expr,
"etype", expr.getClass().getName());