-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
- Loading branch information
There are no files selected for viewing
5 comments
on commit 5b0aedd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another tricky case:
julia> type Foo
x
Base.convert(::Type{Foo}, x) = new(int(x))
end
julia> convert(Foo, 7)
Foo(7)
julia> Foo(3.2)
ERROR: `Foo` has no method matching Foo(::Float64)
julia> call(Foo, 3.2)
Foo(3)
julia> methods(Foo)
#0 methods for generic function "Foo":
The cleanest way to resolve this might be to get rid of constructors as "generic functions" per se, and just make them methods added to call
. That way there is no question whether you want to dispatch on call
or on Foo
methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I was saying yesterday --- constructors should be dispatched on types by call
the way convert
is. This is internally simpler and more general as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a weird behavior:
julia> Base.call(x::Int, y::Int) = x + 3y
call (generic function with 3 methods)
julia> let x=10
x(3) == 19
end
true
julia> let x=10
Base.Test.@test x(3) == 19
end
ERROR: test error during x(3) == 19
type: anonymous: in apply, expected Function, got Int64
in anonymous at test.jl:62
in do_test at test.jl:37
in anonymous at no file:2
@JeffBezanson, how is macro expansion of @test
triggering a different code path here?
Update: seems to be a problem with globals in functions?
julia> Base.call(x::Int, y::Int) = x + 3y
call (generic function with 3 methods)
julia> x = 3
3
julia> x(7)
24
julia> g = () -> x(3)
(anonymous function)
julia> g()
ERROR: type: anonymous: in apply, expected Function, got Int64
in anonymous at none:1
julia> function h()
x(3)
end
h (generic function with 1 method)
julia> h()
ERROR: type: h: in apply, expected Function, got Int64
in h at none:2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I've just added support for switching over to call
from jl_f_apply
and jl_f_kwcall
, but it's still not working, so I must be missing another place. I still haven't changed applicable
and invoke
, but I don't think it could be one of those because the error says in apply
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, the problem is that emit_func_check
needs to go away...
I tried to do this with 762a727, but it broke something else.
@JeffBezanson, this line gives
but the other tests work. What am I missing?
(On the phone, you mentioned something about having to change type inference somewhere, but I'm not quite sure what you were referring to. Something in
inference.jl
?)