refuse a malformed enumerator

Anything in the list but a name or (name value) was taken apart as if
it were the pair: (! 1 2) came out ! = 1.
This commit is contained in:
2026-10-17 17:35:48 +03:00
parent b83009408c
commit 83a1355b6f
2 changed files with 16 additions and 2 deletions

View File

@@ -246,6 +246,14 @@
"enum color m = red"))
(test-assert "a malformed enum is rejected with its location"
(reports? "(enum)" "codegen.sex:1:"))
;; anything else in the list was the name its head was and the
;; value its second element: (! 1 2) came out `! = 1'
(test-assert "an enumerator is a name, or a name and a value"
(reports? "(enum color (red (! 1 2)))" "an enumerator is a name, or (name value)"))
(test-assert "and an operator is no name"
(reports? "(enum color (red (! 1)))" "an enumerator is a name, or (name value)"))
(test-assert "nor a value with no name"
(reports? "(enum color (red 7))" "an enumerator is a name, or (name value)"))
;; c-type handed the declarator's name to c-enum as the enum tag,
;; so this emitted `enum m { up, down }' with no variable at all
(test-assert "an anonymous enum keeps the variable"