Skip to content

Commit 7e81a46

Browse files
committed
more coverage for algclosure
1 parent e4d5c4d commit 7e81a46

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/syntax/GATs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export Constant, AlgTerm, AlgType, AlgAST,
99
termcons,typecons, accessors, structs, primitive_sorts, struct_sorts,
1010
equations, build_infer_expr, compile, sortcheck, allnames, sorts, sortname,
1111
InCtx, TermInCtx, TypeInCtx, headof, argsof, methodof, bodyof, argcontext,
12-
infer_type
12+
infer_type,
13+
tcompose
1314

1415
using ..Scopes
1516
import ..ExprInterop: fromexpr, toexpr

src/syntax/gats/closures.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ function tcompose(fs::Dtry{AlgClosure}, argnames::Vector{Symbol})
115115
end
116116

117117
function (f::AlgClosure)(argvals::Any...)
118-
if length(f.methods) > 1 && any(!(x isa AlgTerm) for x in argvals)
119-
error("cannot infer type of non-AlgTerm value $x")
118+
for x in argvals
119+
if !(x isa AlgTerm)
120+
error("cannot infer type of non-AlgTerm value $x")
121+
end
120122
end
121123
sorts = AlgSort[sortcheck.(Ref(f.theory), argvals)...]
122124
if !haskey(f.methods, sorts)

test/syntax/GATs.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ end
157157
id_span(x) := Span(x, id(x),id(x)) [x::Ob]
158158
end
159159

160+
@test Base.isempty(GAT(:_EMPTY))
161+
160162
# Dtrys
161163

162164
tuplescope = fromexpr(ThMonoid.Meta.theory, :([x::(a::(s,t),b)]), TypeScope)
@@ -165,6 +167,14 @@ tuplescope = fromexpr(ThMonoid.Meta.theory, :([x::(a::(s,t),b)]), TypeScope)
165167
x * y + x * x
166168
end
167169

168-
@test Base.isempty(GAT(:_EMPTY))
170+
@test only(f.methods)[2](1, 2) isa AlgTerm
171+
@test_throws ErrorException f(1, 2)
172+
@test_throws ErrorException f()
173+
174+
@test sprint(show, f) isa String
175+
176+
@test tcompose(
177+
Dtrys.node(:a => Dtrys.leaf(f), :b => Dtrys.leaf(f)), [:x, :y]
178+
) isa AlgClosure
169179

170180
end # module

0 commit comments

Comments
 (0)