Skip to content

Fix nospecializing Functions in Union{Nothing,Function} params (#59327) #251

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: v1.10.2+RAI
Choose a base branch
from

Conversation

NHDaly
Copy link
Member

@NHDaly NHDaly commented Aug 21, 2025

PR Description

Backports JuliaLang#59327.

Original PR description:

Fixes JuliaLang#59326.

Change the logic that decides not to specialize a function parameter based on whether or not the supplied argument is a Function, and that function is not used, so that it will still work if the SpecType is a Union{Function,Nothing} or any other union that contains a Function.

The logic is changed from a hardcoded rule of type_i == Function || type_i == Any || type_i == Base.Callable to type_i >: Function.

This covers all of the above cases, but also includes custom Union{Function, T} such as Union{Function, Nothing}.

Checklist

Requirements for merging:

…iaLang#59327)

Fixes JuliaLang#59326.

Change the logic that decides not to specialize a function parameter
based on whether or not the supplied argument is a Function, and that
function is not used, so that it will still work if the SpecType is a
Union{Function,Nothing} or any other union that contains a Function.

The logic is changed from a hardcoded rule of `type_i == Function ||
type_i == Any || type_i == Base.Callable` to `type_i >: Function`.

This covers all of the above cases, but also includes custom
`Union{Function, T}` such as `Union{Function, Nothing}`.

---------

Co-authored-by: Nick Robinson <npr251@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
@NHDaly NHDaly added port-to-v1.12 This change should apply to Julia v1.12 builds port-to-v1.10 labels Aug 21, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
port-to-master port-to-v1.10 port-to-v1.12 This change should apply to Julia v1.12 builds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Method parameter type annotation Union{Function, Nothing} causes incorrect specialization on concrete Function type
1 participant