Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Type inference case #16050

Closed
davidanthoff opened this issue Apr 26, 2016 · 1 comment
Closed

Type inference case #16050

davidanthoff opened this issue Apr 26, 2016 · 1 comment

Comments

@davidanthoff
Copy link
Contributor

This is on julia 0.4.5 on Windows:

function get_f()
    f1(x) = 2x

    function f2()
        b = f1(2)

        return b
    end

    return f2
end

f = get_f()

@code_warntype f()

I get

Variables:
  b::Any

Body:
  begin  # C:\Users\anthoff\source\4sD.jl\test2.jl, line 5:
      b = f1(2)::Any # C:\Users\anthoff\source\4sD.jl\test2.jl, line 7:
      return b
  end::Any

Could type inference work better here, i.e. type b properly?

I'm not sure how to title this issue, please adjust if this issue makes sense.

@yuyichao
Copy link
Contributor

Not sure what's causing this on 0.4 but on 0.5 this is caused by #15276 on 0.5. I'm going to close this as a dup of #15276 since it's unlikely we'll change anything about this on 0.4.

julia> function get_f()
           f1 = (x) -> 2x

           f2 = function()
               b = f1(2)

               return b
           end

           return f2
       end
get_f (generic function with 1 method)

julia> @code_warntype get_f()
Variables:
  #self#::#get_f
  f1::Core.Box
  #1::##1#3
  f2::##2#4
  #2::##2#4

Body:
  begin  # REPL[0], line 2:
      f1::Core.Box = $(Expr(:new, :((top(getfield))(Core,:Box)::Type{Core.Box})))
      #1::##1#3 = $(Expr(:new, :(Main.##1#3)))
      GenSym(0) = #1::##1#3
      (top(setfield!))(f1::Core.Box,:contents,GenSym(0))::##1#3 # REPL[0], line 4:
      #2::##2#4 = $(Expr(:new, :(Main.##2#4), :(f1::Core.Box)))
      f2::##2#4 = #2::##2#4 # REPL[0], line 10:
      return f2::##2#4
  end::##2#4

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants