Skip to content

Commit 10a618d

Browse files
authored
add error message when using the macros on invalid expressions (#155)
1 parent 66da128 commit 10a618d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Debugger.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,25 @@ function _make_frame(mod, arg)
9494
end
9595
end
9696

97+
_check_is_call(arg) = !(arg isa Expr && arg.head == :call) && throw(ArgumentError("@enter and @run should be applied to a function call"))
98+
9799
macro make_frame(arg)
98100
_make_frame(__module__, arg)
99101
end
100102

101103
macro enter(arg)
104+
_check_is_call(arg)
102105
quote
103-
let frame = $(_make_frame(__module__,arg))
106+
let frame = $(_make_frame(__module__, arg))
104107
RunDebugger(frame)
105108
end
106109
end
107110
end
108111

109112
macro run(arg)
113+
_check_is_call(arg)
110114
quote
111-
let frame = $(_make_frame(__module__,arg))
115+
let frame = $(_make_frame(__module__, arg))
112116
RunDebugger(frame; initial_continue=true)
113117
end
114118
end

test/misc.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,8 @@ import InteractiveUtils
8686
@test JuliaInterpreter.Variable(@__FILE__, :file, false) in locals
8787
@test JuliaInterpreter.Variable(LINE, :line, false) in locals
8888
end
89+
90+
# These are LoadError because the error happens at macro expansion
91+
@test_throws LoadError @macroexpand @enter "foo"
92+
@test_throws LoadError @macroexpand @enter 1
93+
@test_throws LoadError @macroexpand @run [1,2]

0 commit comments

Comments
 (0)