File tree 1 file changed +24
-6
lines changed
1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -5,19 +5,37 @@ using Base.Test
5
5
# Tests for @__LINE__ inside and outside of macros
6
6
@test @__LINE__ () == 6
7
7
8
- macro macro_body_lineno ()
8
+ macro macro_caller_lineno ()
9
9
line = current_location ():: Int
10
+ :($ line)
11
+ end
12
+
13
+ @test @macro_caller_lineno () == @__LINE__
14
+
15
+ # @__LINE__ in a macro expands to the location of the macro caller
16
+ macro emit_LINE ()
17
+ quote
18
+ @__LINE__
19
+ end
20
+ end
21
+ @test @emit_LINE () == @__LINE__
22
+
23
+ # @__LINE__ expands to location of calling macro in a two-level macro expansion,
24
+ # not the top level.
25
+ macro nested_LINE_expansion ()
10
26
quote
11
- $ line
27
+ @emit_LINE ()
12
28
end
13
29
end
30
+ @test @nested_LINE_expansion () == @__LINE__ ()- 3
14
31
15
- macro macro_ast_lineno ()
16
- :(@__LINE__ )
32
+ # @__LINE__ ignores any macro in a multi-level expansion if there's no line
33
+ # nodes in the AST.
34
+ macro nested_LINE_expansion2 ()
35
+ :(@emit_LINE ())
17
36
end
37
+ @test @nested_LINE_expansion2 () == @__LINE__ ()
18
38
19
- @test @macro_body_lineno () == @__LINE__
20
- @test @macro_ast_lineno () == @__LINE__
21
39
22
40
23
41
include (" test_sourcepath.jl" )
You can’t perform that action at this time.
0 commit comments