diff --git a/stdlib/REPL/src/docview.jl b/stdlib/REPL/src/docview.jl index ebb2dcbd70d0d..c569bf91876c1 100644 --- a/stdlib/REPL/src/docview.jl +++ b/stdlib/REPL/src/docview.jl @@ -294,8 +294,56 @@ repl(io::IO, other) = esc(:(@doc $other)) repl(x) = repl(stdout, x) function _repl(x) - if (isexpr(x, :call) && !any(isexpr(x, :(::)) for x in x.args)) - x.args[2:end] = [:(::typeof($arg)) for arg in x.args[2:end]] + if isexpr(x, :call) + # determine the types of the values + kwargs = nothing + pargs = Any[] + for arg in x.args[2:end] + if isexpr(arg, :parameters) + kwargs = map(arg.args) do kwarg + if kwarg isa Symbol + kwarg = :($kwarg::Any) + elseif isexpr(kwarg, :kw) + lhs = kwarg.args[1] + rhs = kwarg.args[2] + if lhs isa Symbol + if rhs isa Symbol + kwarg.args[1] = :($lhs::(@isdefined($rhs) ? typeof($rhs) : Any)) + else + kwarg.args[1] = :($lhs::typeof($rhs)) + end + end + end + kwarg + end + elseif isexpr(arg, :kw) + if kwargs == nothing + kwargs = Any[] + end + lhs = arg.args[1] + rhs = arg.args[2] + if lhs isa Symbol + if rhs isa Symbol + arg.args[1] = :($lhs::(@isdefined($rhs) ? typeof($rhs) : Any)) + else + arg.args[1] = :($lhs::typeof($rhs)) + end + end + push!(kwargs, arg) + else + if arg isa Symbol + arg = :($arg::(@isdefined($arg) ? typeof($arg) : Any)) + elseif !isexpr(arg, :(::)) + arg = :(::typeof($arg)) + end + push!(pargs, arg) + end + end + if kwargs == nothing + x.args = Any[x.args[1], pargs...] + else + x.args = Any[x.args[1], Expr(:parameters, kwargs...), pargs...] + end end #docs = lookup_doc(x) # TODO docs = esc(:(@doc $x)) diff --git a/test/docs.jl b/test/docs.jl index c6cbb3847ae28..8210856fd7b48 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -992,6 +992,20 @@ let dt2 = _repl(:(dynamic_test(::String))) @test dt2.args[1].args[1] == Symbol("@doc") @test dt2.args[1].args[3] == :(dynamic_test(::String)) end +let dt3 = _repl(:(dynamic_test(a))) + @test dt3 isa Expr + @test dt3.args[1] isa Expr + @test dt3.args[1].head === :macrocall + @test dt3.args[1].args[1] == Symbol("@doc") + @test dt3.args[1].args[3].args[2].head == :(::) # can't test equality due to line numbers +end +let dt4 = _repl(:(dynamic_test(1.0,u=2.0))) + @test dt4 isa Expr + @test dt4.args[1] isa Expr + @test dt4.args[1].head === :macrocall + @test dt4.args[1].args[1] == Symbol("@doc") + @test dt4.args[1].args[3] == :(dynamic_test(::typeof(1.0); u::typeof(2.0)=2.0)) +end # Equality testing