Created
May 7, 2012 22:10
-
-
Save carlobaldassi/2630858 to your computer and use it in GitHub Desktop.
Union type dispatch bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias MatOrNothing{T} Union(AbstractMatrix{T}, Vector{None}, Nothing) | |
my_func{T}(A::MatOrNothing{T}) = println("my_func ok") | |
M = [1. 2. ; 3. 4.] | |
my_func(M) # works | |
my_func([]) # works | |
my_func(nothing) # fails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias VecOrNothing{T} Union(AbstractVector{T}, Vector{None}) | |
typealias MatOrNothing{T} Union(AbstractMatrix{T}, Vector{None}) | |
my_func{T<:Real}(A::MatOrNothing{T}, B::MatOrNothing{T}, | |
C::MatOrNothing{T}) = println("my_func ok") | |
M = [ 2. 1. ; 1. 1. ] | |
my_func(M, M, M) | |
#my_func([], M, M) # fails | |
my_func(M, [], M) | |
my_func(M, M, []) | |
my_func(M, [], []) | |
#my_func([], M, []) # fails | |
#my_func([], [], M) # fails | |
my_func([], [], []) | |
# like my_func but C is VecOrNothing : fails more often | |
my_func2{T<:Real}(A::MatOrNothing{T}, B::MatOrNothing{T}, | |
C::VecOrNothing{T}) = println("my_func2 ok") | |
V = [ 0.; 0.] | |
my_func2(M, M, V) | |
#my_func2([], M, V) # fails | |
my_func2(M, [], V) | |
#my_func2(M, M, []) # fails | |
#my_func2(M, [], []) # fails | |
#my_func2([], M, []) # fails | |
#my_func2([], [], V) # fails | |
my_func2([], [], []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment