Closed mchitre closed 6 months ago
This looks good. If it's not possible to find a reasonable test today then I'd accept without a test.
One discussion to have though, before we merge...
An alternative to skipping the check if type inference returns Any
is to check if the type inference result is a supertype of typeof(f₀)
instead. That will deal with type inference working, partially working or failing in a uniform way.
Something like:
inferredtype >: typeof(f₀)
or f₀ isa inferredtype
I don't know if partial inference failures are possible, or if there are downsides to doing this. So I kept the PR simpler, but if you feel this might be a better implementation, I am happy to amend.
I think the less inferred form can show up from some forms of array indexing, so I like that change.
Changed to check f₀ isa inferredtype
.
Codecov did something weird but tests look fine.
Problem
The current implementation checks that
typeof(u0/t) == typeof(du)
by type inference usingBase.promote_op()
. If they are unequal, it throws an error. The problem is that the type inference can fail, even if the actual types are equal. As the documentation ofBase.promote_op()
says:The problem is not hypothetical, but actually occurs at times, but is hard to pin down. For example, with Julia 1.10.2, if I create a new environment with just
MonteCarloMeasurements.jl
:the inference fails, as seen above. The exact same code works with same version of Julia when the environment has some other packages installed (not loaded), although the exact packages needed have been elusive.
Solution
The solution is simply to accept that the inference may result in not the exact type, but a supertype sometimes.
Checklist
Additional context
Test could not be added because the conditions under which type inference fails are highly dependent on Julia version and also what other packages are installed and loaded in what order.