Skip to content

Commit 3331fd2

Browse files
Merge pull request #35 from nsajko/mandatory_arguments
make all `maketerm` arguments mandatory
2 parents 801430a + 1f87c6c commit 3331fd2

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/TermInterface.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function metadata end
109109

110110

111111
"""
112-
maketerm(T, head, children, type=nothing, metadata=nothing)
112+
maketerm(T, head, children, type, metadata)
113113
114114
Constructs an expression. `T` is a constructor type, `head` and `children` are
115115
the head and tail of the S-expression, `type` is the `type` of the S-expression.
@@ -125,8 +125,7 @@ the sub-expression. `T` will be the type of the outer expression.
125125
126126
Packages providing expression types _must_ implement this method for each expression type.
127127
128-
If your types do not support type information or metadata, you still need to accept
129-
these arguments and may choose to not use them.
128+
Giving `nothing` for `type` or `metadata` results in a default being selected.
130129
"""
131130

132131
function maketerm end

src/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ children(e::Expr) = e.args
1010
operation(e::Expr) = iscall(e) ? first(children(e)) : error("operation called on a non-function call expression")
1111
arguments(e::Expr) = iscall(e) ? @view(e.args[2:end]) : error("arguments called on a non-function call expression")
1212

13-
function maketerm(::Type{Expr}, head, args, type=nothing, metadata=nothing)
13+
function maketerm(::Type{Expr}, head, args, type, metadata)
1414
Expr(head, args...)
1515
end

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using Test
99
@test arguments(ex) == [:a, :b]
1010
@test isexpr(ex)
1111
@test iscall(ex)
12-
@test ex == maketerm(Expr, :call, [:f, :a, :b])
12+
@test ex == maketerm(Expr, :call, [:f, :a, :b], nothing, nothing)
1313

1414

1515
ex = :(arr[i, j])
@@ -18,5 +18,5 @@ using Test
1818
@test_throws ErrorException arguments(ex)
1919
@test isexpr(ex)
2020
@test !iscall(ex)
21-
@test ex == maketerm(Expr, :ref, [:arr, :i, :j])
21+
@test ex == maketerm(Expr, :ref, [:arr, :i, :j], nothing, nothing)
2222
end

0 commit comments

Comments
 (0)