diff --git a/Project.toml b/Project.toml index 1e25e6a..33b9049 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "QuickTypes" uuid = "ae2dfa86-617c-530c-b392-ef20fdad97bb" -version = "1.8.0" +version = "1.9.0" [deps] ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" diff --git a/src/QuickTypes.jl b/src/QuickTypes.jl index f8e2a39..426bdf3 100644 --- a/src/QuickTypes.jl +++ b/src/QuickTypes.jl @@ -409,11 +409,17 @@ Note that if no parent type is specified, `<: Function` is used. macro qfunctor(fdef0) if @capture(fdef0, A_ <: parenttype_) fdef = A + elseif @capture(fdef0, A_ <: parenttype_ = rhs_) + fdef = :($A = $rhs) else fdef = fdef0 parenttype = :($QFunctor) end di = splitdef(fdef) + if @capture(di[:body], begin <:ptype_; restofbody__ end) # function Foo(x)(k) <: P ... end + parenttype = ptype + di[:body] = Expr(:block, restofbody...) + end type_def = di[:name] if @capture(type_def, typename_(args__; kwargs__)) all_args = map(first ∘ splitarg, vcat(args, kwargs)) diff --git a/test/runtests.jl b/test/runtests.jl index d42b8b8..bdab5d7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -145,6 +145,16 @@ io = IOBuffer(); show(io, MIME"text/plain"(), ParamAction(1)) @test String(take!(io)) == "ParamAction{Int64}(1)" +@qfunctor Bus(x)(y) <: Real = 2 +@test Bus(2) isa Real + +@qfunctor function Tractor(x)(p) <: Number + x+p +end + +@test Tractor(9)(3) == 12 +@test Tractor(9) isa Number + ################################################################################ # @destruct