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