Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Let a start read from a Dynamic field reach indexOf and lastIndexOf - #506

Open
dimensionscape wants to merge 1 commit into
mainfrom
fix/search-start-field-read
Open

dimensionscape wants to merge 1 commit into
mainfrom
fix/search-start-field-read

Conversation

@dimensionscape

Copy link
Copy Markdown
Member

For 6.0.3. Fixes a regression in 6.0.0 from aaf0388 (#307).

Generated code that passes a start read from a Dynamic field to a String's or a typed Array's indexOf or lastIndexOf no longer compiles:

var o:Dynamic = { start: 2 };
"a b c".indexOf(" ", o.start);
[1, 2, 1].lastIndexOf(1, o.start);
error C2668: 'String::indexOf': ambiguous call to overloaded function      (MSVC)
error: call to member function 'indexOf' is ambiguous                      (clang)

hxc does this in its own source, so its WebAssembly build stopped there under emscripten's clang.

Cause

aaf0388 gave these methods an Int overload beside the Dynamic one, so an Int start is not boxed, and one for null(), which converts to both. A Dynamic field read is an hx::Val, which also converts to both an Int and a Dynamic, so a call that passes one matched two overloads equally well.

Change

A template overload takes a start of any class type that no other overload matches exactly and passes it on as a Dynamic, as every start went before aaf0388. Int, Dynamic and null() starts keep their own overloads, so an Int start is still not boxed, and other arithmetic types still convert to Int as before. In include/hxString.h the conversion goes through a defaulted template parameter, because Dynamic is not complete there. Four declarations, in include/hxString.h and include/Array.h.

Tests

TestSearch in test/haxe now also passes the start through a Dynamic field, on Strings and Int arrays, and compares it with the other kinds. Without the change TestSearch.cpp does not compile (C2668 on all four calls); with it test/haxe passes on 64-bit Windows with MSVC and Haxe 4.3.7, 2880 of 2880 assertions.

hxc's WebAssembly build (emscripten 3.1.74) compiles and links against this branch.

Since aaf0388, a String's and a typed Array's indexOf and lastIndexOf
have an Int overload beside the Dynamic one, and null() an overload of
its own. A start read from a Dynamic field, as in
text.indexOf(" ", o.start), is an hx::Val, which converts to both an
Int and a Dynamic, so generated code that passes one stopped compiling:
C2668 on MSVC, "call to member function 'indexOf' is ambiguous" on
clang. hxc's WebAssembly build fails this way in its own source.

A template overload now takes a start of any class type that no other
overload matches exactly and passes it on as a Dynamic, as every start
went before aaf0388. Int, Dynamic and null() starts keep their own
overloads, so an Int start is still not boxed. In hxString.h the
conversion goes through a defaulted template parameter, because Dynamic
is not complete there.

Tests: TestSearch in test/haxe compares a start read from a Dynamic
field with the other kinds, on Strings and Int arrays. Without the
change TestSearch.cpp does not compile (C2668 on all four calls); with
it test/haxe passes on Windows x64, 2880 assertions.
dimensionscape added a commit to DimensionscapeOrg/haxe-run that referenced this pull request Nov 28, 2026
The compiler is hxc-release 2b4612e1, as before, now built against
openfl/libhxcpp b4a66042: main at b6981ce4 plus the indexOf fix of
openfl/libhxcpp#506. Since 6.0.0 a start read from a Dynamic field no
longer compiled there, and hxc's own source passes one.

libhxcpp's emscripten toolchain now strips the linked module, which took
the function names out, so the build passes -Dnostrip. WORKER_CONTRACT.md
records both, and building against a copy of libhxcpp through
HAXELIB_PATH.

Output is unchanged: the shared ES5 sample, try.haxe.org's sample at its
ES6 and full DCE settings, and PiratePig compile byte for byte as with
stock Haxe, bar Lime's random asset cache version and one float literal
the wasm build already printed with an extra digit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant