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

Behavior of function depends on whether method call is defined before first use of function #3857

Closed
astrieanna opened this issue Jul 28, 2013 · 1 comment

Comments

@astrieanna
Copy link
Contributor

I defined a function that uses a yet-to-be-defined method.
If I don't call the function until after I've defined the function it calls, everything is fine.
If I call it before I define the method, then it (as I expected) throws an error.
If I then define the missing method and run the first function again, there is no error but it also doesn't return the value that it should. I expected it to either work correctly or at least keep throwing an error.

julia> function foo(x,y)
         x + y
       end
# methods for generic function foo
foo(x,y) at none:2

julia> foo(true,"hi")
ERROR: no method +(Bool,ASCIIString)
 in foo at none:2

julia> +(b::Bool,s::String) = "$b$s"
# methods for generic function +
+(x::Bool,y::Bool) at bool.jl:38
+(x::Int64,y::Int64) at int.jl:36
+(x::Union(SubArray{Bool,N,A<:Array{T,N},I<:(Union(Int64,Range1{Int64},Range{Int64})...,)},Array{Bool,N}),y::Union(SubArray{Bool,N,A<:Array{T,N},I<:(Union(Int64,Range1{Int64},Range{Int64})...,)},Array{Bool,N})) at array.jl:1003
+{S,T}(A::Union(SubArray{S,N,A<:Array{T,N},I<:(Union(Int64,Range1{Int64},Range{Int64})...,)},Array{S,N}),B::Union(SubArray{T,N,A<:Array{T,N},I<:(Union(Int64,Range1{Int64},Range{Int64})...,)},Array{T,N})) at array.jl:947
+{T<:Union(Int8,Int64,Int16,Int32)}(x::T<:Union(Int8,Int64,Int16,Int32),y::T<:Union(Int8,Int64,Int16,Int32)) at int.jl:11
... 87 methods not shown (use methods(+) to see them all)

julia> foo(true,"hi")

julia> foo(true,"hi")

julia> function foo(x,y)
         x + y
       end
# methods for generic function foo
foo(x,y) at none:2

julia> foo(true,"hi")
"truehi"
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 28, 2013

dup of #265

@vtjnash vtjnash closed this as completed Jul 28, 2013
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