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

Undefined typevar when it is clearly defined #55933

Closed
wsmoses opened this issue Sep 29, 2024 · 8 comments
Closed

Undefined typevar when it is clearly defined #55933

wsmoses opened this issue Sep 29, 2024 · 8 comments
Labels
bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch

Comments

@wsmoses
Copy link
Contributor

wsmoses commented Sep 29, 2024

On Julia 1.10.5

julia> T = (Vector{Tuple{Code}} where {Code<:Integer})
Array{Tuple{Code}, 1} where Code<:Integer

julia> eltype(T)
Any

julia> @inline ptreltype(::Type{Array{T,N}}) where {T,N} = T
ptreltype (generic function with 1 method)

julia> ptreltype(T)
ERROR: UndefVarError: `T` not defined
Stacktrace:
 [1] ptreltype(::Type{Array{Tuple{Code}, 1} where Code<:Integer})
   @ Main ./REPL[6]:1
 [2] top-level scope
   @ REPL[7]:1

Not entirely sure what I would expect here (actually I would expect a methoderror), but definitely not this.

cc @mofeing

@timholy
Copy link
Member

timholy commented Sep 29, 2024

Seems reasonable to me? This is where @isdefined comes in to play.

@wsmoses
Copy link
Contributor Author

wsmoses commented Sep 29, 2024

Howso?

Consider this code which similarly crashes. I would expect this to return nothing.

julia> T = (Vector{Tuple{Code}} where {Code<:Integer})
Array{Tuple{Code}, 1} where Code<:Integer

julia> @inline ptreltype(x) = nothing
ptreltype (generic function with 1 method)

julia> @inline ptreltype(::Type{Array{T,N}}) where {T,N} = T
ptreltype (generic function with 2 methods)

julia> ptreltype(T)
ERROR: UndefVarError: `T` not defined
Stacktrace:
 [1] ptreltype(::Type{Array{Tuple{Code}, 1} where Code<:Integer})
   @ Main ./REPL[3]:1
 [2] top-level scope
   @ REPL[4]:1

@wsmoses
Copy link
Contributor Author

wsmoses commented Sep 29, 2024

cc @vchuravy @gbaraldi

@vtjnash
Copy link
Member

vtjnash commented Sep 29, 2024

It appears to be fixed in v1.11

$ julia +v1.10
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0 (2023-12-25)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |

julia> Type{Vector{Tuple{Code}} where {Code}} <: Type{Vector{T}} where T
true

julia> Type{Vector{Tuple{Code}} where {Code<:Integer}} <: Type{Vector{T}} where T
true

julia> Type{Vector{Tuple{Code}} where {Code<:Integer}} <: Type{Array{T, N}} where {T, N}
true

julia> typeintersect(Type{Vector{Tuple{Code}} where {Code}}, Type{Vector{T}} where T)
Type{Array{Tuple{Code}, 1} where Code}

julia> typeintersect(Type{Vector{Tuple{Code}} where {Code}}, Type{Array{T,N}} where {T,N})
Type{Array{Tuple{Code}, 1} where Code}

julia> typeintersect(Type{Vector{Tuple{Code}} where {Code<:Integer}}, Type{Array{T,N}} where {T,N})
Type{Array{Tuple{Code}, 1} where Code<:Integer}

$ julia +v1.11
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.0-rc2.54 (2024-08-19)
 _/ |\__'_|_|_|\__'_|  |  backports-release-1.11/8c60a17508d* (fork: 359 commits, 226 days)
|__/                   |

julia> Type{Vector{Tuple{Code}} where {Code}} <: Type{Vector{T}} where T
false

julia> Type{Vector{Tuple{Code}} where {Code<:Integer}} <: Type{Vector{T}} where T
false

julia> Type{Vector{Tuple{Code}} where {Code<:Integer}} <: Type{Array{T, N}} where {T, N}
false

julia> typeintersect(Type{Vector{Tuple{Code}} where {Code}}, Type{Vector{T}} where T)
Union{}

julia> typeintersect(Type{Vector{Tuple{Code}} where {Code}}, Type{Array{T,N}} where {T,N})
Union{}

julia> typeintersect(Type{Vector{Tuple{Code}} where {Code<:Integer}}, Type{Array{T,N}} where {T,N})
Union{}

@wsmoses
Copy link
Contributor Author

wsmoses commented Sep 29, 2024

Any chance whatever the fix was can get backported?

@nsajko nsajko added the types and dispatch Types, subtyping and method dispatch label Sep 29, 2024
@wsmoses wsmoses added the bug Indicates an unexpected problem or unintended behavior label Sep 30, 2024
@wsmoses
Copy link
Contributor Author

wsmoses commented Oct 23, 2024

gentle bump for backporting the fix

@KristofferC
Copy link
Member

Someone needs to identify the fix.

@mofeing
Copy link
Contributor

mofeing commented Oct 27, 2024

I've bisected the commits and found that ebae716 is the commit that fixed the bug.

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

No branches or pull requests

7 participants