Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix macros @which, @edit, @functionloc, @less for literal_pow case. #53713

Merged
merged 15 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stdlib/InteractiveUtils/src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ function gen_call_with_extracted_types(__module__, fcn, ex0, kws=Expr[])
$(kws...))
end
elseif ex0.head === :call
if ex0.args[1] === :^ && length(ex0.args) >= 3 && isa(ex0.args[3], Int)
return Expr(:call, fcn, :(Base.literal_pow),
Expr(:call, typesof, esc(ex0.args[1]), esc(ex0.args[2]),
esc(Val(ex0.args[3]))))
end
return Expr(:call, fcn, esc(ex0.args[1]),
Expr(:call, typesof, map(esc, ex0.args[2:end])...),
kws...)
Expand Down
37 changes: 36 additions & 1 deletion stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,49 @@ let x..y = 0
@test (@which 1..2).name === :..
end

# issue #53691
let a = -1
@test (@which 2^a).name === :^
@test (@which 2^0x1).name === :^
end

let w = Vector{Any}(undef, 9)
@testset "@which x^literal" begin
w[1] = @which 2^0
w[2] = @which 2^1
w[3] = @which 2^2
w[4] = @which 2^3
w[5] = @which 2^-1
w[6] = @which 2^-2
w[7] = @which 2^10
w[8] = @which big(2.0)^1
w[9] = @which big(2.0)^-1
@test all(getproperty.(w, :name) .=== :literal_pow)
@test length(Set(w)) == length(w) # all methods distinct
end
end

if Int === Int64
# literal_pow only for exponents x: -2^63 <= x < 2^63 #53860 (all Int)
@test (@which 2^-9223372036854775809).name === :^
@test (@which 2^-9223372036854775808).name === :literal_pow
@test (@which 2^9223372036854775807).name === :literal_pow
@test (@which 2^9223372036854775808).name === :^
else
# literal_pow only for exponents x: -2^31 <= x < 2^31 #53860 (all Int)
@test (@which 2^-2147483649).name === :^
@test (@which 2^-2147483648).name === :literal_pow
@test (@which 2^-2147483647).name === :literal_pow
@test (@which 2^-2147483648).name === :^
KlausC marked this conversation as resolved.
Show resolved Hide resolved
end

# issue #13464
try
@which x = 1
error("unexpected")
catch err13464
@test startswith(err13464.msg, "expression is not a function call")
end

module MacroTest
export @macrotest
macro macrotest(x::Int, y::Symbol) end
Expand Down