Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6381812

Regression: valid enhanced for loops no longer compile

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • 6
    • 6
    • tools
    • generic
    • generic

      The testing for foreach loops was made too restrictive; this code compiled in build 68 and earlier:

          public Void scan(Iterable<? extends Tree> trees, Object o) {
              if (!found && trees == null)
                  for (Tree tree : trees)
                      if (!found)
                          scan(tree, o);
              return null;
          }

      but fails in build 70 with "foreach not applicable to expression type". Since trees is a collection of instances of type Tree or subclasses of type Tree, any element of that collection can safely be assigned to the foreach tree variable.

            Unassigned Unassigned
            tballsunw Tom Ball (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: