Skip to content

Fix the dead Test-extension guard and let the extension implement a stub - #67

Open
devmotion wants to merge 2 commits into
masterfrom
dmw/fix-test-extension-guard
Open

devmotion wants to merge 2 commits into
masterfrom
dmw/fix-test-extension-guard

Conversation

@devmotion

Copy link
Copy Markdown
Member

Two commits, kept separate so the pre-existing bug stays in the history even though the second commit deletes the line it lives on.

1. Fix the extension name in the error hint. The guard queried :InverseFunctionsTest, but the extension is registered as InverseFunctionsTestExt. Base.get_extension returns nothing for an unknown name rather than erroring, so the guard was permanently true and "Did you forget to load Test?" was appended to every test_inverse MethodError — including ones raised while Test is loaded.

2. Let the extension implement an internal stub. test_inverse becomes a regular method that forwards to _test_inverse, implemented by InverseFunctionsTestExt. That removes __init__, which is the expensive part: on Julia 1.10 (LTS) it costs 17–20 ms of load time, ~80% of it compilation, and an empty __init__ costs the same, so the cost is having one at all. Load time drops to 1.3–1.9 ms; precompilation gets cheaper too.

Compared with a Base.get_extension lookup, the stub needs no extension-name literal — the construct behind the bug in commit 1 — and stays statically resolvable, so it does not trip the --trim verifier. Arity errors go through ordinary dispatch, so no internal method leaks into "Closest candidates".

Behaviour change: a correct-arity call without Test now throws ArgumentError instead of a MethodError carrying a hint, and a wrong-arity call without Test gets a plain MethodError with no hint. The latter is inherent to removing __init__ on Julia ≤ 1.10.

Tests cover both directions, plus @test !isdefined(InverseFunctions, :__init__) so the load-time fix cannot be silently reverted. Full suite passes on 1.11; error shapes and happy path checked on 1.6, 1.10 and 1.11.

Closes #62 (same goal, different route — credit to @Beforerr for identifying the load-time cost) and closes #66 (version bumped to 0.1.18 here).

🤖 Generated with Claude Code

devmotion and others added 2 commits September 21, 2026 13:26
`Base.get_extension` returns `nothing` for an unknown extension name, so
querying `:InverseFunctionsTest` instead of `:InverseFunctionsTestExt` left
the guard permanently true: "Did you forget to load Test?" was appended to
every `test_inverse` `MethodError`, including those raised when `Test` is
loaded and the extension method exists.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`test_inverse` is now a regular method of the package that forwards to
`_test_inverse`, which `InverseFunctionsTestExt` implements. This removes
`__init__` and with it the error hint: registering the hint cost 17-20 ms of
load time on Julia 1.10 (~80% of it compilation), and an empty `__init__`
costs the same, so the cost is having one at all. Precompilation gets cheaper
too, since `__init__` also runs there.

Arity errors now go through ordinary dispatch, so no internal method leaks
into "Closest candidates", and the "load Test" message cannot be emitted
while the extension is loaded. Unlike a `Base.get_extension` lookup, the stub
needs no extension name literal -- the source of the bug fixed in the
previous commit -- and stays statically resolvable, so it does not trip the
`--trim` verifier.

Behaviour change: a correct-arity call without `Test` now throws an
`ArgumentError` instead of a `MethodError` carrying a hint, and a wrong-arity
call without `Test` gets a plain `MethodError` with no hint at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.49%. Comparing base (0434eba) to head (d51de21).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage   98.48%   98.49%   +0.01%     
==========================================
  Files           6        6              
  Lines         132      133       +1     
==========================================
+ Hits          130      131       +1     
  Misses          2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@devmotion
devmotion requested a review from oschulz September 21, 2026 11:58

This branch has not been deployed

No deployments
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