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

Improve promotion for constructors... #18623

Closed
wants to merge 1 commit into from

Conversation

mbauman
Copy link
Member

@mbauman mbauman commented Sep 22, 2016

by enabling Type{} specialization in the promote_op methods that request return information from Inference. Notably, this makes constructors behave in exactly the same manner as normal functions... even in cases where that behavior may be controversial:

julia> Int.(Number[1,2])
2-element Array{Number,1}:
 1
 2

julia> (x->Int(x)).(Number[1,2])
2-element Array{Number,1}:
 1
 2

by enabling `Type{}` specialization in the `promote_op` methods that request return information from Inference. Notably, this makes constructors behave in exactly the same manner as normal functions... even in cases where that behavior may be controversial:

```jl
julia> Int.(Number[1,2])
2-element Array{Number,1}:
 1
 2

julia> (x->Int(x)).(Number[1,2])
2-element Array{Number,1}:
 1
 2
```
@pabloferz
Copy link
Contributor

Would you mind if I fix this together with #18622? Fixing the last one involves changing these functions too, so it would avoid some conflicts.

@mbauman
Copy link
Member Author

mbauman commented Sep 22, 2016

Go for it.

@kshyatt kshyatt added the types and dispatch Types, subtyping and method dispatch label Sep 22, 2016
@pabloferz
Copy link
Contributor

What would you think it would be better to return here Array{Int,1} or Array{Number,1} in both cases? (map returns the first)

@@ -337,3 +337,15 @@ end
@test broadcast(+, 1.0, (0, -2.0)) == (1.0,-1.0)
@test broadcast(+, 1.0, (0, -2.0), [1]) == [2.0, 0.0]
@test broadcast(*, ["Hello"], ", ", ["World"], "!") == ["Hello, World!"]

# Ensure that even strange constructors that break `T(x)::T` work with broadcast
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually care about such constructors? Is is supported to return an object not of type T? (I've been wondering about this for one of my packages.

@stevengj
Copy link
Member

stevengj commented Nov 7, 2016

Closed by #18642

@stevengj stevengj closed this Nov 7, 2016
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

Successfully merging this pull request may close these issues.

5 participants