Skip to content

TypeId: the counter starts lazily, without __init__ - #25

Merged
back2dos merged 1 commit into
masterfrom
lazy-type-id
Nov 29, 2026
Merged

back2dos merged 1 commit into
masterfrom
lazy-type-id

Conversation

@back2dos

Copy link
Copy Markdown
Member

TypeId's counter was reset to 0 in __init__. TypeIds are made by other classes' static initializers (every factory's TYPE, VEmpty.TYPE, ...), so this relies on every __init__ running before every static initializer. JS and HL generate it that way, but Haxe doesn't document it.

hxmc runs an __init__ after the statics of classes it reached earlier. Three modules reproduce it:

A.TYPE, B.TYPE, then a third id
js 0, 1, 2
hxmc 0, 1, 0 (the reset came after A and B)

In coconut.appkit (native AppKit views) the repeated ids made the differ take a native view's node type for the empty node's, which ended in invalid cast in RNativeBase.update when a <Box> was replaced by null.

The change: the counter is Null<Int>, null until the first id is taken. There's no __init__ and no initializer, so the result doesn't depend on initialization order. On JS an untouched static is undefined, which == null. TypeIds are made once per node type (in statics), so the extra test costs nothing.

Tested:

  • Ids 0, 1, 2 on JS (node) and on hxmc, with another class's static taking the first one.
  • coconut.appkit's demo test with this code as a patch: all checks pass.

Not tested: the repo's own tests. Its pinned Haxe 4.2.1 is an x86 binary this Mac can't run, and the pinned tink_core 2.0.2 doesn't compile under 4.3.7 ("Recursive implicit cast" in Promise.hx), unrelated to this change.

The v1 branch has the same TypeId. I can port this there too.

🤖 Generated with Claude Code

TypeIds are made by other classes' static initializers (factories'
`TYPE`s), and Haxe documents no order between those and TypeId's own
static initialization. Under hxmc, `__init__` ran after the statics of
classes reached earlier: it reset the counter, later ids repeated earlier
ones, and the differ took one node type for another (a native view for
an empty node: "invalid cast" in RNativeBase.update). The counter is now
null until the first id is taken, which holds whatever the order. TypeIds
are made once per node type, so the test costs nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@back2dos
back2dos merged commit 3b819e2 into master Nov 29, 2026
1 of 41 checks passed
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