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

"No method" error with parametric type Union(Nothing, T) #7445

Closed
nalimilan opened this issue Jun 28, 2014 · 2 comments
Closed

"No method" error with parametric type Union(Nothing, T) #7445

nalimilan opened this issue Jun 28, 2014 · 2 comments

Comments

@nalimilan
Copy link
Member

This is similar to #3738 but it also affects positional arguments.

julia> test{T<:Number}(x::Union(Nothing, T)) = true
test (generic function with 1 method)

julia> test(1)
true

julia> test(nothing)
ERROR: no method test(Nothing)
@JeffBezanson
Copy link
Member

This behavior is correct. A parametric method cannot be called unless values for the parameters can be determined. For example

julia> f{T}(x) = 0
Warning: static parameter T does not occur in signature for f at none:1.
The method will not be callable.

However we can't give the warning in this case since it is possible to call the method.

@nalimilan
Copy link
Member Author

But it means unions with Nothing and any parametric type cannot be used, and in particular that Union(Nothing, AbstractArray{T}) with T<:Real does not work. This is annoying since there's no way of passing an equivalent of NULL for an argument. See my use case (but for keyword arguments) at https://groups.google.com/d/msg/julia-users/FAKPYxxiQgQ/VFW9l6-tqF8J

Wouldn't it be possible to call the method even if T is not specified, since nothing matches a type in the union?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants