Skip to content

Commit 20cafc8

Browse files
committed
feat: better errors for mixed tuples in ref
1 parent afe3118 commit 20cafc8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/macros.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ function _ref(lifetime_expr::Expr, expr::Expr, mut::Bool)
289289
$(refs...)
290290
end,
291291
)
292+
elseif Meta.isexpr(dest, :tuple) Meta.isexpr(src, :tuple)
293+
error("Cannot mix tuple and non-tuple arguments in @ref")
292294
else
293295
return esc(:($dest = $(ref)($lifetime, $src, $(QuoteNode(dest)), Val($mut))))
294296
end

test/reference_tests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ end
208208
@test rx2 == [1]
209209
end
210210

211+
# Need to pass tuple on both sides
212+
@test_throws(
213+
"Cannot mix tuple and non-tuple arguments in @ref", @eval @ref ~lt (a, b, c) = d
214+
)
215+
@test_throws(
216+
"Cannot mix tuple and non-tuple arguments in @ref", @eval @ref ~lt a = (b, c, d)
217+
)
218+
@test_throws(
219+
"Number of variables must match number of values in tuple unpacking",
220+
@eval @ref ~lt (a, b) = (c, d, e, f)
221+
)
222+
211223
# Test mutable references
212224
@own :mut mx = [1]
213225
@own :mut my = [2]

0 commit comments

Comments
 (0)