changeset 743:f813d93e510c

Bug fix: *) Small adjustments to DA/DU rules and corresponding translation technique. *) Better error reporting (hide partially specified lambda types)
author mcimadamore
date Wed, 20 Oct 2010 18:19:47 +0100
parents caadb412a4a6
children e23ed3e167e8
files src/share/classes/com/sun/tools/javac/comp/Flow.java src/share/classes/com/sun/tools/javac/comp/Unlambda.java src/share/classes/com/sun/tools/javac/resources/compiler.properties src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java test/tools/javac/diags/examples.not-yet.txt
diffstat 5 files changed, 10 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Oct 19 16:26:29 2010 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Wed Oct 20 18:19:47 2010 +0100
@@ -1322,7 +1322,6 @@
             caught = List.of(syms.throwableType); //inhibit exception checking
             thrown = List.nil();            
             inits = inits.orSet(uninits);
-            uninits.clear();
             pendingExits = new ListBuffer<PendingExit>();
             for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
                 JCVariableDecl def = l.head;
--- a/src/share/classes/com/sun/tools/javac/comp/Unlambda.java	Tue Oct 19 16:26:29 2010 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Unlambda.java	Wed Oct 20 18:19:47 2010 +0100
@@ -239,7 +239,7 @@
 
             super.visitVarDef(tree);
             JCClassDecl c = ((JCNewClass)tree.init).def;
-            final VarSymbol capturedVar = new VarSymbol(0, names.fromString("$f"), c.type, c.sym);
+            final VarSymbol selfRef = new VarSymbol(0, names._this, c.type, c.sym);
 
             //references to variable under initialization from lambda body
             //are automatically turned into references to a synthetic field
@@ -251,52 +251,15 @@
                 public void visitIdent(JCIdent that) {
                     if (tree.sym == that.sym) {
                         needsCapture = true;
-                        that.sym = capturedVar;
-                        that.name = capturedVar.name;
+                        that.sym = selfRef;
+                        that.name = selfRef.name;
                     }
                 }
             }
             LambdaVarInitPatcher lvis = new LambdaVarInitPatcher();
             lvis.scan(tree.init);
-            if (lvis.needsCapture) {
-
-                //if the previous step has replaced some references to the
-                //variable being initialized, generate extra synthetic field
-                //append to desugared lambda class and initialize it
-
-                c.sym.members().enter(capturedVar);
-                JCVariableDecl capturedVarDecl = make.VarDef(capturedVar, null);
-                c.defs = c.defs.prepend(capturedVarDecl);
-                JCIdent varRef = make.Ident(tree.sym);
-                JCExpression capturedVarRef = make.Select(
-                        make.TypeCast(c.type, varRef).setType(c.type),
-                        capturedVar);
-                tailStats.append(make.Exec(make.Assign(capturedVarRef, varRef).setType(tree.type)));
-            }
         } else {
             super.visitVarDef(tree);
         }
     }
-
-    /*
-     * list buffer containing additional statements to be generated
-     * during translation of a block - this might be required in case
-     * a single block statement gets desugared into multiple statements
-     * (and a block cannot be used)
-     */
-    ListBuffer<JCStatement> tailStats = ListBuffer.lb();
-
-    @Override
-    public void visitBlock(JCBlock tree) {
-        ListBuffer<JCStatement> newStats = ListBuffer.lb();
-        for (JCStatement stat : tree.stats) {
-            newStats = newStats.append(translate(stat));
-            if (tailStats.nonEmpty()) {
-                newStats = newStats.appendList(tailStats);
-                tailStats.clear();
-            }
-        }
-        tree.stats = newStats.toList();
-        result = tree;
-    }
 }
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Oct 19 16:26:29 2010 +0100
+++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed Oct 20 18:19:47 2010 +0100
@@ -1435,6 +1435,9 @@
 compiler.misc.type.null=\
     <null>
 
+compiler.misc.type.lambda=\
+    <lambda>
+
 # X#n (where n is an int id) is disambiguated tvar name
 compiler.misc.type.var=\
     {0}#{1}
--- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Tue Oct 19 16:26:29 2010 +0100
+++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Wed Oct 20 18:19:47 2010 +0100
@@ -350,7 +350,9 @@
         @Override
         public String visitForAll(ForAll t, Locale locale) {
             if (types.isFunctionType(t)) {
-                return visit(t.qtype, locale);
+                return t.qtype.containsAny(t.tvars) ?
+                    localize(locale, "compiler.misc.type.lambda") :
+                    visit(t.qtype, locale);
             }
             else {
                 return super.visitForAll(t, locale);
--- a/test/tools/javac/diags/examples.not-yet.txt	Tue Oct 19 16:26:29 2010 +0100
+++ b/test/tools/javac/diags/examples.not-yet.txt	Wed Oct 20 18:19:47 2010 +0100
@@ -150,5 +150,6 @@
 compiler.misc.where.disjunctive                                                  #LAMBDA
 compiler.misc.where.disjunctive.1                                                #LAMBDA
 compiler.note.potential.lambda.found                                             #LAMBDA
+compiler.misc.type.lambda                                                        #LAMBDA
 compiler.warn.cyclic.lambda.inference.throws                                     #LAMBDA
 compiler.warn.cyclic.lambda.inference.throws.1                                   #LAMBDA