8144168: No type annotations generated for nested lambdas
Reviewed-by: jlahoda
This commit is contained in:
parent
c7c54cf62a
commit
a7a324e4cb
@ -1812,7 +1812,7 @@ public class LambdaToMethod extends TreeTranslator {
|
||||
|
||||
TranslationContext(T tree) {
|
||||
this.tree = tree;
|
||||
this.owner = owner();
|
||||
this.owner = owner(true);
|
||||
this.depth = frameStack.size() - 1;
|
||||
this.prev = context();
|
||||
ClassSymbol csym =
|
||||
|
@ -2173,8 +2173,8 @@ public class Gen extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
public void visitTypeCast(JCTypeCast tree) {
|
||||
setTypeAnnotationPositions(tree.pos);
|
||||
result = genExpr(tree.expr, tree.clazz.type).load();
|
||||
setTypeAnnotationPositions(tree.pos);
|
||||
// Additional code is only needed if we cast to a reference type
|
||||
// which is not statically a supertype of the expression's type.
|
||||
// For basic types, the coerce(...) in genExpr(...) will do
|
||||
@ -2191,8 +2191,8 @@ public class Gen extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
public void visitTypeTest(JCInstanceOf tree) {
|
||||
setTypeAnnotationPositions(tree.pos);
|
||||
genExpr(tree.expr, tree.expr.type).load();
|
||||
setTypeAnnotationPositions(tree.pos);
|
||||
code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
|
||||
result = items.makeStackItem(syms.booleanType);
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ class LambdaTest --
|
||||
LambdaTest.<init>()
|
||||
LambdaTest.foo(i)
|
||||
LambdaTest.lambda$static$1(arg0)/*synthetic*/
|
||||
LambdaTest.lambda$null$0(arg0, arg1)/*synthetic*/
|
||||
LambdaTest.lambda$static$0(arg0, arg1)/*synthetic*/
|
||||
static interface LambdaTest$I -- inner
|
||||
LambdaTest$I.m(x)
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8144168
|
||||
* @summary No type annotations generated for nested lambdas
|
||||
* @library /tools/lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
* @build ToolBox
|
||||
* @run compile NestedLambdasCastedTest.java
|
||||
* @run main NestedLambdasCastedTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
public class NestedLambdasCastedTest {
|
||||
|
||||
// Expected output can't be directly encoded into NestedLambdasCastedTest !!!
|
||||
static class ExpectedOutputHolder {
|
||||
public String [] outputs = {
|
||||
"public static strictfp void main(java.lang.String[])",
|
||||
"private static strictfp void lambda$main$3();",
|
||||
"private static strictfp void lambda$main$2();",
|
||||
"private static strictfp void lambda$main$1();",
|
||||
"private static strictfp void lambda$main$0();",
|
||||
"0: #63(#64=s#65): CAST, offset=5, type_index=0",
|
||||
"0: #63(#64=s#70): CAST, offset=5, type_index=0",
|
||||
"0: #63(#64=s#73): CAST, offset=5, type_index=0",
|
||||
"0: #63(#64=s#76): CAST, offset=5, type_index=0"
|
||||
};
|
||||
}
|
||||
|
||||
@Target(ElementType.TYPE_USE)
|
||||
public @interface TA {
|
||||
String value() default "";
|
||||
};
|
||||
|
||||
public static strictfp void main(String args[]) throws Exception {
|
||||
Runnable one = (@TA("1") Runnable) () -> {
|
||||
Runnable two = (@TA("2") Runnable) () -> {
|
||||
Runnable three = (@TA("3") Runnable) () -> {
|
||||
Runnable four = (@TA("4") Runnable) () -> {
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
ToolBox tb = new ToolBox();
|
||||
Path classPath = Paths.get(ToolBox.testClasses, "NestedLambdasCastedTest.class");
|
||||
String javapOut = tb.new JavapTask()
|
||||
.options("-v", "-p")
|
||||
.classes(classPath.toString())
|
||||
.run()
|
||||
.getOutput(ToolBox.OutputKind.DIRECT);
|
||||
ExpectedOutputHolder holder = new ExpectedOutputHolder();
|
||||
for (String s : holder.outputs)
|
||||
if (!javapOut.contains(s))
|
||||
throw new AssertionError("Expected type annotation on LOCAL_VARIABLE missing");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user