Question on Type Inference with Anonymous Functions and Broadcast

julia> x = range(0, 1, 2^5)
0.0:0.03225806451612903:1.0

julia> f(x) = exp(2 * x)
f (generic function with 1 method)

julia> @code_warntype (x -> f(x)).(x)
MethodInstance for (::var"##dotfunction#291#2")(::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
  from (::var"##dotfunction#291#2")(x1) in Main
Arguments
  #self#::Core.Const(var"##dotfunction#291#2"())
  x1::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}
Locals
  #1::var"#1#3"
Body::Vector{Float64}
1 ─      (#1 = %new(Main.:(var"#1#3")))
│   %2 = #1::Core.Const(var"#1#3"())
│   %3 = Base.broadcasted(%2, x1)::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, var"#1#3", Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
│   %4 = Base.materialize(%3)::Vector{Float64}
└──      return %4


julia> const h = x -> f(x)
#4 (generic function with 1 method)

julia> @code_warntype h.(x)
MethodInstance for (::var"##dotfunction#292#6")(::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
  from (::var"##dotfunction#292#6")(x1) in Main
Arguments
  #self#::Core.Const(var"##dotfunction#292#6"())
  x1::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}
Body::Vector{Float64}
1 ─ %1 = Base.broadcasted(Main.h, x1)::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, var"#4#5", Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
│   %2 = Base.materialize(%1)::Vector{Float64}
└──      return %2

so as you can see the problem is that in your code the binding h = x -> f(x) is not a constant (the type of value bound to h might change).