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

counterexample for subtyping transitivity involving types of types #57754

Open
nsajko opened this issue Mar 13, 2025 · 1 comment
Open

counterexample for subtyping transitivity involving types of types #57754

nsajko opened this issue Mar 13, 2025 · 1 comment
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@nsajko
Copy link
Contributor

nsajko commented Mar 13, 2025

julia> a = Type{Tuple{UnitRange{Int64}, Symbol, X} where {X}}
Type{Tuple{UnitRange{Int64}, Symbol, X} where X}

julia> b = Type{Tuple{UnitRange{Int64}, Symbol, Any}}
Type{Tuple{UnitRange{Int64}, Symbol, Any}}

julia> c = DataType
DataType

julia> a <: b
true

julia> a <: c
false

julia> b <: a
true

julia> b <: c
true

julia> c <: a
false

julia> c <: b
false

So we have (a <: b) && (b <: c), but !(a <: c).

See also comments by @topolarity here: #57631 (comment)

@nsajko nsajko added the types and dispatch Types, subtyping and method dispatch label Mar 13, 2025
@topolarity
Copy link
Member

To be explicit, this is the cause of unsoundness in inference:

foo(x::Type{Tuple{Integer}}, y::DataType) = (@noinline rand(Bool)) ? x : y
function bar()
    A = Core.compilerbarrier(:type, Tuple{X} where X<:Integer)
    B = Core.compilerbarrier(:type, Int)
    T = @noinline foo(A, B)
    @show T
    @show T isa DataType
    return T
end
julia> @show bar() isa DataType;
T = Tuple{X} where X<:Integer
T isa DataType = true
bar() isa DataType = false

Sometimes transitivity issues are benign, but not in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

2 participants