Skip to content

Test for closure boxes on Julia 1.14+ - #88

Merged
maleadt merged 1 commit into
mainfrom
tb/closure-boxes
Oct 18, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/closure-boxes

Conversation

@maleadt

@maleadt maleadt commented Oct 18, 2026

Copy link
Copy Markdown
Member

This adds a closure boxes testset that runs Test.detect_closure_boxes(ObjectiveC) on Julia versions that have it (1.14+), so that captured variables ending up in a Core.Box get caught in CI. The function also scans submodules, so Foundation, CoreFoundation, Dispatch and OS are covered too. It would also catch regressions like the box in os_log_with_type on #87.

On main it found three boxes, fixed here without changing behavior:

methods(::Class) reassigned meths after capturing it in a comprehension, so the second array now has its own name. In objcm, the parse_argument closure assigned to value and typ, which also exist in the enclosing function, so they're now declared local in the closure. The argument arrays were also reassigned to fresh empty arrays when the method is a plain symbol, which was redundant, so that branch is gone. @objcproperties defined process_property as a recursive local function, which is now a module-level process_property! that takes the property list and module as arguments.

Tests pass on 1.10, 1.12 and nightly. On nightly the new test fails without the fixes.

On Julia 1.14+, use `Test.detect_closure_boxes` to check that no method in
ObjectiveC or its submodules captures a variable in a `Core.Box`, which makes
that variable type-unstable. This catches regressions where a closure
captures a variable that is reassigned.

Three boxes existed: `methods(::Class)` reused `meths` after capturing it in
a comprehension, `objcm`'s `parse_argument` closure assigned to `value` and
`typ` from the enclosing scope and the argument arrays were redundantly
reassigned, and `@objcproperties` defined a recursive local function. Use a
separate name, a `local` declaration with no reassignment, and a module-level
function respectively.
@maleadt
maleadt merged commit a33043c into main Oct 18, 2026
12 checks passed
@maleadt
maleadt deleted the tb/closure-boxes branch October 18, 2026 13:23
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