File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 49
49
"""
50
50
@allowscalar ex...
51
51
@disallowscalar ex...
52
+ allowscalar(::Function, ...)
52
53
53
54
Temporarily allow or disallow scalar iteration.
54
55
@@ -77,6 +78,15 @@ macro disallowscalar(ex)
77
78
end
78
79
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
+
80
90
81
91
# basic indexing
82
92
Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ function test_indexing(AT)
24
24
@test x[1 ] == 3
25
25
end
26
26
27
+ allowscalar () do
28
+ x[1 ] = 4
29
+ @test x[1 ] == 4
30
+ end
31
+
27
32
@test_throws ErrorException x[1 ]
28
33
@test_throws ErrorException x[1 ] = 1
29
34
You can’t perform that action at this time.
0 commit comments