Skip to content

fix(compiler): box a value-typed callee before the cast to IFn - #172

Merged
skydread1 merged 2 commits into
developfrom
fix/value-type-in-fn-position
Sep 2, 2026
Merged

fix(compiler): box a value-typed callee before the cast to IFn#172
skydread1 merged 2 commits into
developfrom
fix/value-type-in-fn-position

Conversation

@skydread1

Copy link
Copy Markdown
Member

Closes #171

  • Calling something that is not a function throws a catchable InvalidCastException, matching JVM Clojure, which throws ClassCastException for the same form. A value-typed callee reached the cast to IFn unboxed, and castclass needs an object reference, so the JIT refused the whole method instead of the cast throwing.
  • The conversion is guarded on the callee being a value type. Converting unconditionally sends an interface-typed callee through castclass Object and re-emits every invoke in the tree; with the guard, check-drift recompiles the whole stdlib to identical bytes.

ifn-invoke-compiler boxes a value-typed callee, so the cast to IFn runs on
an object reference and the method verifies. castclass needs a reference,
and the callee reached it unboxed, which made the JIT refuse the whole
method. JVM Clojure emits the same shape, and the arguments beside it
already convert the same way.

The conversion is guarded on the callee being a value type: converting
unconditionally sends an interface-typed callee through castclass Object
and re-emits every invoke in the tree.
@skydread1 skydread1 self-assigned this Sep 2, 2026
@skydread1
skydread1 merged commit e2dace5 into develop Sep 2, 2026
1 check passed
@skydread1
skydread1 deleted the fix/value-type-in-fn-position branch September 2, 2026 13:22
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.

Calling something that is not a function reports "Invalid IL code" instead of a cast error

1 participant