We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5233b45 + 1788d90 commit bf2d515Copy full SHA for bf2d515
src/host/indexing.jl
@@ -49,6 +49,7 @@ end
49
"""
50
@allowscalar ex...
51
@disallowscalar ex...
52
+ allowscalar(::Function, ...)
53
54
Temporarily allow or disallow scalar iteration.
55
@@ -77,6 +78,15 @@ macro disallowscalar(ex)
77
78
end
79
80
81
+@doc (@doc @allowscalar) ->
82
+function allowscalar(f::Base.Callable, allow::Bool=true, warn::Bool=false)
83
+ prev = scalar_allowed[]
84
+ allowscalar(allow, warn)
85
+ ret = f()
86
+ scalar_allowed[] = prev
87
+ ret
88
+end
89
+
90
91
# basic indexing
92
test/testsuite/indexing.jl
@@ -24,6 +24,11 @@ function test_indexing(AT)
24
@test x[1] == 3
25
26
27
+ allowscalar() do
28
+ x[1] = 4
29
+ @test x[1] == 4
30
+ end
31
32
@test_throws ErrorException x[1]
33
@test_throws ErrorException x[1] = 1
34
0 commit comments