Skip to content

Instantly share code, notes, and snippets.

@mbauman
Created February 28, 2024 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbauman/60f311851c930ff6a094096ba4b95359 to your computer and use it in GitHub Desktop.
Save mbauman/60f311851c930ff6a094096ba4b95359 to your computer and use it in GitHub Desktop.
julia> using StructArrays
julia> begin
g(x::StructArray{<:Tuple{String}}) = nothing
g(x::StructArray{<:Tuple{Integer}}) = nothing
function f(x)
# ok, yes, this line is fairly contrived, but this is a short-hand for
# building a partial type-instability -- something that happens frequently
z1 = Core.compilerbarrier(:type, x)::StructArray{<:Tuple{Nothing}}
z2 = g(z1)
nothing === z2, z2
end
end;
julia> f(StructArray((Union{}[],)))
ERROR: MethodError: g(::StructVector{Tuple{Union{}}, Tuple{Vector{Union{}}}, Int64}) is ambiguous.
Candidates:
g(x::StructArray{<:Tuple{String}})
@ Main REPL[2]:2
g(x::StructArray{<:Tuple{Integer}})
@ Main REPL[2]:3
Possible fix, define
g(::StructArray{Union{}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment