From 3e23ec6354878ff99dea0906197cd16514f9a4b9 Mon Sep 17 00:00:00 2001 From: Markus Kurtz Date: Sun, 17 Jul 2022 10:13:00 +0200 Subject: [PATCH] Fix `is_doc_expr` by constraining number of args Fix for #538 --- src/utils.jl | 1 + test/toplevel.jl | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index c1120759..eb7d3c91 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -226,6 +226,7 @@ function is_doc_expr(@nospecialize(ex)) docsym = Symbol("@doc") if isexpr(ex, :macrocall) ex::Expr + length(ex.args) == 4 || return false a = ex.args[1] is_global_ref(a, Core, docsym) && return true isa(a, Symbol) && a == docsym && return true diff --git a/test/toplevel.jl b/test/toplevel.jl index f0893c0f..044059d5 100644 --- a/test/toplevel.jl +++ b/test/toplevel.jl @@ -36,6 +36,16 @@ end io = IOBuffer() show(io, @doc(Main.DocStringTest)) @test occursin("Special", String(take!(io))) + # issue #538 + @test !JuliaInterpreter.is_doc_expr(:(Core.@doc "string")) + ex = quote + @doc("no docstring") + + sum + end + modexs = collect(ExprSplitter(Main, ex)) + m, ex = first(modexs) + @test !JuliaInterpreter.is_doc_expr(ex.args[2]) @test !isdefined(Main, :JIInvisible) collect(ExprSplitter(JIVisible, :(module JIInvisible f() = 1 end))) @@ -561,4 +571,4 @@ end @test JuliaInterpreter.finish!(Frame(mod, ex), true) === nothing end @test length(modexs) == 2 -end \ No newline at end of file +end