Add more error messages for local/anonymous labels

This commit is contained in:
2025-07-05 23:49:57 -07:00
parent eee57848e0
commit 3ff40241ee
4 changed files with 92 additions and 3 deletions
+22
View File
@@ -52,6 +52,28 @@ pub fn parse_stat_labels(stat: &Stat, ctx: &Context) -> ParsedStat {
Tag::Reference => {
let label = cap.children().find(|c| c.kind() == Tag::Label).unwrap();
label_captures.push((Tag::Reference, label));
// Detect invalid recipients.
// This should probably happen later in processing, but
// we'd need an AST that can track spans for message recipients.
let mut recipient = None;
let (mut anon, mut local) = (false, false);
for child in cap.walk_children() {
match child.kind() {
Tag::Anon => anon = true,
Tag::Local => local = true,
Tag::Recipient => recipient = Some(child),
_ => {}
}
}
if let Some(recipient) = recipient {
let ctx = ctx.with_span(recipient.span());
if anon {
ctx.error("message targets not allowed for anonymous labels");
} else if local {
ctx.error("message targets not supported for local labels");
}
}
}
_ => {}
}