bail! when #symbol is called without parameters (#440)

This commit is contained in:
Naim A 2023-03-30 00:07:08 +03:00 committed by GitHub
parent f04b6ebc1a
commit 2ed4212c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -258,6 +258,9 @@ pub fn symbol(
variants: Vec<Spanned<Variant>>,
) -> 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");

View File

@ -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")