Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Commit

Permalink
Mostly running now.
Browse files Browse the repository at this point in the history
These two bugs do not matter anymore as the new tests do not rely on method_exists:
method_exists_bug1 = false # see JuliaLang/julia#8959
method_exists_bug2 = false # see JuliaLang/julia#9043 and #2
  • Loading branch information
mauro3 committed Apr 10, 2015
1 parent 907bc78 commit 4f720b6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/Traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/base_fixes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 11 additions & 11 deletions src/commontraits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/traitdef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions test/traitdef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 4f720b6

Please sign in to comment.