Expand description
#3445 (ADR 0678 C, amended): a constant in a literal-only annotation argument.
A bare reference to a constant counts as the literal it is bound to wherever
an annotation argument takes a literal, as ADR 0762 already does for SQL
text. The resolution is a lookup, not an evaluation: a constant’s initialiser
is a closed static set (crate::consts::static_error), so a reference
resolves, by following constant-to-constant references, to literal text in
the source.
The pass runs once, over the parsed declarations, ahead of every validator
and reader of annotation arguments (the checker, hover, the emitters, the
OpenAPI readers of wire_name()), and replaces the argument’s value with the
resolved literal. Those consumers are syntactic and hold no constant table;
resolving once upstream means none of them can miss it. The replaced value
keeps the reference’s span, and bynk_syntax::ast::AnnotationArg::from_const names the
constant, so a diagnostic points at the reference and the IDE can find the
use.
An argument that does not resolve (not a constant, the wrong declared type, a refined constant, an initialiser that is not a plain literal, a name a local shadows) is left as written, so the annotation’s existing “bad argument” diagnostic fires on it unchanged. No new diagnostic code.
Functions§
- resolve_
annotation_ consts - Phase 5c: resolve a constant named by a literal-only annotation argument to
the literal it denotes, in every production unit. Run after
usesresolution (a used commons’ public constants are in scope) and before anything reads an annotation argument. A unit whose declarations changed has its symbol table rebuilt from the rewritten files, so the table holds the resolved literals too; the rebuild’s own diagnostics were already reported by the first build. - resolve_
single_ file - The single-file form of
resolve_annotation_consts, for a commons checked on its own (bynk check file.bynk, the playground, the editor’s single-file mode): nouses, so only the file’s own constants are in scope. It runs the same pass over a one-unit project, so the rules cannot differ. - with_
const_ origin - Attach the constant’s declaration to
erras a related span, when the argument was a reference to a constant in the same file.