From 4f720b6e10f216902d1c8921fcd3abe01774dc7a Mon Sep 17 00:00:00 2001 From: Mauro Werder Date: Fri, 10 Apr 2015 17:17:21 +0200 Subject: [PATCH] Mostly running now. These two bugs do not matter anymore as the new tests do not rely on method_exists: method_exists_bug1 = false # see https://github.com/JuliaLang/julia/issues/8959 method_exists_bug2 = false # see https://github.com/JuliaLang/julia/issues/9043 and https://github.com/mauro3/Traits.jl/issues/2 --- src/Traits.jl | 10 ++++++---- src/base_fixes.jl | 5 +++++ src/commontraits.jl | 22 +++++++++++----------- src/traitdef.jl | 7 +++++-- test/runtests.jl | 2 +- test/traitdef.jl | 8 ++++---- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/Traits.jl b/src/Traits.jl index 7f8054d..6cf7de1 100644 --- a/src/Traits.jl +++ b/src/Traits.jl @@ -159,8 +159,10 @@ function istrait{T<:Trait}(Tr::Type{T}; verbose=false) end end - # check return-type - if flag_check_return_types + # check return-type. Specifed return type tret and return-type of + # the methods frets should fret<:tret. This is backwards to + # argument types... + if flag_check_return_types for (gf,_gf) in tr.methods for tm in methods(_gf) # loop over all methods defined for each function in traitdef @show tret_typ = Base.return_types(_gf, tm.sig) # trait-defined return type @@ -177,9 +179,9 @@ function istrait{T<:Trait}(Tr::Type{T}; verbose=false) end end if !checks - println_verb("""No return types found which are subtypes of the specified return type: + println_verb("""For function $gf: no return types found which are subtypes of the specified return type: $tret_typ - found: + List of found return types: $fret_typ """) return false diff --git a/src/base_fixes.jl b/src/base_fixes.jl index ed09bc5..6979665 100644 --- a/src/base_fixes.jl +++ b/src/base_fixes.jl @@ -11,3 +11,8 @@ function Base.func_for_method(m::Method, tt, env) end end println(" endof ok-warning.") + + +# eltype for dicts +Base.eltype{K}(::Type{Associative{K}}) = (K,Any) +Base.eltype(::Type{Associative}) = (Any,Any) diff --git a/src/commontraits.jl b/src/commontraits.jl index b99fe01..133f02e 100644 --- a/src/commontraits.jl +++ b/src/commontraits.jl @@ -58,17 +58,17 @@ end K,V = eltype(X) # note, ObjectId dict is not part of this interface - haskey(X, All) - get(X, All, All) - get(Function, X, All) - get!(X, All, All) - get!(Function, X, All) - getkey(X, All, All) - delete!(X, All) -> X - pop!(X, All) - pop!(X, All, All) - merge(X, All...) -> X - merge!(X, All...) + haskey(X, Any) + get(X, Any, Any) + get(Function, X, Any) + get!(X, Any, Any) + get!(Function, X, Any) + getkey(X, Any, Any) + delete!(X, Any) -> X + pop!(X, Any) + pop!(X, Any, Any) + # merge(X, Any...) -> X + # merge!(X, Any...) # provieds # keys(X) -> Base.KeyIterator # values(X) -> Base.ValueIterator diff --git a/src/traitdef.jl b/src/traitdef.jl index b04655d..c5a212b 100644 --- a/src/traitdef.jl +++ b/src/traitdef.jl @@ -138,13 +138,16 @@ function parsefnstypes!(outfns, ln) # parses f(X,Y), f{X <:T}(X,Y) and X+Y # into f and _f(...) + # getsymbol = gensym + getsymbol(fn) = symbol("__"*string(fn)) + _fn = deepcopy(def) if isa(def.args[1], Symbol) # f(X,Y) or X+Y fn = def.args[1] - _fn.args[1] = gensym(fn) + _fn.args[1] = getsymbol(fn) elseif def.args[1].head==:curly # f{X}(X,Y) fn = def.args[1].args[1] - _fn.args[1].args[1] = gensym(fn) + _fn.args[1].args[1] = getsymbol(fn) else throw(TraitException( "Something went wrong parsing the trait function definition:\n$fn")) diff --git a/test/runtests.jl b/test/runtests.jl index 8bdc127..b8362ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,7 @@ using Base.Test using Traits ## BUG flags: set to false once fixed to activate tests # Julia issues: -method_exists_bug1 = true # see https://github.com/JuliaLang/julia/issues/8959 +method_exists_bug1 = false # see https://github.com/JuliaLang/julia/issues/8959 method_exists_bug2 = false # see https://github.com/JuliaLang/julia/issues/9043 and https://github.com/mauro3/Traits.jl/issues/2 function_types_bug1 = true # set to false if function types get implemented in Julia # Traits.jl issues: diff --git a/test/traitdef.jl b/test/traitdef.jl index 4ed459f..74ffd97 100644 --- a/test/traitdef.jl +++ b/test/traitdef.jl @@ -79,12 +79,12 @@ end coll = [Vector{Int}, Dict{Int,Int}, Set{Int}] iter = [Traits.GenerateTypeVars{:upcase}, Int] #todo: add String, if method_exists_bug1 - assoc = [] #todo add again: Dict{Int,Int}] # , ObjectIdDict] + dicts = [] #todo add again: Dict{Int,Int}] # , ObjectIdDict] else - assoc = [Array{Int,2}, Dict{Int,Int}, StepRange{Int,Int}] + dicts = [Dict{Int}, Dict{Int,Int}] # Dict does not work, ObjectIdDict does not fulfill the trait end index = [Array{Int,2}, StepRange{Int,Int}] - +c =1 for c in coll @test istrait(Collection{c}, verbose=true) @test istrait(Iter{c}, verbose=true) @@ -98,7 +98,7 @@ for c in iter @test istrait(Iter{c}, verbose=true) end -for c in assoc +for c in dicts @test istrait(Assoc{c}, verbose=true) end