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

typeassert does not constrain types on subsequent path #25632

Open
Keno opened this issue Jan 18, 2018 · 0 comments
Open

typeassert does not constrain types on subsequent path #25632

Keno opened this issue Jan 18, 2018 · 0 comments
Assignees
Labels
compiler:inference Type inference

Comments

@Keno
Copy link
Member

Keno commented Jan 18, 2018

function foo(x)
       a = x ? (1,2) : nothing
       a::Tuple
       a[1]
end
@code_warntype foo(true)
Variables:
  x::Bool
  a::Union{Nothing, Tuple{Int64,Int64}}
  #temp#@_4::Union{Nothing, Tuple{Int64,Int64}}
  #temp#@_5::Int64

Body:
  begin
      unless x::Bool goto 4
      #temp#@_4::Union{Nothing, Tuple{Int64,Int64}} = (1, 2)
      goto 6
      4:
      #temp#@_4::Union{Nothing, Tuple{Int64,Int64}} = Main.nothing
      6:
      a::Union{Nothing, Tuple{Int64,Int64}} = #temp#@_4::Union{Nothing, Tuple{Int64,Int64}}
      #= line 3 =#
      (Core.typeassert)(a::Union{Nothing, Tuple{Int64,Int64}}, Main.Tuple)::Tuple{Int64,Int64}
      #= line 4 =#
      SSAValue(1) = (a::Union{Nothing, Tuple{Int64,Int64}} isa Tuple{Int64,Int64})::Bool
      unless SSAValue(1) goto 15
      #temp#@_5::Int64 = $(Expr(:invoke, MethodInstance for getindex(::Tuple{Int64,Int64}, ::Int64), :(Main.getindex), :(a), 1))::Int64
      goto 20
      15:
      goto 17
      17:
      #temp#@_5::Int64 = (Main.getindex)(a::Union{Nothing, Tuple{Int64,Int64}}, 1)::Int64
      goto 20
      20:
      SSAValue(0) = #temp#@_5::Int64
      return SSAValue(0)
  end::Int64

There should be a TypedSlot on the getindex since we know that after the typeassert a can't be nothing.

@Keno Keno added the compiler:inference Type inference label Jan 18, 2018
@vtjnash vtjnash self-assigned this Jul 10, 2018
@vtjnash vtjnash added this to the 1.x milestone Jul 10, 2018
@DilumAluthge DilumAluthge removed this from the 1.x milestone Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

3 participants