Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expression in foreach stmt where the expression type structurally implements Iterator and a class extension exists that makes Iterable structural #396

Closed
rsmckinney opened this issue Nov 17, 2022 · 1 comment

Comments

@rsmckinney
Copy link
Member

Support expression in foreach stmt where the expression type structurally implements Iterator and a class extension exists that makes Iterable structrual.

Enable Iterable as a structural interface .

package extensions.java.lang.Iterable;
. . .
@Extension
@Structural
public class StructuralIterable {
}

Make NodeList implement Iterable.

package extensions.org.w3c.dom.NodeList;
. . .
@Extension
public abstract class NodeListExt implements Iterable<Node> {
    public static Iterator<Node> iterator(@This NodeList thiz) {
        return new NodeListIterator(thiz);
    }

    public static Node get(@This NodeList thiz, int index) {
        return thiz.item(index);
    }
}

Use foreach statement with NodeList.

for (Node node : doc.documentElement.childNodes) {
  . . .
}

See slack discussion.

rsmckinney added a commit that referenced this issue Nov 17, 2022
- Support case where Iterable is made structural via extension. As such, foreach stmt should work with types that implement Iterable structurally. Note, this did not work initially because javac foreach desugar happens during Gen (in Lower).
@rsmckinney rsmckinney changed the title Support expression in foreach stmt where the expression type structurally implements Iterator and a class extension exists that makes Iterable structrual Support expression in foreach stmt where the expression type structurally implements Iterator and a class extension exists that makes Iterable structural Nov 18, 2022
rsmckinney added a commit to manifold-systems/manifold-ij that referenced this issue Nov 18, 2022
- Handle expression in foreach stmt where the expression type structurally implements Iterator and a class extension exists that makes Iterable structural

manifold-systems/manifold#395
- Support property inference on record types

Bump version
@rsmckinney
Copy link
Member Author

Supported since release 2022.1.24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant