1173 env.dup(env.tree, env.info.dup(env.info.scope.dup())); |
1173 env.dup(env.tree, env.info.dup(env.info.scope.dup())); |
1174 try { |
1174 try { |
1175 //the Formal Parameter of a for-each loop is not in the scope when |
1175 //the Formal Parameter of a for-each loop is not in the scope when |
1176 //attributing the for-each expression; we mimick this by attributing |
1176 //attributing the for-each expression; we mimick this by attributing |
1177 //the for-each expression first (against original scope). |
1177 //the for-each expression first (against original scope). |
1178 Type exprType = types.upperBound(attribExpr(tree.expr, loopEnv)); |
1178 Type exprType = types.cvarUpperBound(attribExpr(tree.expr, loopEnv)); |
1179 attribStat(tree.var, loopEnv); |
1179 attribStat(tree.var, loopEnv); |
1180 chk.checkNonVoid(tree.pos(), exprType); |
1180 chk.checkNonVoid(tree.pos(), exprType); |
1181 Type elemtype = types.elemtype(exprType); // perhaps expr is an array? |
1181 Type elemtype = types.elemtype(exprType); // perhaps expr is an array? |
1182 if (elemtype == null) { |
1182 if (elemtype == null) { |
1183 // or perhaps expr implements Iterable<T>? |
1183 // or perhaps expr implements Iterable<T>? |
1190 elemtype = types.createErrorType(exprType); |
1190 elemtype = types.createErrorType(exprType); |
1191 } else { |
1191 } else { |
1192 List<Type> iterableParams = base.allparams(); |
1192 List<Type> iterableParams = base.allparams(); |
1193 elemtype = iterableParams.isEmpty() |
1193 elemtype = iterableParams.isEmpty() |
1194 ? syms.objectType |
1194 ? syms.objectType |
1195 : types.upperBound(iterableParams.head); |
1195 : types.wildUpperBound(iterableParams.head); |
1196 } |
1196 } |
1197 } |
1197 } |
1198 chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type); |
1198 chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type); |
1199 loopEnv.tree = tree; // before, we were not in loop! |
1199 loopEnv.tree = tree; // before, we were not in loop! |
1200 attribStat(tree.body, loopEnv); |
1200 attribStat(tree.body, loopEnv); |