Skip to content

Commit

Permalink
Make allowscalar a macro with auto-world-age-increment (#583)
Browse files Browse the repository at this point in the history
Goes along with JuliaLang/julia#56509
  • Loading branch information
Keno authored Nov 20, 2024
1 parent 14333ea commit 1b4933c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/abstractsparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
8 changes: 4 additions & 4 deletions test/allowscalar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ 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

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
Expand Down

0 comments on commit 1b4933c

Please sign in to comment.