mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-15 10:23:28 +00:00
8037546: javac -parameters does not emit parameter names for lambda expressions
MethodParameters attribute is missing for synthetic methods encoding lambda expressions. Reviewed-by: rfield, mcimadamore
This commit is contained in:
parent
1be81e358c
commit
33a3e1add3
@ -263,7 +263,7 @@ public class LambdaToMethod extends TreeTranslator {
|
||||
@Override
|
||||
public void visitLambda(JCLambda tree) {
|
||||
LambdaTranslationContext localContext = (LambdaTranslationContext)context;
|
||||
MethodSymbol sym = (MethodSymbol)localContext.translatedSym;
|
||||
MethodSymbol sym = localContext.translatedSym;
|
||||
MethodType lambdaType = (MethodType) sym.type;
|
||||
|
||||
{
|
||||
@ -1755,7 +1755,7 @@ public class LambdaToMethod extends TreeTranslator {
|
||||
Map<LambdaSymbolKind, Map<Symbol, Symbol>> translatedSymbols;
|
||||
|
||||
/** the synthetic symbol for the method hoisting the translated lambda */
|
||||
Symbol translatedSym;
|
||||
MethodSymbol translatedSym;
|
||||
|
||||
List<JCVariableDecl> syntheticParams;
|
||||
|
||||
@ -1997,6 +1997,7 @@ public class LambdaToMethod extends TreeTranslator {
|
||||
|
||||
//compute synthetic params
|
||||
ListBuffer<JCVariableDecl> params = new ListBuffer<>();
|
||||
ListBuffer<VarSymbol> parameterSymbols = new ListBuffer<>();
|
||||
|
||||
// The signature of the method is augmented with the following
|
||||
// synthetic parameters:
|
||||
@ -2005,19 +2006,16 @@ public class LambdaToMethod extends TreeTranslator {
|
||||
// 2) enclosing locals captured by the lambda expression
|
||||
for (Symbol thisSym : getSymbolMap(CAPTURED_VAR).values()) {
|
||||
params.append(make.VarDef((VarSymbol) thisSym, null));
|
||||
}
|
||||
if (methodReferenceReceiver != null) {
|
||||
params.append(make.VarDef(
|
||||
make.Modifiers(PARAMETER|FINAL),
|
||||
names.fromString("$rcvr$"),
|
||||
make.Type(methodReferenceReceiver.type),
|
||||
null));
|
||||
parameterSymbols.append((VarSymbol) thisSym);
|
||||
}
|
||||
for (Symbol thisSym : getSymbolMap(PARAM).values()) {
|
||||
params.append(make.VarDef((VarSymbol) thisSym, null));
|
||||
parameterSymbols.append((VarSymbol) thisSym);
|
||||
}
|
||||
syntheticParams = params.toList();
|
||||
|
||||
translatedSym.params = parameterSymbols.toList();
|
||||
|
||||
// Compute and set the lambda name
|
||||
translatedSym.name = isSerializable()
|
||||
? serializedLambdaName()
|
||||
|
||||
@ -147,6 +147,7 @@ class ClassFileVisitor extends Tester.Visitor {
|
||||
public int mAttrs;
|
||||
public int mNumParams;
|
||||
public boolean mSynthetic;
|
||||
public boolean mIsLambda;
|
||||
public boolean mIsConstructor;
|
||||
public boolean mIsClinit;
|
||||
public boolean mIsBridge;
|
||||
@ -165,6 +166,7 @@ class ClassFileVisitor extends Tester.Visitor {
|
||||
mIsClinit = mName.equals("<clinit>");
|
||||
prefix = cname + "." + mName + "() - ";
|
||||
mIsBridge = method.access_flags.is(AccessFlags.ACC_BRIDGE);
|
||||
mIsLambda = mSynthetic && mName.startsWith("lambda$");
|
||||
|
||||
if (mIsClinit) {
|
||||
sb = new StringBuilder(); // Discard output
|
||||
@ -225,7 +227,7 @@ class ClassFileVisitor extends Tester.Visitor {
|
||||
|
||||
// IMPL: Whether MethodParameters attributes will be generated
|
||||
// for some synthetics is unresolved. For now, assume no.
|
||||
if (mSynthetic) {
|
||||
if (mSynthetic && !mIsLambda) {
|
||||
warn(prefix + "synthetic has MethodParameter attribute");
|
||||
}
|
||||
|
||||
@ -349,10 +351,12 @@ class ClassFileVisitor extends Tester.Visitor {
|
||||
} else if (isEnum && mNumParams == 1 && index == 0 && mName.equals("valueOf")) {
|
||||
expect = "name";
|
||||
allowMandated = true;
|
||||
} else if (mIsBridge) {
|
||||
} else if (mIsBridge || mIsLambda) {
|
||||
allowSynthetic = true;
|
||||
/* you can't expect an special name for bridges' parameters.
|
||||
* The name of the original parameters are now copied.
|
||||
* The name of the original parameters are now copied. Likewise
|
||||
* for a method encoding the lambda expression, names are derived
|
||||
* from source lambda's parameters and captured enclosing locals.
|
||||
*/
|
||||
expect = null;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2015 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8006582
|
||||
* @bug 8006582 8037546
|
||||
* @summary javac should generate method parameters correctly.
|
||||
* @build Tester
|
||||
* @compile -parameters LambdaTest.java
|
||||
@ -31,8 +31,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parameter names are not recorded for lambdas. This test verifies
|
||||
* that there are no MethodParameters attribute for lambdas.
|
||||
* Post https://bugs.openjdk.java.net/browse/JDK-8037546, this test verifies
|
||||
* that MethodParameters attribute for lambdas are emitted properly.
|
||||
*/
|
||||
class LambdaTest {
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
class LambdaTest --
|
||||
LambdaTest.<init>()
|
||||
LambdaTest.foo(i)
|
||||
LambdaTest.lambda$static$1(arg0)/*synthetic*/
|
||||
LambdaTest.lambda$null$0(arg0, arg1)/*synthetic*/
|
||||
LambdaTest.lambda$static$1(x1/*synthetic*/)/*synthetic*/
|
||||
LambdaTest.lambda$null$0(final cap$0/*synthetic*/, x2/*synthetic*/)/*synthetic*/
|
||||
static interface LambdaTest$I -- inner
|
||||
LambdaTest$I.m(x)
|
||||
|
||||
@ -277,7 +277,7 @@ public class ReflectionVisitor extends Tester.Visitor {
|
||||
param = "final " + param;
|
||||
}
|
||||
sb.append(sep).append(param);
|
||||
if (!m.isBridge() && !expect.equals(param)) {
|
||||
if (!m.isBridge() && !m.getName().startsWith("lambda$") && !expect.equals(param)) {
|
||||
error(prefix + "param[" + i + "]='"
|
||||
+ param + "' expected '" + expect + "'");
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user