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

Strange error in constructor to Base.Fix2 #35661

Open
jlumpe opened this issue Apr 30, 2020 · 4 comments
Open

Strange error in constructor to Base.Fix2 #35661

jlumpe opened this issue Apr 30, 2020 · 4 comments
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@jlumpe
Copy link
Contributor

jlumpe commented Apr 30, 2020

I originally encountered this while playing around with the type system in IJulia. Here is a minimum example in that context:

In[1]:   T = Tuple{A} where A

Out[1]:  Tuple{A} where A
In[2]:   print(T.body)

Out[2]:  Tuple{A}
In[3]:  display(T.body)

TypeError: in new, expected UnionAll, got Type{Tuple{A}}

Stacktrace:
 [1] Base.Fix2(::typeof(isequal), ::Type{Tuple{A} where A}) at ./operators.jl:910
 [2] isequal(::Type{T} where T) at ./operators.jl:925
 [3] undisplay at /Users/student/.julia/packages/IJulia/yLI42/src/display.jl:125 [inlined]
 [4] display(::IJulia.InlineDisplay, ::Type{T} where T) at /Users/student/.julia/packages/IJulia/yLI42/src/inline.jl:94
 [5] display(::Any) at ./multimedia.jl:323
 [6] top-level scope at In[3]:1

I can shorten this to:

In[1]:   T = Tuple{A} where A

Out[1]:  Tuple{A} where A
In[2]:   Base.Fix2(isequal, T)

TypeError: in new, expected UnionAll, got Type{Tuple{A}}

Stacktrace:
 [1] Base.Fix2(::typeof(isequal), ::Type{Tuple{A} where A}) at ./operators.jl:910
 [2] top-level scope at In[2]:1

At first I could not recreate this in the REPL, but after a lot of playing around I figured out it is dependent on display(T) and thus Fix2(isequal, T) being called when showing the result of the first cell.

The following script is a minimal reproducible example in versions 1.2 to 1.4:

T = Tuple{A} where A
@show Base.Fix2(isequal, T)
@show Base.Fix2(isequal, T.body)
Base.Fix2(isequal, T) = Base.Fix2{typeof(isequal),UnionAll}(isequal, Tuple{A} where A)
ERROR: LoadError: TypeError: in new, expected UnionAll, got Type{Tuple{A}}
Stacktrace:
 [1] Base.Fix2(::typeof(isequal), ::Type{Tuple{A} where A}) at ./operators.jl:910
 [2] top-level scope at show.jl:613
 [3] include(::Module, ::String) at ./Base.jl:377
 [4] exec_options(::Base.JLOptions) at ./client.jl:288
 [5] _start() at ./client.jl:484
in expression starting at /Users/student/git/jl-julia/ex-minimal.jl:3

This error occurs only in very specific but reproducible circumstances. It does not occur in the following examples:

Fix2 not called on T first:

T = Tuple{A} where A
@show Base.Fix2(isequal, T.body)
Base.Fix2(isequal, T.body) = Base.Fix2{typeof(isequal),DataType}(isequal, Tuple{A})

Called with different functions (functions other than isequal do cause an error if used for both):

T = Tuple{A} where A
@show Base.Fix2(isequal, T)
@show Base.Fix2(+, T.body)
Base.Fix2(isequal, T) = Base.Fix2{typeof(isequal),UnionAll}(isequal, Tuple{A} where A)
Base.Fix2(+, T.body) = Base.Fix2{typeof(+),DataType}(+, Tuple{A})

A second UnionAll identical to the first:

T = Tuple{A} where A
@show Base.Fix2(isequal, T)
try
	@show Base.Fix2(isequal, T.body)
catch e
	@error e
end

T2 = Tuple{A} where A
@assert T2 === T1
@show Base.Fix2(isequal, T2)
try
	@show Base.Fix2(isequal, T2.body)
catch e
	@error e
end
Base.Fix2(isequal, T) = Base.Fix2{typeof(isequal),UnionAll}(isequal, Tuple{A} where A)
┌ Error: TypeError(:new, "", UnionAll, Tuple{A})
└ @ Main ~/git/jl-julia/ex-t2.jl:6
Base.Fix2(isequal, T2) = Base.Fix2{typeof(isequal),UnionAll}(isequal, Tuple{A} where A)
Base.Fix2(isequal, T2.body) = Base.Fix2{typeof(isequal),DataType}(isequal, Tuple{A})
@JeffBezanson JeffBezanson added the types and dispatch Types, subtyping and method dispatch label Apr 30, 2020
@JeffBezanson
Copy link
Member

Similar to #28983; types with free variables misbehave a bit sometimes. We should try to fix this soon.

@JeffBezanson
Copy link
Member

Also related: #35130

@jakobnissen
Copy link
Contributor

Seems to be fixed on master?

@vtjnash
Copy link
Member

vtjnash commented Nov 15, 2021

no, confirmed not fixed

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

4 participants