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

Incorrect subtyping result for Ref{Vector{Tuple{K}} where K} <: Ref{<:Vector{K}} where K #50716

Closed
topolarity opened this issue Jul 29, 2023 · 3 comments · Fixed by #50832
Closed
Labels
bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch

Comments

@topolarity
Copy link
Member

I might be reasoning about this incorrectly, but Julia declares:

julia> Ref{Vector{Tuple{K}} where K} <: Ref{<:Vector{K}} where K
true

I think this is incorrect because it requires proving that ∃K'. (Vector{Tuple{K}} where K) <: Vector{K'} which is false.

For comparison:

julia> Ref{Vector{K} where K} <: Ref{<:Vector{K}} where K
false
@topolarity topolarity added bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch labels Jul 29, 2023
@N5N3
Copy link
Member

N5N3 commented Aug 6, 2023

Another comparison:

julia> Ref{Vector{Tuple{K}} where K} <: Ref{<:Vector{K}} where K
true

julia> Ref{Vector{Val{K}} where K} <: Ref{<:Vector{K}} where K
false

Fixing should be simple, just replace var_occurs_invariant(t, v) with var_occurs_inside(t, v, 0, 0)

julia/src/subtype.c

Lines 937 to 950 in 9f9e989

jl_varbinding_t *btemp = e->vars;
if (vb.lb != vb.ub) {
while (btemp != NULL) {
jl_value_t *vu = btemp->ub;
jl_value_t *vl = btemp->lb;
// TODO: this takes a significant amount of time
if (btemp->depth0 != vb.depth0 &&
((vu != (jl_value_t*)vb.var && btemp->var->ub != vu && var_occurs_invariant(vu, vb.var)) ||
(vl != (jl_value_t*)vb.var && btemp->var->lb != vl && var_occurs_invariant(vl, vb.var)))) {
ans = 0; break;
}
btemp = btemp->prev;
}
}

Perhaps a typo in #24104?

@vtjnash
Copy link
Member

vtjnash commented Aug 8, 2023

Seems to have been intentional, but simply was wrong. Perhaps at the time it was avoiding some other bug. Did you want to make a PR and we can try PkgEval on it?

@topolarity
Copy link
Member Author

Thanks @N5N3 !

KristofferC pushed a commit that referenced this issue Oct 29, 2024
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 types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants