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

M3/heisenbug #11

Closed
wants to merge 15 commits into from
Closed
Prev Previous commit
Next Next commit
All tests passing except a few:
which are marked in test/traitdef.jl with:
varag_not_supported_bug = true
constructors_not_supported_bug = true
  • Loading branch information
mauro3 committed Apr 10, 2015
commit 907bc7894cc6eba5f2d3c0381b2a737815502837
9 changes: 9 additions & 0 deletions src/Traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ function istrait{T<:Trait}(Tr::Type{T}; verbose=false)

# check call signature of methods:
for (gf,_gf) in tr.methods # loop over all generic functions in traitdef
# if isa(gf, DataType) && gf in traitgetpara(Tr)
# error("asdf")
# end
for tm in methods(_gf) # loop over all methods defined for each function in traitdef
checks = false
for fm in methods(gf, NTuple{length(tm.sig),Any}) # only loop over methods which have
Expand Down Expand Up @@ -217,6 +220,12 @@ end
function isfitting(tm::Method, fm::Method; verbose=false) # tm=trait-method, fm=function-method
println_verb = verbose ? println : x->x

# special casing for call-overloading:
if fm.func.code.name==:call && tm.func.code.name!=:call
# make a call-like method
error("Constructors not supported yet.")
end

# No Vararg methods implement yet
if tm.va || fm.va
# runtests.jl flag: varag_not_supported_bug
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function_types_bug1 = true # set to false if function types get implemented in J
dispatch_bug1 = true # in traitdispatch.jl
traitdef_bug1 = true
varag_not_supported_bug = true
constructors_not_supported_bug = true

# src/Traits.jl tests
type A1 end
Expand Down
57 changes: 38 additions & 19 deletions test/traitdef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ for a1 in arith
end

## test trait definition
@traitdef FF{X} begin
f948576()
end
@test !istrait(FF{Int})
f948576() = 1
@test istrait(FF{Int})

@traitdef Tr20{X} begin
length(X) -> Bool
Expand Down Expand Up @@ -297,25 +303,36 @@ AssocIsBits{T3484675{Int,4.5,:a}}()
####
# DataType constructors
####

@traitdef TT45{D} begin
# This trait contains all datatypes which have a constructor with
# no arguments.
D() -> D
end
type A4758 end
type A4759
a
end

@test istrait(TT45{A4758})
@test !istrait(TT45{A4759})
@test istrait(TT45{Dict{Int,Int}})
@test istrait(TT45{Set{Int}})
@test !istrait(TT45{Int})
@test !istrait(TT45{Array{Int,1}})

if varag_not_supported_bug
if !constructors_not_supported_bug
@traitdef TT45{D} begin
# This trait contains all datatypes which have a constructor with
# no arguments.
D() -> D
end
type A4758 end
type A4759
a
end

@test istrait(TT45{A4758})
@test !istrait(TT45{A4759})
@test istrait(TT45{Dict{Int,Int}})
@test istrait(TT45{Set{Int}})
@test !istrait(TT45{Int})
@test !istrait(TT45{Array{Int,1}})

@traitdef TT44{D} begin
#
Array(D,Any)
end
@test istrait(TT44{A4758})
@test istrait(TT44{A4759})
@test istrait(TT44{Dict{Int,Int}})
@test istrait(TT44{Set{Int}})
@test istrait(TT44{Int})
@test istrait(TT44{Array{Int,1}})

if !varag_not_supported_bug
# This is the trait for datatypes with Array like constructors:
@traitdef TT46{Ar} begin
T = Type{eltype(Ar)}
Expand All @@ -339,3 +356,5 @@ if varag_not_supported_bug
# @test istrait(TT46{Array{Int}}, verbose=true) # this does not pass currently because of https://github.com/JuliaLang/julia/issues/10642
@test istrait(TT46{Array}, verbose=true)
end

end # !constructors_not_supported_bug