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

Array of Parametric Typed data fails Type Equality (but passes Type Identity) #11243

Closed
oxinabox opened this issue May 12, 2015 · 3 comments
Closed
Labels
domain:types and dispatch Types, subtyping and method dispatch kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version

Comments

@oxinabox
Copy link
Contributor

On version: v"0.4.0-dev+4770"

I have made the MWE to illustrate:
Comments are the printed output of that/the preceeding line

Define the type:

abstract Side
abstract Left <: Side
abstract Right <: Side

type Hand{B<:Side}
    data::Int
end

create a Vector of it:

allhands = [Hand{Left}(5), Hand{Left}(6), Hand{Right}(2)]
#3-element Array{Hand{B<:Side},1}:
# Hand{Left}(5) 
# Hand{Left}(6) 
# Hand{Right}(2)

Check its equality:

println(typeof(allhands)) #Array{Hand{B<:Side},1}
println(Array{Hand,1})    #Array{Hand{B<:Side},1}
println(typeof(allhands) == Array{Hand,1}) #false
println(typeof(allhands) <: Array{Hand,1}) #false
println(typeof(allhands) === Array{Hand,1}) #true

That doesn't seem right at all.
How can they be Identical (===), but not Equal (==)?


Further, this breaks function calls:

function test(hands::Vector{Hand})
    print("yes")
end

println(methods(test))
#1 method for generic function "test":
# test(hands::Array{Hand{B<:Side},1}) 

test(allhands)
#LoadError: MethodError: `test` has no method matching test(::Array{Hand{B<:Side},1})
#Closest candidates are:
#  test(::Array{Hand{B<:Side},1})
@oxinabox
Copy link
Contributor Author

Futher:

println(isequal(typeof(allhands), Array{Hand,1})) #false
println(isequal(hash(typeof(allhands)), hash(Array{Hand,1}))) #true
println(isequal(object_id(typeof(allhands)), object_id(Array{Hand,1}))) #true
object_id(typeof(allhands)) |> println #0xf333652b378c7f4e
object_id(Array{Hand,1})  |> println  #0xf333652b378c7f4e

as well as:

println(Array{Hand,1}==Array{Hand,1}) #true
x=Array{Hand,1}
y=Array{Hand,1}
println(x==y) #true
println(x===y) #true

@oxinabox
Copy link
Contributor Author

Persistes with no change if the subtypes are made concrete:

abstract Side
#abstract Left <: Side
#abstract Right <: Side

type Left<:Side
end
type Right<:Side
end

Infact it persists even if the constraint is removed entirely:
As follows:

type Hand{T}
    data::Int
end

allhands = [Hand{Int}(5), Hand{Int}(6), Hand{Float64}(2)]

println(typeof(allhands)) #Array{Hand{T},1}
println(Array{Hand,1})    #Array{Hand{T},1}
println(typeof(allhands) == Array{Hand,1}) #false
println(typeof(allhands) <: Array{Hand,1}) #false
println(typeof(allhands) === Array{Hand,1}) #true

function test(hands::Vector{Hand})
    print("yes")
end

println(methods(test))
# 1 method for generic function "test":
# test(hands::Array{Hand{T},1}) 

test(allhands)
#LoadError: MethodError: `test` has no method matching test(::Array{Hand{T},1})
#Closest candidates are:
#  test(::Array{Hand{T},1})

What does work is:

function test_vec(hands::Vector)
    print("yes")
end

println(methods(test_vec))
# 1 method for generic function "test_vec":
#test_vec(hands::Array{T,1}) 

test_vec(allhands) #yes

@oxinabox
Copy link
Contributor Author

I can confirm that all works as expect in v"0.3.9-pre+12"
So this is a 0.4 bug.
Not surprising I guess, it will need a regression test.
Unless it is a breaking change that I missed.

@oxinabox oxinabox changed the title Array of Parametric Typed data fails Type Equality (but Passed Type Identity) Array of Parametric Typed data fails Type Equality (but passes Type Identity) May 12, 2015
@vtjnash vtjnash added the kind:bug Indicates an unexpected problem or unintended behavior label May 12, 2015
@simonster simonster added domain:types and dispatch Types, subtyping and method dispatch kind:regression Regression in behavior compared to a previous version labels May 13, 2015
mbauman pushed a commit to mbauman/julia that referenced this issue Jun 6, 2015
looks like I had tried to add a clause to jl_subtype_le that wasn't
present in 0.3. failed experiment I guess.
tkelman pushed a commit to tkelman/julia that referenced this issue Jun 6, 2015
looks like I had tried to add a clause to jl_subtype_le that wasn't
present in 0.3. failed experiment I guess.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:types and dispatch Types, subtyping and method dispatch kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

3 participants