take a docstring on a sum

record, struct and enum take one; sum read it where its variants go.
This commit is contained in:
2026-10-19 14:48:43 +03:00
parent 1fcce30f28
commit f2e8807359
4 changed files with 43 additions and 26 deletions

View File

@@ -422,6 +422,13 @@
;; A string as the first body form (or after the name of a struct,
;; union or enum) is a docstring: it becomes a comment immediately
;; before the declaration, not a statement inside it.
(test-group "a sum's docstring"
;; record, struct and enum took one, and sum read it as its variants
(test-assert "is a comment ahead of it"
(emits? "(sum shape \"A shape.\" ((dot ()) (box ((w int)))))" "/* A shape. */"))
(test-assert "and the sum is still one"
(emits? "(sum shape \"A shape.\" ((dot ()) (box ((w int)))))" "shapeǂbox")))
(test-group "docstrings"
(test-assert "appears before the function"
(emits? "(fn greet ((name (* char))) void \"Greet NAME.\" (printf \"hi\" name))"

View File

@@ -550,6 +550,9 @@ ahead of its pub forms."
(test "a private one is solved where it is"
'()
(interface-of "(var n _ 42)"))
(test-assert "a pub sum's variants are looked at past its docstring"
(interface-reports? "(record cell ((v int))) (pub sum s \"doc\" ((a ((c cell))) (b ())))"
"held by value"))
(test-assert "held by value it is an error"
(interface-reports? "(record cell ((v int))) (pub record shape ((c cell)))"
"held by value"))