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

fix some bugs in diagonal subtyping #31833

Closed
wants to merge 2 commits into from
Closed

fix some bugs in diagonal subtyping #31833

wants to merge 2 commits into from

Conversation

JeffBezanson
Copy link
Member

fixes #31824, fixes #24166

This is slightly breaking, since convert(NTuple, (1,"")) used to work but now gives a MethodError. I'm convinced it's correct though, since NTuple means "homogeneous tuple".

@JeffBezanson JeffBezanson added breaking This change will break code types and dispatch Types, subtyping and method dispatch bugfix This change fixes an existing bug labels Apr 25, 2019
@@ -28,11 +28,8 @@ end
@test convert(Tuple{Int, Int, Float64}, (1, 2, 3)) === (1, 2, 3.0)

@test convert(Tuple{Float64, Int, UInt8}, (1.0, 2, 0x3)) === (1.0, 2, 0x3)
@test convert(NTuple, (1.0, 2, 0x3)) === (1.0, 2, 0x3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to NTuple{N, Real} where N or something similar?

@test convert(Tuple{Vararg{Int}}, (1.0, 2, 0x3)) === (1, 2, 3)
@test convert(Tuple{Int, Vararg{Int}}, (1.0, 2, 0x3)) === (1, 2, 3)
@test convert(Tuple{Vararg{T}} where T<:Integer, (1.0, 2, 0x3)) === (1, 2, 0x3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuple{Vararg{Integer}}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. In fact we need a new method to handle that now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, one downside to making the element type inside Vararg diagonal is that Tuple{Vararg{Integer}} doesn't match Tuple{Vararg{T}} where T. In fact I can't find a type that includes all such vararg types without also including NTuple, which you can't sensibly convert to. AFAICT, the best we can do is adding a type assertion to the conversion method to make sure the result is valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, I'm not convinced the following normalization is correct:

julia> Tuple{Vararg{T where T<:S}} where S
Tuple{Vararg{S,N} where N} where S

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point; I would put all the blame on the diagonal rule however --- it's too structure-based, so potentially all sorts of rearrangements get in its way.

@JeffBezanson JeffBezanson force-pushed the jb/diagfix branch 4 times, most recently from 8960c6c to 7113fec Compare April 26, 2019 17:16
test/tuple.jl Outdated
# issue #31824
# there is no generic way to convert an arbitrary tuple to a homogeneous tuple
@test_throws MethodError convert(NTuple, (1, 1.0))
@test_throws MethodError convert(Tuple{Vararg{T}} where T<:Integer, (1.0, 2, 0x3)) === (1, 2, 0x3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test_throws MethodError convert(Tuple{Vararg{T}} where T<:Integer, (1.0, 2, 0x3)) === (1, 2, 0x3)
let T = Tuple{Vararg{T}} where T<:Integer, v = (1.0, 2, 0x3)
@test_throws MethodError(convert, (T, v)) convert(T, v)
end

@JeffBezanson
Copy link
Member Author

@nanosoldier runtests(ALL, vs = ":master")

@maleadt
Copy link
Member

maleadt commented Dec 12, 2019

Something went wrong when running your job:

NanosoldierError: failed to run tests against primary commit: UndefVarError: prnumber not defined

Logs and partial data can be found here
cc @maleadt

@JeffBezanson JeffBezanson added this to the 1.4 milestone Dec 13, 2019
@maleadt
Copy link
Member

maleadt commented Dec 16, 2019

NanosoldierError: failed to run tests against primary commit: UndefVarError: prnumber not defined

Ah, that's a bug. I'll fix it and re-trigger.

@JuliaLang JuliaLang deleted a comment from JeffBezanson Dec 16, 2019
@maleadt
Copy link
Member

maleadt commented Dec 16, 2019

@nanosoldier runtests(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your test job has completed - possible new issues were detected. A full report can be found here. cc @maleadt

@JeffBezanson
Copy link
Member Author

Ok, this has some legit regressions. Can wait for 1.4.1 to see if those can be avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code bugfix This change fixes an existing bug types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tuple splatting bug with simple program Subtyping is not reflexive and not transitive with triangular rule
5 participants