Skip to content

Array.iterator() is not a haxe.iterators.ArrayIterator #5

Open

Description

@dimensionscape

Array.iterator() returns the native hx::ArrayIterator, so checks and casts against haxe.iterators.ArrayIterator fail.

var it = ([1, 2, 3] : Iterable<Int>).iterator();
trace(Std.isOfType(it, haxe.iterators.ArrayIterator)); // false
var typed:haxe.iterators.ArrayIterator<Int> = cast it; // null

Upstream: HaxeFoundation/hxcpp#870

Activity

  1. added
    needs haxeCan't be finished without a change in the Haxe compiler or std (HaxeFoundation/haxe)
    on Oct 19, 2026
  2. dimensionscape commented on Oct 19, 2026

    @dimensionscape
    MemberAuthor

    Status: needs a change in Haxe's standard library or generator (label needs haxe). Not fixable cleanly in libhxcpp.

    Haxe's std/Array.hx (4.3.7, line 280) declares @:runtime inline function iterator():haxe.iterators.ArrayIterator<T>. Statically typed calls are inlined to new haxe.iterators.ArrayIterator(this). Calls through Iterable dispatch to the runtime's Array_obj::iterator (include/Array.h:1027), which returns the native hx::ArrayIterator.

    haxe.iterators.ArrayIterator is a generated class: the runtime can't name it, and it's only compiled into programs that use it. A runtime-only fix would have to look the class up by name at run time and fall back when it isn't linked, which is fragile. The fix belongs on the Haxe side, for example by having the dynamic iterator field resolve to the Haxe implementation, or by not promising haxe.iterators.ArrayIterator as the dynamic return type.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs haxeCan't be finished without a change in the Haxe compiler or std (HaxeFoundation/haxe)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions