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

unreachable reached when struct constructor trys to convert a Vector{Union{Nothing, T} where T} to a Vector{Any} #38091

Closed
Roger-luo opened this issue Oct 19, 2020 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@Roger-luo
Copy link
Contributor

MWE:

struct Foo
   a::Vector{Any}
end

xs = Vector{Union{Nothing, T} where T}([2, 3])
Foo(xs)

this leads to "illegal hardware instruction" on both Julia 1.5.2 and julia 1.6.0-DEV.1184

The lowered code and typed code seems fine, but code_llvm gives

julia> @code_llvm Foo(xs)
;  @ REPL[1]:2 within `Foo'
define [1 x {}*] @julia_Foo_491({}* nonnull align 16 dereferenceable(40) %0) {
top:
  call void @llvm.trap()
  unreachable
}

also I find that the result of convert and Vector{Any}(x) does not match, though convert actually (should) calls Vector{Any} to convert xs to Vector{Any} (https://github.com/JuliaLang/julia/blob/master/base/array.jl#L554), e.g

julia> convert(Vector{Any}, xs)
2-element Vector{Union{Nothing, T} where T}:
 2
 3

julia> Vector{Any}(xs)
2-element Vector{Any}:
 2
 3

This is because Julia thinks xs of type Vector{Union{Nothing, T} where T} is a Vector{Any}, so convert returns xs directly but I'm not sure if this is actually true...

@KristofferC KristofferC added the bug Indicates an unexpected problem or unintended behavior label Oct 19, 2020
@vtjnash
Copy link
Member

vtjnash commented Oct 19, 2020

It is trivially true:

julia> Any == Union{Nothing, T} where T
true

But datatype creation is not handling this

@vtjnash
Copy link
Member

vtjnash commented Oct 19, 2020

Duplicate of #35130

@vtjnash vtjnash marked this as a duplicate of #35130 Oct 19, 2020
@vtjnash vtjnash closed this as completed Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants