-
Notifications
You must be signed in to change notification settings - Fork 152
Activate helpful error message for undefined-Size conversions #448
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
Conversation
Adding `S<:Tuple` ensured a method would be higher in the methodtable.
Femtocleaner has a number of useful suggestions. OK to accept? Or would you rather keep this tiny? |
Codecov Report
@@ Coverage Diff @@
## master #448 +/- ##
=========================================
+ Coverage 88.29% 88.3% +<.01%
=========================================
Files 36 36
Lines 2982 2983 +1
=========================================
+ Hits 2633 2634 +1
Misses 349 349
Continue to review full report at Codecov.
|
Cool, thanks Tim! Yes I generally love femtocleaner- bring it on :) |
Size(a::T) where {T<:AbstractArray} = Size(T) | ||
Size(::Type{<:StaticArray{S}}) where {S} = Size(S) | ||
end | ||
Size(::Type{SA}) where {SA <: StaticArray{S}} where {S<:Tuple} = Size(S) # S defined as a Tuple |
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.
This gives UndefVarError: S not defined
:
julia> convert(SVector, [1,2,3])
ERROR: UndefVarError: S not defined
Stacktrace:
[1] Size(::Type{SArray{Tuple{S},T,1,S} where T where S}) at /Users/Fredrik/.julia/packages/StaticArrays/Jd49/src/traits.jl:86
[2] length(::Type{SArray{Tuple{S},T,1,S} where T where S}) at /Users/Fredrik/.julia/packages/StaticArrays/Jd49/src/abstractarray.jl:2
[3] convert(::Type{SArray{Tuple{S},T,1,S} where T where S}, ::Array{Int64,1}) at /Users/Fredrik/.julia/packages/StaticArrays/Jd49/src/convert.jl:22
[4] top-level scope at none:0
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.
Interesting. We tested this with 0.6, where it works as intended.
I wonder if this is actually a dispatch bug in 0.7. That line explicitly requires that S<:Tuple
, and when S
is undefined I don't see how that statement could be true.
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.
Hmmm, it should work...
julia> abstract type AType{T} end
julia> foo(::Type{A}) where A<:AType = "parameter missing"
foo (generic function with 1 method)
julia> foo(::Type{A}) where A<:AType{T} where T<:Tuple = "parameter present"
foo (generic function with 2 methods)
julia> struct C{T} <: AType{T} end
julia> foo(C)
"parameter missing"
julia> foo(C{Tuple{1,2}})
"parameter present"
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.
I don't what the exact problem is here, but note that, continuing with your definitions:
julia> foo(C{Union{T,Tuple}} where T <: Tuple)
"parameter present"
julia> foo(::Type{A}) where A<:AType{T} where T<:Tuple = "parameter present: $T"
foo (generic function with 2 methods)
julia> foo(C{Union{T,Tuple}} where T <: Tuple)
ERROR: UndefVarError: T not defined
So it's always safer to add an @isdefined T
conditional.
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.
Opened #452 to track this.
Adding
S<:Tuple
ensured a method would be higher in the methodtable.