Skip to content

Commit 0c1204a

Browse files
committed
Make allowscalar a macro with auto-world-age-increment
Goes along with JuliaLang/julia#56509
1 parent 14333ea commit 0c1204a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/abstractsparse.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ else
184184
end
185185
end
186186

187+
macro allowscalar(p)
188+
quote
189+
$(allowscalar)($(esc(p)))
190+
@Core.latestworld
191+
end
192+
end
193+
187194
@inline _is_fixed(::AbstractArray) = false
188195
@inline _is_fixed(A::AbstractArray, Bs::Vararg{Any,N}) where N = _is_fixed(A) || (N > 0 && _is_fixed(Bs...))
189196
macro if_move_fixed(a...)

test/allowscalar.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ using Test, SparseArrays
44
A = sprandn(10, 20, 0.9)
55
A[1, 1] = 2
66
@test A[1, 1] == 2
7-
SparseArrays.allowscalar(false)
7+
SparseArrays.@allowscalar(false)
88
@test_throws Any A[1, 1]
99
@test_throws Any A[1, 1] = 2
10-
SparseArrays.allowscalar(true)
10+
SparseArrays.@allowscalar(true)
1111
@test A[1, 1] == 2
1212
A[1, 1] = 3
1313
@test A[1, 1] == 3
1414

1515
B = sprandn(10, 0.9)
1616
B[1] = 2
1717
@test B[1] == 2
18-
SparseArrays.allowscalar(false)
18+
SparseArrays.@allowscalar(false)
1919
@test_throws Any B[1]
20-
SparseArrays.allowscalar(true)
20+
SparseArrays.@allowscalar(true)
2121
@test B[1] == 2
2222
B[1] = 3
2323
@test B[1] == 3

0 commit comments

Comments
 (0)