src/share/classes/com/sun/tools/javac/comp/Attr.java

changeset 94
6542933af8f4
parent 89
b6d5f53b3b29
child 110
91eea580fbe9
equal deleted inserted replaced
93:30a415f8667f 94:6542933af8f4
728 Env<AttrContext> initEnv = memberEnter.initEnv(tree, env); 728 Env<AttrContext> initEnv = memberEnter.initEnv(tree, env);
729 initEnv.info.lint = lint; 729 initEnv.info.lint = lint;
730 // In order to catch self-references, we set the variable's 730 // In order to catch self-references, we set the variable's
731 // declaration position to maximal possible value, effectively 731 // declaration position to maximal possible value, effectively
732 // marking the variable as undefined. 732 // marking the variable as undefined.
733 v.pos = Position.MAXPOS; 733 initEnv.info.enclVar = v;
734 attribExpr(tree.init, initEnv, v.type); 734 attribExpr(tree.init, initEnv, v.type);
735 v.pos = tree.pos;
736 } 735 }
737 } 736 }
738 result = tree.type = v.type; 737 result = tree.type = v.type;
739 chk.validateAnnotations(tree.mods.annotations, v); 738 chk.validateAnnotations(tree.mods.annotations, v);
740 } 739 }
2196 // and the tree and variable definition occur in the same class 2195 // and the tree and variable definition occur in the same class
2197 // definition. Note that writes don't count as references. 2196 // definition. Note that writes don't count as references.
2198 // This check applies only to class and instance 2197 // This check applies only to class and instance
2199 // variables. Local variables follow different scope rules, 2198 // variables. Local variables follow different scope rules,
2200 // and are subject to definite assignment checking. 2199 // and are subject to definite assignment checking.
2201 if (v.pos > tree.pos && 2200 if ((env.info.enclVar == v || v.pos > tree.pos) &&
2202 v.owner.kind == TYP && 2201 v.owner.kind == TYP &&
2203 canOwnInitializer(env.info.scope.owner) && 2202 canOwnInitializer(env.info.scope.owner) &&
2204 v.owner == env.info.scope.owner.enclClass() && 2203 v.owner == env.info.scope.owner.enclClass() &&
2205 ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && 2204 ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) &&
2206 (env.tree.getTag() != JCTree.ASSIGN || 2205 (env.tree.getTag() != JCTree.ASSIGN ||
2207 TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) { 2206 TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) {
2208 2207 String suffix = (env.info.enclVar == v) ?
2208 "self.ref" : "forward.ref";
2209 if (!onlyWarning || isStaticEnumField(v)) { 2209 if (!onlyWarning || isStaticEnumField(v)) {
2210 log.error(tree.pos(), "illegal.forward.ref"); 2210 log.error(tree.pos(), "illegal." + suffix);
2211 } else if (useBeforeDeclarationWarning) { 2211 } else if (useBeforeDeclarationWarning) {
2212 log.warning(tree.pos(), "forward.ref", v); 2212 log.warning(tree.pos(), suffix, v);
2213 } 2213 }
2214 } 2214 }
2215 2215
2216 v.getConstValue(); // ensure initializer is evaluated 2216 v.getConstValue(); // ensure initializer is evaluated
2217 2217

mercurial