Skip to content

Bug Report: Type argument not specializing for closures #45257

@schlichtanders

Description

@schlichtanders

According to the documentation it can happen, that julia does not specialize functions on Types (and same goes for Functions and Vararg, but I am focussing on Types here).

I think I found a case where Julia should naturally specialize, but does not do so: Creating closures with the type.

Here is an example of what I mean

myconvert(T, value) = T(value)

function outerfunc(type, value)
    innerfunc(x) = myconvert(type, x)
    innerfunc(value)
end
using Test
tostring(a) = "$a"
@inferred outerfunc(tostring, 1)
# "1"

@inferred outerfunc(Symbol, 1)
# ERROR: return type Symbol does not match inferred return type Any

Please correct me if this missing specialization is indeed an intended aspect of julia. It looks accidental to me.

Using Julia 1.7.1
julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, icelake-client)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions