1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Sep 14 19:04:47 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Sep 16 14:13:44 2013 +0200 1.3 @@ -748,19 +748,11 @@ 1.4 * @see VarSymbol#setLazyConstValue 1.5 */ 1.6 public Object attribLazyConstantValue(Env<AttrContext> env, 1.7 - JCTree.JCExpression initializer, 1.8 + JCVariableDecl variable, 1.9 Type type) { 1.10 1.11 - /* When this env was created, it didn't have the correct lint nor had 1.12 - * annotations has been processed. 1.13 - * But now at this phase we have already processed annotations and the 1.14 - * correct lint must have been set in chk, so we should use that one to 1.15 - * attribute the initializer. 1.16 - */ 1.17 - Lint prevLint = env.info.lint; 1.18 - env.info.lint = chk.getLint(); 1.19 - 1.20 - JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); 1.21 + DiagnosticPosition prevLintPos 1.22 + = deferredLintHandler.setPos(variable.pos()); 1.23 1.24 try { 1.25 // Use null as symbol to not attach the type annotation to any symbol. 1.26 @@ -768,17 +760,16 @@ 1.27 // to the symbol. 1.28 // This prevents having multiple type annotations, just because of 1.29 // lazy constant value evaluation. 1.30 - memberEnter.typeAnnotate(initializer, env, null); 1.31 + memberEnter.typeAnnotate(variable.init, env, null, variable.pos()); 1.32 annotate.flush(); 1.33 - Type itype = attribExpr(initializer, env, type); 1.34 + Type itype = attribExpr(variable.init, env, type); 1.35 if (itype.constValue() != null) { 1.36 return coerce(itype, type).constValue(); 1.37 } else { 1.38 return null; 1.39 } 1.40 } finally { 1.41 - env.info.lint = prevLint; 1.42 - log.useSource(prevSource); 1.43 + deferredLintHandler.setPos(prevLintPos); 1.44 } 1.45 } 1.46 1.47 @@ -1012,7 +1003,7 @@ 1.48 } 1.49 1.50 // Attribute all type annotations in the body 1.51 - memberEnter.typeAnnotate(tree.body, localEnv, m); 1.52 + memberEnter.typeAnnotate(tree.body, localEnv, m, null); 1.53 annotate.flush(); 1.54 1.55 // Attribute method body. 1.56 @@ -1042,7 +1033,7 @@ 1.57 } else { 1.58 if (tree.init != null) { 1.59 // Field initializer expression need to be entered. 1.60 - memberEnter.typeAnnotate(tree.init, env, tree.sym); 1.61 + memberEnter.typeAnnotate(tree.init, env, tree.sym, tree.pos()); 1.62 annotate.flush(); 1.63 } 1.64 } 1.65 @@ -1056,18 +1047,16 @@ 1.66 ((JCLambda)env.tree).paramKind == JCLambda.ParameterKind.IMPLICIT && 1.67 (tree.sym.flags() & PARAMETER) != 0; 1.68 chk.validate(tree.vartype, env, !isImplicitLambdaParameter); 1.69 - deferredLintHandler.flush(tree.pos()); 1.70 1.71 try { 1.72 + v.getConstValue(); // ensure compile-time constant initializer is evaluated 1.73 + deferredLintHandler.flush(tree.pos()); 1.74 chk.checkDeprecatedAnnotation(tree.pos(), v); 1.75 1.76 if (tree.init != null) { 1.77 - if ((v.flags_field & FINAL) != 0 && 1.78 - memberEnter.needsLazyConstValue(tree.init)) { 1.79 - // In this case, `v' is final. Ensure that it's initializer is 1.80 - // evaluated. 1.81 - v.getConstValue(); // ensure initializer is evaluated 1.82 - } else { 1.83 + if ((v.flags_field & FINAL) == 0 || 1.84 + !memberEnter.needsLazyConstValue(tree.init)) { 1.85 + // Not a compile-time constant 1.86 // Attribute initializer in a new environment 1.87 // with the declared variable as owner. 1.88 // Check that initializer conforms to variable's declared type. 1.89 @@ -1106,7 +1095,7 @@ 1.90 if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; 1.91 1.92 // Attribute all type annotations in the block 1.93 - memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner); 1.94 + memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner, null); 1.95 annotate.flush(); 1.96 1.97 { 1.98 @@ -4209,6 +4198,7 @@ 1.99 ResultInfo prevReturnRes = env.info.returnResult; 1.100 1.101 try { 1.102 + deferredLintHandler.flush(env.tree); 1.103 env.info.returnResult = null; 1.104 // java.lang.Enum may not be subclassed by a non-enum 1.105 if (st.tsym == syms.enumSym &&