code_warntype is being a bit misleading there. code inference hasn't yet
fully run on the inner function.

On Sat Jan 31 2015 at 7:21:56 PM Kirill Ignatiev <[email protected]>
wrote:

> Consider the following function:
>
> function f()
>>   x::Float64 = 1.0
>>   function g(y::Float64)
>>     x += y
>>   end
>>   g(2.0)
>>   g(3.0)
>>   x
>> end
>
>
> Then @code_warntype gives:
>
> julia> @code_warntype f()
>> Variables:
>>   x::Float64
>>   g::F
>> Body:
>>   begin  # /***.jl, line 310:
>>       NewvarNode(:x)
>>       x = 1.0 # line 311:
>>       $(Expr(:method, :g,
>> :((top(tuple))((top(tuple))(Float64)::Any,(top(tuple))()::Any)::Any),
>> AST(:($(Expr(:lambda, Any[:y],
>> Any[Any[symbol("#s5504")],Any[Any[:y,Any,0],Any[symbol("#s5504"),Any,18]],Any[Any[:x,Float64,7]]],
>> :(begin  # /***.jl, line 312:
>>         #s5504 = x + y::Any
>>         x =
>> (top(typeassert))((top(convert))(Float64,#s5504)::Any,Float64)::Any
>>         return #s5504
>>     end::Any))))), false)) # line 314:
>>       (g::F)(2.0)::Any # line 315:
>>       (g::F)(3.0)::Any # line 316:
>>       return x::Float64
>>   end::Float64
>
>
> Is there anything I can do to make it recognize that the type of x doesn't
> change here? It seems to think that "y" can be Any, despite the annotation
> saying it can only be Float64. I am missing something here?
>

Reply via email to