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

Commit d762137

Browse files
committed
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 JuliaLang/julia#8959 method_exists_bug2 = false # see JuliaLang/julia#9043 and #2
1 parent 54d899e commit d762137

File tree

6 files changed

+32
-22
lines changed

6 files changed

+32
-22
lines changed

src/Traits.jl

+6-4
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ function istrait{T<:Trait}(Tr::Type{T}; verbose=false)
159159
end
160160
end
161161

162-
# check return-type
163-
if flag_check_return_types
162+
# check return-type. Specifed return type tret and return-type of
163+
# the methods frets should fret<:tret. This is backwards to
164+
# argument types...
165+
if flag_check_return_types
164166
for (gf,_gf) in tr.methods
165167
for tm in methods(_gf) # loop over all methods defined for each function in traitdef
166168
@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)
177179
end
178180
end
179181
if !checks
180-
println_verb("""No return types found which are subtypes of the specified return type:
182+
println_verb("""For function $gf: no return types found which are subtypes of the specified return type:
181183
$tret_typ
182-
found:
184+
List of found return types:
183185
$fret_typ
184186
""")
185187
return false

src/base_fixes.jl

+5
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ function Base.func_for_method(m::Method, tt, env)
1111
end
1212
end
1313
println(" endof ok-warning.")
14+
15+
16+
# eltype for dicts
17+
Base.eltype{K}(::Type{Associative{K}}) = (K,Any)
18+
Base.eltype(::Type{Associative}) = (Any,Any)

src/commontraits.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ end
5858
K,V = eltype(X)
5959

6060
# note, ObjectId dict is not part of this interface
61-
haskey(X, All)
62-
get(X, All, All)
63-
get(Function, X, All)
64-
get!(X, All, All)
65-
get!(Function, X, All)
66-
getkey(X, All, All)
67-
delete!(X, All) -> X
68-
pop!(X, All)
69-
pop!(X, All, All)
70-
merge(X, All...) -> X
71-
merge!(X, All...)
61+
haskey(X, Any)
62+
get(X, Any, Any)
63+
get(Function, X, Any)
64+
get!(X, Any, Any)
65+
get!(Function, X, Any)
66+
getkey(X, Any, Any)
67+
delete!(X, Any) -> X
68+
pop!(X, Any)
69+
pop!(X, Any, Any)
70+
# merge(X, Any...) -> X
71+
# merge!(X, Any...)
7272
# provieds
7373
# keys(X) -> Base.KeyIterator
7474
# values(X) -> Base.ValueIterator

src/traitdef.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,16 @@ function parsefnstypes!(outfns, ln)
138138
# parses f(X,Y), f{X <:T}(X,Y) and X+Y
139139
# into f and _f(...)
140140

141+
# getsymbol = gensym
142+
getsymbol(fn) = symbol("__"*string(fn))
143+
141144
_fn = deepcopy(def)
142145
if isa(def.args[1], Symbol) # f(X,Y) or X+Y
143146
fn = def.args[1]
144-
_fn.args[1] = gensym(fn)
147+
_fn.args[1] = getsymbol(fn)
145148
elseif def.args[1].head==:curly # f{X}(X,Y)
146149
fn = def.args[1].args[1]
147-
_fn.args[1].args[1] = gensym(fn)
150+
_fn.args[1].args[1] = getsymbol(fn)
148151
else
149152
throw(TraitException(
150153
"Something went wrong parsing the trait function definition:\n$fn"))

test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Base.Test
33
using Traits
44
## BUG flags: set to false once fixed to activate tests
55
# Julia issues:
6-
method_exists_bug1 = true # see https://github.com/JuliaLang/julia/issues/8959
6+
method_exists_bug1 = false # see https://github.com/JuliaLang/julia/issues/8959
77
method_exists_bug2 = false # see https://github.com/JuliaLang/julia/issues/9043 and https://github.com/mauro3/Traits.jl/issues/2
88
function_types_bug1 = true # set to false if function types get implemented in Julia
99
# Traits.jl issues:

test/traitdef.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ end
7979
coll = [Vector{Int}, Dict{Int,Int}, Set{Int}]
8080
iter = [Traits.GenerateTypeVars{:upcase}, Int] #todo: add String,
8181
if method_exists_bug1
82-
assoc = [] #todo add again: Dict{Int,Int}] # , ObjectIdDict]
82+
dicts = [] #todo add again: Dict{Int,Int}] # , ObjectIdDict]
8383
else
84-
assoc = [Array{Int,2}, Dict{Int,Int}, StepRange{Int,Int}]
84+
dicts = [Dict{Int}, Dict{Int,Int}] # Dict does not work, ObjectIdDict does not fulfill the trait
8585
end
8686
index = [Array{Int,2}, StepRange{Int,Int}]
87-
87+
c =1
8888
for c in coll
8989
@test istrait(Collection{c}, verbose=true)
9090
@test istrait(Iter{c}, verbose=true)
@@ -98,7 +98,7 @@ for c in iter
9898
@test istrait(Iter{c}, verbose=true)
9999
end
100100

101-
for c in assoc
101+
for c in dicts
102102
@test istrait(Assoc{c}, verbose=true)
103103
end
104104

0 commit comments

Comments
 (0)