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

Inference substitutes Any for MethodError #14336

Closed
timholy opened this issue Dec 9, 2015 · 5 comments
Closed

Inference substitutes Any for MethodError #14336

timholy opened this issue Dec 9, 2015 · 5 comments
Labels
compiler:inference Type inference

Comments

@timholy
Copy link
Member

timholy commented Dec 9, 2015

As reported in #14335:

julia> function foo(A::VecOrMat)
           if size(A,1) == 2 && size(A,2) == 2
               return bar(A)
           end
           sum(A)
       end
foo (generic function with 1 method)

julia> bar(A::Matrix) = sum(A)
bar (generic function with 1 method)

julia> using Base.Test

julia> @inferred(foo([1,2]))
ERROR: return type Int64 does not match inferred return type Any
 in error at ./error.jl:21

It seems that it could be Union{}, as with other errors, and not destroy inference for the rest of the function.

@andreasnoack
Copy link
Member

I think I was wondering about the exact same issue here https://groups.google.com/forum/#!topic/julia-dev/OWImSfq-cuM

@JeffBezanson
Copy link
Member

Yes, Union{} is more precise but we've found returning this to be unsafe, probably because of #265. Returning Any avoids problems when the needed methods are added later.

@timholy
Copy link
Member Author

timholy commented Dec 9, 2015

OK, so should I close this and/(EDIT: add "or") merge #14335? I think it's best to leave open as a reminder for when we fix #265.

@kshyatt kshyatt added the compiler:inference Type inference label Jan 25, 2017
@kshyatt
Copy link
Contributor

kshyatt commented Jan 25, 2017

This is still happening on master.

@vtjnash
Copy link
Member

vtjnash commented Jun 9, 2017

fixed by #21892

@vtjnash vtjnash closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

5 participants