[ductilej] push by samskivert - Added some tests for inferred receiver heuristics. Uncovered a new pro... on 2010-07-10 18:20 GMT

0 views
Skip to first unread message

duct...@googlecode.com

unread,
Jul 10, 2010, 2:21:05 PM7/10/10
to ductil...@googlegroups.com
Revision: 57b938abe6
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 11:20:25 2010
Log: Added some tests for inferred receiver heuristics. Uncovered a new
problem
wherein we fail to do the right thing with assertEquals() because its
arguments
cannot be resolved, so we fail to "see" that we want the statically imported
methods from Assert and instead assume they should be normal members called
on
the enclosing class.

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());

Reply all
Reply to author
Forward
0 new messages