3684 */ |
3684 */ |
3685 private void checkInit(JCTree tree, |
3685 private void checkInit(JCTree tree, |
3686 Env<AttrContext> env, |
3686 Env<AttrContext> env, |
3687 VarSymbol v, |
3687 VarSymbol v, |
3688 boolean onlyWarning) { |
3688 boolean onlyWarning) { |
3689 // System.err.println(v + " " + ((v.flags() & STATIC) != 0) + " " + |
|
3690 // tree.pos + " " + v.pos + " " + |
|
3691 // Resolve.isStatic(env));//DEBUG |
|
3692 |
|
3693 // A forward reference is diagnosed if the declaration position |
3689 // A forward reference is diagnosed if the declaration position |
3694 // of the variable is greater than the current tree position |
3690 // of the variable is greater than the current tree position |
3695 // and the tree and variable definition occur in the same class |
3691 // and the tree and variable definition occur in the same class |
3696 // definition. Note that writes don't count as references. |
3692 // definition. Note that writes don't count as references. |
3697 // This check applies only to class and instance |
3693 // This check applies only to class and instance |
3698 // variables. Local variables follow different scope rules, |
3694 // variables. Local variables follow different scope rules, |
3699 // and are subject to definite assignment checking. |
3695 // and are subject to definite assignment checking. |
3700 if ((env.info.enclVar == v || v.pos > tree.pos) && |
3696 Env<AttrContext> initEnv = enclosingInitEnv(env); |
|
3697 if (initEnv != null && |
|
3698 (initEnv.info.enclVar == v || v.pos > tree.pos) && |
3701 v.owner.kind == TYP && |
3699 v.owner.kind == TYP && |
3702 enclosingInitEnv(env) != null && |
|
3703 v.owner == env.info.scope.owner.enclClass() && |
3700 v.owner == env.info.scope.owner.enclClass() && |
3704 ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && |
3701 ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && |
3705 (!env.tree.hasTag(ASSIGN) || |
3702 (!env.tree.hasTag(ASSIGN) || |
3706 TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) { |
3703 TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) { |
3707 String suffix = (env.info.enclVar == v) ? |
3704 String suffix = (initEnv.info.enclVar == v) ? |
3708 "self.ref" : "forward.ref"; |
3705 "self.ref" : "forward.ref"; |
3709 if (!onlyWarning || isStaticEnumField(v)) { |
3706 if (!onlyWarning || isStaticEnumField(v)) { |
3710 log.error(tree.pos(), "illegal." + suffix); |
3707 log.error(tree.pos(), "illegal." + suffix); |
3711 } else if (useBeforeDeclarationWarning) { |
3708 } else if (useBeforeDeclarationWarning) { |
3712 log.warning(tree.pos(), suffix, v); |
3709 log.warning(tree.pos(), suffix, v); |