From 1b4933ccc7b1f97427ff88bd7ba58950021f2c60 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Tue, 19 Nov 2024 22:16:40 -0500 Subject: [PATCH] Make `allowscalar` a macro with auto-world-age-increment (#583) Goes along with https://github.com/JuliaLang/julia/pull/56509 --- src/abstractsparse.jl | 7 +++++++ test/allowscalar.jl | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/abstractsparse.jl b/src/abstractsparse.jl index 37f79e25..d23eebca 100644 --- a/src/abstractsparse.jl +++ b/src/abstractsparse.jl @@ -184,6 +184,13 @@ else end end +macro allowscalar(p) + quote + $(allowscalar)($(esc(p))) + @Core.latestworld + end +end + @inline _is_fixed(::AbstractArray) = false @inline _is_fixed(A::AbstractArray, Bs::Vararg{Any,N}) where N = _is_fixed(A) || (N > 0 && _is_fixed(Bs...)) macro if_move_fixed(a...) diff --git a/test/allowscalar.jl b/test/allowscalar.jl index fa35f35c..306689c5 100644 --- a/test/allowscalar.jl +++ b/test/allowscalar.jl @@ -4,10 +4,10 @@ using Test, SparseArrays A = sprandn(10, 20, 0.9) A[1, 1] = 2 @test A[1, 1] == 2 - SparseArrays.allowscalar(false) + SparseArrays.@allowscalar(false) @test_throws Any A[1, 1] @test_throws Any A[1, 1] = 2 - SparseArrays.allowscalar(true) + SparseArrays.@allowscalar(true) @test A[1, 1] == 2 A[1, 1] = 3 @test A[1, 1] == 3 @@ -15,9 +15,9 @@ using Test, SparseArrays B = sprandn(10, 0.9) B[1] = 2 @test B[1] == 2 - SparseArrays.allowscalar(false) + SparseArrays.@allowscalar(false) @test_throws Any B[1] - SparseArrays.allowscalar(true) + SparseArrays.@allowscalar(true) @test B[1] == 2 B[1] = 3 @test B[1] == 3