6509042: javac rejects class literals in enum constructors
Javac now distinguish between enum class literals and static fields Reviewed-by: jjg
This commit is contained in:
parent
70bcd151a0
commit
8ef814eb9c
@ -2199,7 +2199,7 @@ public class Attr extends JCTree.Visitor {
|
||||
(env.tree.getTag() != JCTree.ASSIGN ||
|
||||
TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) {
|
||||
|
||||
if (!onlyWarning || isNonStaticEnumField(v)) {
|
||||
if (!onlyWarning || isStaticEnumField(v)) {
|
||||
log.error(tree.pos(), "illegal.forward.ref");
|
||||
} else if (useBeforeDeclarationWarning) {
|
||||
log.warning(tree.pos(), "forward.ref", v);
|
||||
@ -2233,7 +2233,7 @@ public class Attr extends JCTree.Visitor {
|
||||
// initializer expressions of an enum constant e to refer
|
||||
// to itself or to an enum constant of the same type that
|
||||
// is declared to the right of e."
|
||||
if (isNonStaticEnumField(v)) {
|
||||
if (isStaticEnumField(v)) {
|
||||
ClassSymbol enclClass = env.info.scope.owner.enclClass();
|
||||
|
||||
if (enclClass == null || enclClass.owner == null)
|
||||
@ -2254,8 +2254,14 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNonStaticEnumField(VarSymbol v) {
|
||||
return Flags.isEnum(v.owner) && Flags.isStatic(v) && !Flags.isConstant(v);
|
||||
/** Is the given symbol a static, non-constant field of an Enum?
|
||||
* Note: enum literals should not be regarded as such
|
||||
*/
|
||||
private boolean isStaticEnumField(VarSymbol v) {
|
||||
return Flags.isEnum(v.owner) &&
|
||||
Flags.isStatic(v) &&
|
||||
!Flags.isConstant(v) &&
|
||||
v.name != names._class;
|
||||
}
|
||||
|
||||
/** Can the given symbol be the owner of code which forms part
|
||||
|
41
langtools/test/tools/javac/enum/T6509042.java
Normal file
41
langtools/test/tools/javac/enum/T6509042.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6509042
|
||||
*
|
||||
* @summary javac rejects class literals in enum constructors
|
||||
* @author Maurizio Cimadamore
|
||||
*
|
||||
* @compile T6509042.java
|
||||
*/
|
||||
enum T6509042 {
|
||||
A, B;
|
||||
|
||||
Class<T6509042> cl = T6509042.class;
|
||||
|
||||
T6509042() {
|
||||
Class<T6509042> cl2 = T6509042.class;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user