From 2ed4212c760701e308dcf6c740720d18e8f2dbf1 Mon Sep 17 00:00:00 2001 From: Naim A <227396+naim94a@users.noreply.github.com> Date: Thu, 30 Mar 2023 00:07:08 +0300 Subject: [PATCH] bail! when #symbol is called without parameters (#440) --- library/src/compute/construct.rs | 3 +++ tests/typ/compute/construct.typ | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/library/src/compute/construct.rs b/library/src/compute/construct.rs index a30faf2ea..04195f421 100644 --- a/library/src/compute/construct.rs +++ b/library/src/compute/construct.rs @@ -258,6 +258,9 @@ pub fn symbol( variants: Vec>, ) -> Value { let mut list = Vec::new(); + if variants.is_empty() { + bail!(args.span, "expected at least one variant"); + } for Spanned { v, span } in variants { if list.iter().any(|(prev, _)| &v.0 == prev) { bail!(span, "duplicate variant"); diff --git a/tests/typ/compute/construct.typ b/tests/typ/compute/construct.typ index dc1467194..ee0a24b07 100644 --- a/tests/typ/compute/construct.typ +++ b/tests/typ/compute/construct.typ @@ -57,6 +57,10 @@ #envelope.lightning #envelope.fly +--- +// Error: 8-10 expected at least one variant +#symbol() + --- // Test conversion to string. #test(str(123), "123")