Skip to content

Inference failure for Ref{Int}? #38133

@kcajf

Description

@kcajf
julia> struct Foo
           i::Ref{Int}
       end

julia> f = Foo(Ref(0))
Foo(Base.RefValue{Int64}(0))

julia> g(x) = x.i[]
g (generic function with 1 method)

julia> @code_warntype g(f)
Variables
  #self#::Core.Const(g)
  x::Foo

Body::Any
1 ─ %1 = Base.getproperty(x, :i)::Ref{Int64}
│   %2 = Base.getindex(%1)::Any
└──      return %2

julia> versioninfo()
Julia Version 1.6.0-DEV.1227
Commit 86bbe0941c (2020-10-15 00:29 UTC)

I thought this would infer the return type as Int, but it only manages Any. Am I doing something wrong, or is this expected? Is there a situation where the dereference can return something other than Int?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions