From 51b0409eefdfcd0c9ee1f7fcaaaf362cf5ec2a59 Mon Sep 17 00:00:00 2001 From: Lionel Zoubritzky Date: Fri, 15 May 2020 11:46:51 +0200 Subject: [PATCH] Fix introspection macros for getproperty --- stdlib/InteractiveUtils/src/macros.jl | 12 +++++++++--- stdlib/InteractiveUtils/test/runtests.jl | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/stdlib/InteractiveUtils/src/macros.jl b/stdlib/InteractiveUtils/src/macros.jl index 6bed2a0be0b07..475535e67aa97 100644 --- a/stdlib/InteractiveUtils/src/macros.jl +++ b/stdlib/InteractiveUtils/src/macros.jl @@ -69,9 +69,15 @@ function gen_call_with_extracted_types(__module__, fcn, ex0, kws=Expr[]) fully_qualified_symbol &= ex1 isa Symbol if fully_qualified_symbol if string(fcn) == "which" - return quote $(fcn)($(esc(ex0.args[1])), $(ex0.args[2])) end - else - return Expr(:call, :error, "expression is not a function call or symbol") + return quote + local arg1 = $(esc(ex0.args[1])) + if isa(arg1, Module) + $(fcn)(arg1, $(ex0.args[2])) + else + local args = typesof($(map(esc, ex0.args)...)) + $(fcn)(Base.getproperty, args) + end + end end elseif ex0.args[2] isa Expr return Expr(:call, :error, "dot expressions are not lowered to " diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 7bbc2b321a440..3fe32282b0da6 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -322,9 +322,15 @@ B33163(x) = x # Issue #14637 @test (@which Base.Base.Base.nothing) == Core -@test_throws ErrorException (@functionloc Base.nothing) +@test (@functionloc Base.nothing)[2] isa Integer @test (@code_typed (3//4).num)[2] == Int +struct A14637 + x +end +a14637 = A14637(0) +@test (@which a14637.x).name == :getproperty + # Issue #28615 @test_throws ErrorException (@which [1, 2] .+ [3, 4]) @test (@code_typed optimize=true max.([1,7], UInt.([4])))[2] == Vector{UInt}