Skip to content

Commit b73fc63

Browse files
ararslanJeffBezanson
authored andcommitted
Provide a clearer error for at-threads for a, b (#34099)
Currently, nested loops specified as `for i = 1:2, j = 1:2` fail when passed to `at-threads`, since the macro assumes the expression is a single `for` loop. This change just provides a more explicit error message in this case.
1 parent d1d5ec4 commit b73fc63

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

base/threadingconstructs.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ macro threads(args...)
9090
throw(ArgumentError("need an expression argument to @threads"))
9191
end
9292
if ex.head === :for
93-
return _threadsfor(ex.args[1], ex.args[2])
93+
if ex.args[1] isa Expr && ex.args[1].head === :(=)
94+
return _threadsfor(ex.args[1], ex.args[2])
95+
else
96+
throw(ArgumentError("nested outer loops are not currently supported by @threads"))
97+
end
9498
else
9599
throw(ArgumentError("unrecognized argument to @threads"))
96100
end

test/threads_exec.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,3 +705,10 @@ let a = zeros(nthreads())
705705
_atthreads_with_error(a, false)
706706
@test a == [1:nthreads();]
707707
end
708+
709+
try
710+
@macroexpand @threads(for i = 1:10, j = 1:10; end)
711+
catch ex
712+
@test ex isa LoadError
713+
@test ex.error isa ArgumentError
714+
end

0 commit comments

Comments
 (0)