macros checking is not working
rssdev10 opened this issue · 0 comments
rssdev10 commented
I found that current implementation of macros checking is not working.
doc.jl-test generates an error:
s = """
@doc "this is a test"
f() = 0
"""
msgs = lintstr(s)
@test msgs[1].code == :W443
#AST Linting: Error During Test at /Users/rss/.julia/dev/Lint/test/doc.jl:16
# Test threw exception
# Expression: (msgs[1]).code == :W443
# BoundsError: attempt to access 0-element Array{LintMessage,1} at index [1]
I added debug output into appropriate part of macros.jl:
if istopmacro(ex.args[1], Core, Symbol("@doc")) && length(ex.args) >= 2 # see Docile.jl
@show ex.args
if isexpr(ex.args[2], :(->))
@show ex.args[2].args[2]
lintexpr(ex.args[2].args[2], ctx) # no need to lint the doc string
return
elseif typeof(ex.args[2]) <: AbstractString && length(ex.args) >= 3 && isexpr(ex.args[3], :call)
# grandfather as a docstring of a previously declared function
@show ex.args[2]
return
elseif (typeof(ex.args[2]) <: AbstractString ||
isexpr(ex.args[2], :macrocall) && ex.args[2].args[1] == Symbol("@mstr")
)
@show ex.args[2]
if length(ex.args) >= 3
lintexpr(ex.args[3], ctx)
else
msg(ctx, :W443, "did you forget an -> after @doc or make it inline?")
end
return
end
return
end
Results which I see for @doc
macros are:
ex.args = Any[Symbol("@doc"), :(#= none:1 =#), :("this is a test"->begin
#= none:1 =#
f() = begin
#= none:1 =#
0
end
end)]
ex.args = Any[Symbol("@doc"), :(#= none:1 =#), :("this is a test"->begin
#= none:1 =#
f() = begin
#= none:1 =#
0
end
end)]
ex.args = Any[Symbol("@doc"), :(#= none:1 =#), "this is a test", :(f() = begin
#= none:2 =#
0
end)]
See that ex.args[2]
is always equal to :(#= none:1 =#)
. So nothing from the checks upper is working. Also I see very similar approach in other macros analysis.
So, what is it, is it specific of Julia 1.0 with adding of :(#= none:1 =#)
expressions or forgotten removing of it from an array for analysis?