Skip to main content

bynk_syntax/
diagnostics.rs

1//! Central registry of diagnostic codes.
2//!
3//! This is the single source of truth for the `bynk.*` codes the compiler can
4//! emit. The reference page `docs/src/reference/diagnostics.md` is generated
5//! from [`render_markdown`], and the test `tests/diagnostics_registry.rs`
6//! asserts that this table matches exactly the set of codes used across the
7//! compiler source — so a new code cannot be introduced without documenting it
8//! here, and a removed code cannot linger in the docs.
9//!
10//! Each entry is a `(code, summary)` pair, optionally tagged with the grammar
11//! production(s) it constrains (`grammar_symbol`). The category shown in the
12//! generated reference is derived from the second dotted segment of the code;
13//! the grammar weave (`docs/grammar-semantics.json`, the
14//! `{{#grammar-semantics}}` directive, and the diagnostics page's Construct
15//! column) is generated from `grammar_symbol`.
16
17/// One documented diagnostic: its stable code and a one-line summary of the
18/// cause. Richer "cause and fix" material for the common diagnostics lives in
19/// the troubleshooting how-to guides.
20pub struct DiagnosticInfo {
21    pub code: &'static str,
22    pub summary: &'static str,
23    /// The grammar production(s) this diagnostic constrains, by `tree-sitter`
24    /// rule name (e.g. `http_handler`). This is the single source of the
25    /// "static semantics" weave: a grammar-reference entry embeds the
26    /// diagnostics for a rule via `{{#grammar-semantics <rule>}}`, generated
27    /// from here. Empty for diagnostics with no single governing construct
28    /// (e.g. `bynk.boundary.structural_mismatch`). Every non-empty name is
29    /// checked against the grammar by `tests/diagnostics_registry.rs`.
30    pub grammar_symbol: &'static [&'static str],
31}
32
33/// Every diagnostic code the compiler emits, sorted by code.
34pub const REGISTRY: &[DiagnosticInfo] = &[
35    d(
36        "bynk.actor.bearer_identity_not_string_constructible",
37        "A `Bearer` actor's identity is not a string-constructible type.",
38    ),
39    d(
40        "bynk.actor.bearer_missing_secret",
41        "A `Bearer` actor does not name its signing secret.",
42    ),
43    d(
44        "bynk.actor.binder_shadows_param",
45        "A `by` actor binder collides with a handler parameter of the same name.",
46    ),
47    d(
48        "bynk.actor.by_on_agent",
49        "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
50    ),
51    d(
52        "bynk.actor.duplicate_sum_scheme",
53        "Two peers in a multi-actor sum share an authentication scheme.",
54    ),
55    d(
56        "bynk.actor.identity_not_sealed",
57        "An actor identity type is not a context-ownable (sealed) value type.",
58    ),
59    d(
60        "bynk.actor.missing_by_on_http",
61        "An HTTP handler lacks the required `by` actor clause.",
62    ),
63    d(
64        "bynk.actor.outside_context",
65        "An `actor` was declared outside a context (e.g. in a commons).",
66    ),
67    d(
68        "bynk.actor.refinement_base_unsupported",
69        "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
70    ),
71    d(
72        "bynk.actor.refinement_in_sum",
73        "A refinement actor appears as a member of a multi-actor sum.",
74    ),
75    d(
76        "bynk.actor.refinement_predicate_unsupported",
77        "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
78    ),
79    d(
80        "bynk.actor.scheme_not_admissible",
81        "An actor's scheme is not admissible on this handler's protocol.",
82    ),
83    d(
84        "bynk.actor.signature_identity_unsupported",
85        "A `Signature` actor declared an `identity`, which is not yet supported.",
86    ),
87    d(
88        "bynk.actor.signature_missing_header",
89        "A `Signature` actor does not name its signature header.",
90    ),
91    d(
92        "bynk.actor.signature_missing_secret",
93        "A `Signature` actor does not name its signing secret.",
94    ),
95    d(
96        "bynk.actor.signature_requires_body",
97        "A `Signature` handler does not take a `body` parameter.",
98    ),
99    d(
100        "bynk.actor.signature_tolerance_without_timestamp",
101        "A `Signature` actor set `tolerance` without a `timestamp` header.",
102    ),
103    d(
104        "bynk.actor.sum_requires_binder",
105        "A multi-actor sum `by` clause has no binder to match the resolved actor.",
106    ),
107    d(
108        "bynk.actor.unknown_actor",
109        "A handler's `by` clause names an actor that is not declared.",
110    ),
111    d(
112        "bynk.actor.unknown_scheme",
113        "An actor declares an authentication scheme that is not compiler-known.",
114    ),
115    d(
116        "bynk.actor.unreachable_sum_arm",
117        "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
118    ),
119    dg(
120        "bynk.adapter.consumes_context",
121        "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
122        &["consumes_decl"],
123    ),
124    dg(
125        "bynk.adapter.consumes_requires_selection",
126        "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
127        &["consumes_decl"],
128    ),
129    dg(
130        "bynk.adapter.disallowed_item",
131        "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
132        &["adapter_decl"],
133    ),
134    dg(
135        "bynk.adapter.duplicate_binding",
136        "An `adapter` declared more than one `binding` clause.",
137        &["binding_decl"],
138    ),
139    dg(
140        "bynk.adapter.no_binding",
141        "An `adapter` declares an external provider but no `binding` module to supply it.",
142        &["adapter_decl"],
143    ),
144    dg(
145        "bynk.adapter.provider_has_body",
146        "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
147        &["provider_decl"],
148    ),
149    dg(
150        "bynk.agent.construction_arity",
151        "An agent was constructed with the wrong number of key arguments.",
152        &["agent_decl"],
153    ),
154    dg(
155        "bynk.agent.handler_arity",
156        "An agent handler was called with the wrong number of arguments.",
157        &["agent_decl"],
158    ),
159    dg(
160        "bynk.agent.handler_not_found",
161        "Called a handler the agent does not declare.",
162        &["agent_decl"],
163    ),
164    dg(
165        "bynk.agent.key_mismatch",
166        "An agent key argument has the wrong type.",
167        &["agent_decl"],
168    ),
169    dg(
170        "bynk.agent.outside_context",
171        "An `agent` was declared outside a context.",
172        &["agent_decl"],
173    ),
174    dg(
175        "bynk.agent.return_not_effect",
176        "An agent handler's return type is not an `Effect`.",
177        &["agent_decl"],
178    ),
179    dg(
180        "bynk.agents.bad_state_initialiser",
181        "An agent `store` field initialiser is not a static value of the field's type.",
182        &["store_field"],
183    ),
184    dg(
185        "bynk.agents.non_zeroable_state_field",
186        "An agent `store` field has no initialiser and no implicit zero value.",
187        &["store_field"],
188    ),
189    dg(
190        "bynk.assert.non_bool",
191        "`assert` was given a non-`Bool` expression.",
192        &["assert_expr"],
193    ),
194    dg(
195        "bynk.assert.outside_test",
196        "`assert` was used outside a test case body.",
197        &["assert_expr"],
198    ),
199    d(
200        "bynk.boundary.structural_mismatch",
201        "Data crossing a context boundary did not match the expected shape.",
202    ),
203    dg(
204        "bynk.capability.op_arity",
205        "A capability operation was called with the wrong number of arguments.",
206        &["capability_decl"],
207    ),
208    dg(
209        "bynk.capability.outside_context",
210        "A `capability` was declared outside a context.",
211        &["capability_decl"],
212    ),
213    dg(
214        "bynk.capability.unknown_operation",
215        "Referenced an operation the capability does not declare.",
216        &["capability_decl"],
217    ),
218    d(
219        "bynk.cell.invalid_target",
220        "A `:=` write targets something that is not a `store Cell` field.",
221    ),
222    d(
223        "bynk.cell.self_reference",
224        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
225    ),
226    dg(
227        "bynk.consumes.alias_conflict",
228        "Two `consumes` aliases collide.",
229        &["consumes_decl"],
230    ),
231    dg(
232        "bynk.consumes.capability_name_clash",
233        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
234        &["consumes_decl"],
235    ),
236    dg(
237        "bynk.consumes.in_commons",
238        "`consumes` appears in a `commons` (it is only valid in a context).",
239        &["consumes_decl"],
240    ),
241    dg(
242        "bynk.consumes.name_conflict",
243        "A `consumes` name collides with another name in scope.",
244        &["consumes_decl"],
245    ),
246    dg(
247        "bynk.consumes.self_reference",
248        "A context `consumes` itself.",
249        &["consumes_decl"],
250    ),
251    dg(
252        "bynk.consumes.service_arity",
253        "A consumed service was called with the wrong number of arguments.",
254        &["consumes_decl"],
255    ),
256    dg(
257        "bynk.consumes.target_is_commons",
258        "`consumes` targets a `commons` instead of a context.",
259        &["consumes_decl"],
260    ),
261    dg(
262        "bynk.consumes.unknown_context",
263        "`consumes` names a context that does not exist.",
264        &["consumes_decl"],
265    ),
266    dg(
267        "bynk.consumes.unknown_service",
268        "Called a service the consumed context does not declare.",
269        &["consumes_decl"],
270    ),
271    d(
272        "bynk.context.consumes_cycle",
273        "Contexts form a `consumes` dependency cycle.",
274    ),
275    d(
276        "bynk.context.external_construction",
277        "A context-owned type was constructed from outside that context.",
278    ),
279    dg(
280        "bynk.context.external_provider",
281        "A bodiless (external) provider was declared outside an `adapter`.",
282        &["provider_decl"],
283    ),
284    d(
285        "bynk.context.opaque_inspection",
286        "An opaquely-exported type was inspected from outside its context.",
287    ),
288    dg(
289        "bynk.cron.bad_params",
290        "A cron handler declares more than one parameter, or a non-`Int` one.",
291        &["cron_handler"],
292    ),
293    dg(
294        "bynk.cron.duplicate_schedule",
295        "Two cron handlers declare the same schedule.",
296        &["cron_handler"],
297    ),
298    dg(
299        "bynk.cron.invalid_schedule",
300        "A cron expression is not five whitespace-separated fields.",
301        &["cron_handler"],
302    ),
303    dg(
304        "bynk.cron.return_not_effect_result",
305        "A cron handler does not return `Effect[Result[(), E]]`.",
306        &["cron_handler"],
307    ),
308    d(
309        "bynk.duration.literal_overflow",
310        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
311    ),
312    dg(
313        "bynk.effect.bind_in_pure_context",
314        "An `<-` bind was used in a pure (non-effectful) context.",
315        &["effect_let_stmt"],
316    ),
317    dg(
318        "bynk.effect.bind_on_non_effect",
319        "An `<-` bind was applied to a non-`Effect` value.",
320        &["effect_let_stmt"],
321    ),
322    d(
323        "bynk.effect.capability_in_pure_context",
324        "A capability was used in a pure context.",
325    ),
326    d(
327        "bynk.effect.cross_context_in_pure_context",
328        "A cross-context call was made in a pure context.",
329    ),
330    dg(
331        "bynk.effect.fn_value_in_pure_context",
332        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
333        &["call"],
334    ),
335    dg(
336        "bynk.exports.capability_not_provided",
337        "An exported capability has no provider in its context.",
338        &["exports_decl"],
339    ),
340    dg(
341        "bynk.exports.conflicting_visibility",
342        "A type is exported with conflicting visibilities.",
343        &["exports_decl"],
344    ),
345    dg(
346        "bynk.exports.duplicate_export",
347        "The same name is exported more than once.",
348        &["exports_decl"],
349    ),
350    dg(
351        "bynk.exports.duplicate_in_clause",
352        "A name appears twice in one `exports` clause.",
353        &["exports_decl"],
354    ),
355    dg(
356        "bynk.exports.undeclared_capability",
357        "`exports capability` names a capability that is not declared.",
358        &["exports_decl"],
359    ),
360    dg(
361        "bynk.exports.undeclared_type",
362        "`exports` names a type that is not declared.",
363        &["exports_decl"],
364    ),
365    dg(
366        "bynk.generics.no_bounds",
367        "A type parameter carries a bound (`[A: …]`); bounded generics are not in v0.20a.",
368        &["fn_decl"],
369    ),
370    dg(
371        "bynk.generics.no_generic_types",
372        "A `type` declaration carries a type-parameter list; generic type declarations are not in v0.20a (type parameters belong to functions).",
373        &["type_decl"],
374    ),
375    dg(
376        "bynk.generics.type_arg_mismatch",
377        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
378        &["call"],
379    ),
380    dg(
381        "bynk.generics.uninferable_type_arg",
382        "A generic function's type parameter could not be inferred from the arguments and was not given explicitly (`name[T](…)`); a bare generic function also cannot be passed as a value in v0.20a.",
383        &["call"],
384    ),
385    dg(
386        "bynk.given.cross_context_unknown_capability",
387        "`given B.Cap` names a capability the consumed context does not export.",
388        &["given_clause"],
389    ),
390    dg(
391        "bynk.given.undeclared_capability",
392        "A handler uses a capability it did not declare with `given`.",
393        &["given_clause"],
394    ),
395    dg(
396        "bynk.given.unknown_capability",
397        "`given` names a capability that does not exist.",
398        &["given_clause"],
399    ),
400    dg(
401        "bynk.given.unused_capability",
402        "A `given` capability is never used (warning).",
403        &["given_clause"],
404    ),
405    d(
406        "bynk.held.branch_divergence",
407        "Branches of a conditional leave a held value (e.g. `Connection[F]`) in inconsistent ownership states — one consumes or stores it, another leaves it owned (§2.9.5, real-time track slice 2).",
408    ),
409    d(
410        "bynk.held.consume_on_borrow",
411        "A consuming operation (`close`/`put`/`take`) is called on a *borrowed* held reference — borrows admit only non-consuming operations like `send` (§2.9.3, real-time track slice 2).",
412    ),
413    d(
414        "bynk.held.leak",
415        "A held value (`Connection[F]`) is still owned at scope exit — it must be disposed (stored, closed, or transferred) before the handler returns (§2.9.1, real-time track slice 2).",
416    ),
417    d(
418        "bynk.held.unsupported_map_op",
419        "A held `Map[K, Connection]` is given an `update`/`upsert` — a held resource cannot be transformed by a `(Connection) -> Connection` function; use `put`/`get`/`remove` (real-time track slice 3b-ii).",
420    ),
421    d(
422        "bynk.held.unsupported_storage",
423        "A held value (`Connection[F]`) is stored in a `Set`/`Log`/`Cache` — held values may only live in `Cell[Option[Connection]]` or `Map[K, Connection]` (§2.9.3, real-time track slice 2).",
424    ),
425    d(
426        "bynk.held.use_after_consume",
427        "A held value (`Connection[F]`) is used after a consuming operation (`close`/`put`/`take`) ended its lifetime (§2.9.2, real-time track slice 2).",
428    ),
429    dg(
430        "bynk.http.body_on_get_or_delete",
431        "A GET or DELETE handler declares a `body` parameter.",
432        &["http_handler"],
433    ),
434    dg(
435        "bynk.http.duplicate_route",
436        "Two handlers share the same method and route.",
437        &["http_handler"],
438    ),
439    dg(
440        "bynk.http.extra_param",
441        "A handler parameter is neither a path parameter nor `body`.",
442        &["http_handler"],
443    ),
444    dg(
445        "bynk.http.invalid_path",
446        "An HTTP route path is malformed.",
447        &["http_handler"],
448    ),
449    dg(
450        "bynk.http.path_param_not_stringy",
451        "A path parameter's type is not constructible from a string.",
452        &["http_handler"],
453    ),
454    dg(
455        "bynk.http.reserved_prefix",
456        "A route uses the reserved `/_bynk/` prefix.",
457        &["http_handler"],
458    ),
459    dg(
460        "bynk.http.return_not_effect_http_result",
461        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
462        &["http_handler"],
463    ),
464    dg(
465        "bynk.http.unbound_path_param",
466        "A `:name` route segment has no matching handler parameter.",
467        &["http_handler"],
468    ),
469    d(
470        "bynk.index.bad_argument",
471        "An `@indexed` argument is not a `by: <field>` label.",
472    ),
473    d(
474        "bynk.index.missing",
475        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
476    ),
477    d(
478        "bynk.index.unkeyable_key",
479        "An `@indexed(by: k)` field is not value-keyable.",
480    ),
481    d(
482        "bynk.index.unknown_key",
483        "An `@indexed(by: k)` field is not a field of the map's value type.",
484    ),
485    d(
486        "bynk.index.unused",
487        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
488    ),
489    dg(
490        "bynk.integration.duplicate_participant",
491        "A context is listed more than once in a `wires` clause.",
492        &["wires_decl"],
493    ),
494    dg(
495        "bynk.integration.duplicate_suite",
496        "Two integration tests share the same suite name.",
497        &["integration_decl"],
498    ),
499    dg(
500        "bynk.integration.mock_in_integration",
501        "`mocks` is not allowed in an integration test.",
502        &["mocks_decl"],
503    ),
504    dg(
505        "bynk.integration.too_few_participants",
506        "An integration test wires fewer than two contexts.",
507        &["wires_decl"],
508    ),
509    dg(
510        "bynk.integration.unknown_participant",
511        "A `wires` clause names something that is not a declared context.",
512        &["wires_decl"],
513    ),
514    dg(
515        "bynk.integration.unwired_dependency",
516        "A participant consumes a context that is not wired into the integration test.",
517        &["integration_decl"],
518    ),
519    d(
520        "bynk.invariant.cross_agent_reference",
521        "An invariant predicate references another agent; invariants are per-agent.",
522    ),
523    d(
524        "bynk.invariant.duplicate_name",
525        "An agent declares two invariants with the same name.",
526    ),
527    d(
528        "bynk.invariant.impure_predicate",
529        "An invariant predicate uses an effectful or test-only construct.",
530    ),
531    d(
532        "bynk.invariant.not_bool",
533        "An invariant predicate does not have type `Bool`.",
534    ),
535    dg(
536        "bynk.lambda.unannotated_param",
537        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
538        &["lambda_expr"],
539    ),
540    dg(
541        "bynk.lex.bad_escape",
542        "An invalid escape sequence in a string literal.",
543        &["string_literal"],
544    ),
545    dg(
546        "bynk.lex.float_literal_overflow",
547        "A float literal does not fit a finite 64-bit float.",
548        &["float_literal"],
549    ),
550    dg(
551        "bynk.lex.integer_overflow",
552        "An integer literal is out of range.",
553        &["number_literal"],
554    ),
555    d(
556        "bynk.lex.unclosed_doc_block",
557        "A documentation block is not closed.",
558    ),
559    d(
560        "bynk.lex.unexpected_character",
561        "An unexpected character in the source.",
562    ),
563    dg(
564        "bynk.lex.unterminated_interpolation",
565        "An interpolation hole `\\(…)` is not closed on its line.",
566        &["string_literal"],
567    ),
568    dg(
569        "bynk.lex.unterminated_string",
570        "A string literal is not terminated.",
571        &["string_literal"],
572    ),
573    d(
574        "bynk.list.deprecated_function",
575        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
576    ),
577    dg(
578        "bynk.mock.arity",
579        "`Mock[T]` was given the wrong number of pin arguments.",
580        &["mock_expr"],
581    ),
582    dg(
583        "bynk.mock.duplicate_target",
584        "A `mocks` target is declared more than once.",
585        &["mocks_decl"],
586    ),
587    dg(
588        "bynk.mock.in_commons_test",
589        "`mocks` used in a commons test, where there is no dependency to inject.",
590        &["mocks_decl"],
591    ),
592    dg(
593        "bynk.mock.literal_violates",
594        "A pinned `Mock[T]` value violates the type's refinement.",
595        &["mock_expr"],
596    ),
597    dg(
598        "bynk.mock.needs_pin",
599        "A bare `Mock[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
600        &["mock_expr"],
601    ),
602    dg(
603        "bynk.mock.outside_test",
604        "`Mock[T]` was used outside a test case body.",
605        &["mock_expr"],
606    ),
607    dg(
608        "bynk.mock.pin_not_literal",
609        "A `Mock[T]` pin argument is not a compile-time literal.",
610        &["mock_expr"],
611    ),
612    dg(
613        "bynk.mock.pin_unsupported",
614        "A pin was given for a type kind that does not support pinning.",
615        &["mock_expr"],
616    ),
617    dg(
618        "bynk.mock.signature_mismatch",
619        "A `mocks` implementation's signature does not match the capability.",
620        &["mocks_decl"],
621    ),
622    dg(
623        "bynk.mock.unknown_target",
624        "`mocks` names a capability that is not in scope.",
625        &["mocks_decl"],
626    ),
627    dg(
628        "bynk.mock.unknown_type",
629        "`Mock[T]` names a type that does not resolve.",
630        &["mock_expr"],
631    ),
632    dg(
633        "bynk.mock.unsupported_kind",
634        "`Mock[T]` cannot fabricate a value for this kind of type.",
635        &["mock_expr"],
636    ),
637    d(
638        "bynk.namespace.reserved",
639        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
640    ),
641    dg(
642        "bynk.parse.consumes_after_decls",
643        "`consumes` appears after other declarations.",
644        &["consumes_decl"],
645    ),
646    dg(
647        "bynk.parse.empty_agent",
648        "An `agent` body is empty.",
649        &["agent_decl"],
650    ),
651    dg(
652        "bynk.parse.empty_capability",
653        "A `capability` body is empty.",
654        &["capability_decl"],
655    ),
656    d(
657        "bynk.parse.empty_interpolation",
658        "An interpolation hole `\\(…)` contains no expression.",
659    ),
660    dg(
661        "bynk.parse.empty_match",
662        "A `match` has no arms.",
663        &["match_expr"],
664    ),
665    dg(
666        "bynk.parse.empty_mock_body",
667        "A `mocks` body is empty.",
668        &["mocks_decl"],
669    ),
670    dg(
671        "bynk.parse.empty_service",
672        "A `service` body is empty.",
673        &["service_decl"],
674    ),
675    dg(
676        "bynk.parse.expected_agent_key",
677        "Expected a `key` declaration in an agent.",
678        &["agent_decl"],
679    ),
680    d(
681        "bynk.parse.expected_agent_storage",
682        "An agent declares no storage — it has no `store` fields.",
683    ),
684    dg(
685        "bynk.parse.expected_base_type",
686        "Expected a base type.",
687        &["base_type"],
688    ),
689    dg(
690        "bynk.parse.expected_capability_op",
691        "Expected a capability operation.",
692        &["capability_op"],
693    ),
694    d("bynk.parse.expected_expression", "Expected an expression."),
695    dg(
696        "bynk.parse.expected_handler",
697        "Expected a handler.",
698        &["handler"],
699    ),
700    d("bynk.parse.expected_item", "Expected a declaration."),
701    dg(
702        "bynk.parse.expected_predicate",
703        "Expected a refinement predicate.",
704        &["refinement"],
705    ),
706    dg(
707        "bynk.parse.expected_provider_op",
708        "Expected a provider operation.",
709        &["provider_op"],
710    ),
711    d("bynk.parse.expected_token", "Expected a specific token."),
712    d("bynk.parse.expected_type", "Expected a type."),
713    d(
714        "bynk.parse.expected_unit_header",
715        "Expected a `commons` or `context` header.",
716    ),
717    dg(
718        "bynk.parse.expected_visibility",
719        "Expected a visibility keyword.",
720        &["exports_decl"],
721    ),
722    dg(
723        "bynk.parse.exports_after_decls",
724        "`exports` appears after other declarations.",
725        &["exports_decl"],
726    ),
727    d(
728        "bynk.parse.extra_tokens",
729        "Unexpected tokens after an otherwise complete construct.",
730    ),
731    dg(
732        "bynk.parse.generic_arg_count",
733        "Wrong number of generic type arguments.",
734        &["generic_type_ref"],
735    ),
736    dg(
737        "bynk.parse.handler_in_agent",
738        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
739        &["handler"],
740    ),
741    d(
742        "bynk.parse.invariant_after_handler",
743        "An `invariant` was declared after a handler; invariants precede handlers.",
744    ),
745    dg(
746        "bynk.parse.malformed_float_literal",
747        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
748        &["float_literal"],
749    ),
750    dg(
751        "bynk.parse.non_associative",
752        "A non-associative operator was chained (e.g. `a == b == c`).",
753        &["binary_expr"],
754    ),
755    d(
756        "bynk.parse.orphan_doc_block",
757        "A documentation block is not attached to a declaration (warning).",
758    ),
759    dg(
760        "bynk.parse.reserved_keyword",
761        "A reserved keyword was used as an identifier.",
762        &["identifier"],
763    ),
764    dg(
765        "bynk.parse.self_outside_method",
766        "`self` used outside a method or handler.",
767        &["self_expr"],
768    ),
769    d(
770        "bynk.parse.storage_after_phase",
771        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
772    ),
773    d(
774        "bynk.parse.unexpected_adapter",
775        "An `adapter` appeared where it is not allowed.",
776    ),
777    dg(
778        "bynk.parse.unexpected_context",
779        "A `context` appeared where it is not allowed.",
780        &["context_decl"],
781    ),
782    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
783    dg(
784        "bynk.parse.unexpected_test",
785        "A `test` appeared where it is not allowed.",
786        &["test_decl"],
787    ),
788    d(
789        "bynk.parse.unknown_effect_method",
790        "An unknown method on `Effect`.",
791    ),
792    dg(
793        "bynk.parse.unknown_handler_kind",
794        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
795        &["handler"],
796    ),
797    dg(
798        "bynk.parse.unknown_predicate",
799        "An unknown refinement predicate.",
800        &["predicate_name"],
801    ),
802    dg(
803        "bynk.parse.uses_after_decls",
804        "`uses` appears after other declarations.",
805        &["uses_decl"],
806    ),
807    d(
808        "bynk.project.file_and_directory",
809        "A unit exists as both a file and a directory.",
810    ),
811    d(
812        "bynk.project.inconsistent_commons_name",
813        "A source file's path does not match its declared name.",
814    ),
815    d(
816        "bynk.project.inconsistent_test_path",
817        "A test file's path does not match its target's name.",
818    ),
819    d(
820        "bynk.project.kind_conflict",
821        "A name is declared as both a commons and a context.",
822    ),
823    d(
824        "bynk.project.no_root",
825        "No project root could be determined.",
826    ),
827    d(
828        "bynk.project.no_sources",
829        "The project contains no source files.",
830    ),
831    d(
832        "bynk.project.read_failed",
833        "A source file could not be read.",
834    ),
835    dg(
836        "bynk.provider.dependency_cycle",
837        "Providers form a capability dependency cycle through `given`.",
838        &["provider_decl"],
839    ),
840    dg(
841        "bynk.provider.extra_operation",
842        "A `provides` block implements an operation not in the capability.",
843        &["provider_decl"],
844    ),
845    dg(
846        "bynk.provider.missing_operation",
847        "A `provides` block is missing a capability operation.",
848        &["provider_decl"],
849    ),
850    dg(
851        "bynk.provider.outside_context",
852        "`provides` was declared outside a context.",
853        &["provider_decl"],
854    ),
855    dg(
856        "bynk.provider.signature_mismatch",
857        "A `provides` operation's signature does not match the capability.",
858        &["provider_decl"],
859    ),
860    dg(
861        "bynk.provider.unknown_capability",
862        "`provides` names a capability that does not exist.",
863        &["provider_decl"],
864    ),
865    d(
866        "bynk.query.join_key_mismatch",
867        "A `joinOn`/`leftJoin` left and right key function return different types.",
868    ),
869    dg(
870        "bynk.query.sum_needs_numeric",
871        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
872        &[],
873    ),
874    dg(
875        "bynk.queue.bad_params",
876        "An `on message` handler does not take exactly one `message` parameter.",
877        &["queue_handler"],
878    ),
879    dg(
880        "bynk.queue.duplicate_consumer",
881        "Two `on message` handlers consume the same queue.",
882        &["queue_handler"],
883    ),
884    dg(
885        "bynk.queue.invalid_name",
886        "A `from queue(\"…\")` binding has an empty queue name.",
887        &["queue_handler"],
888    ),
889    dg(
890        "bynk.queue.return_not_queue_result",
891        "An `on message` handler does not return `Effect[QueueResult]`.",
892        &["handler"],
893    ),
894    dg(
895        "bynk.record_spread.field_type_mismatch",
896        "A record-spread override has the wrong type for the field.",
897        &["record_spread"],
898    ),
899    dg(
900        "bynk.record_spread.non_record_base",
901        "The base of a record spread is not a record.",
902        &["record_spread"],
903    ),
904    dg(
905        "bynk.record_spread.type_mismatch",
906        "A record spread's base is a different record type.",
907        &["record_spread"],
908    ),
909    dg(
910        "bynk.record_spread.unknown_field",
911        "A record spread overrides a field the record does not have.",
912        &["record_spread"],
913    ),
914    dg(
915        "bynk.refine.literal_violates",
916        "A literal does not satisfy the refined type's predicate.",
917        &["refined_type"],
918    ),
919    dg(
920        "bynk.requires.unpinned_dependency",
921        "An adapter `binding … requires { … }` entry has an unpinned version range.",
922        &["binding_decl"],
923    ),
924    d(
925        "bynk.resolve.ambiguous_variant",
926        "A variant name is ambiguous across several sum types.",
927    ),
928    dg(
929        "bynk.resolve.arity_mismatch",
930        "A function was called with the wrong number of arguments.",
931        &["call"],
932    ),
933    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
934    dg(
935        "bynk.resolve.duplicate_agent",
936        "Two agents share a name.",
937        &["agent_decl"],
938    ),
939    dg(
940        "bynk.resolve.duplicate_capability",
941        "Two capabilities share a name.",
942        &["capability_decl"],
943    ),
944    dg(
945        "bynk.resolve.duplicate_field",
946        "A record declares a field twice.",
947        &["record_type"],
948    ),
949    dg(
950        "bynk.resolve.duplicate_field_init",
951        "A record construction initialises a field twice.",
952        &["record_construction"],
953    ),
954    dg(
955        "bynk.resolve.duplicate_fn",
956        "Two functions share a name.",
957        &["fn_decl"],
958    ),
959    dg(
960        "bynk.resolve.duplicate_method",
961        "Two methods share a name.",
962        &["fn_decl"],
963    ),
964    dg(
965        "bynk.resolve.duplicate_param",
966        "A parameter name is repeated.",
967        &["param"],
968    ),
969    dg(
970        "bynk.resolve.duplicate_provider",
971        "A capability is provided more than once.",
972        &["provider_decl"],
973    ),
974    dg(
975        "bynk.resolve.duplicate_service",
976        "Two services share a name.",
977        &["service_decl"],
978    ),
979    dg(
980        "bynk.resolve.duplicate_type",
981        "Two types share a name.",
982        &["type_decl"],
983    ),
984    dg(
985        "bynk.resolve.duplicate_variant",
986        "A sum type declares a variant twice.",
987        &["sum_type"],
988    ),
989    d(
990        "bynk.resolve.fn_without_call",
991        "A function was referenced without being called.",
992    ),
993    dg(
994        "bynk.resolve.let_shadows_fn",
995        "A `let` binding shadows a function.",
996        &["let_stmt"],
997    ),
998    dg(
999        "bynk.resolve.let_shadows_type",
1000        "A `let` binding shadows a type.",
1001        &["let_stmt"],
1002    ),
1003    d(
1004        "bynk.resolve.method_unknown_type",
1005        "A method is defined on an unknown type.",
1006    ),
1007    dg(
1008        "bynk.resolve.missing_field",
1009        "A record construction omits a required field.",
1010        &["record_construction"],
1011    ),
1012    d(
1013        "bynk.resolve.name_conflict",
1014        "Two declarations share a name.",
1015    ),
1016    dg(
1017        "bynk.resolve.not_a_record_type",
1018        "Record syntax was used on a non-record type.",
1019        &["record_construction"],
1020    ),
1021    dg(
1022        "bynk.resolve.opaque_record_construction",
1023        "An opaque type was constructed with record syntax.",
1024        &["record_construction"],
1025    ),
1026    dg(
1027        "bynk.resolve.param_as_function",
1028        "A value (such as a parameter) was called as a function.",
1029        &["call"],
1030    ),
1031    dg(
1032        "bynk.resolve.recursive_record_field",
1033        "A record directly contains a field of its own type.",
1034        &["record_type"],
1035    ),
1036    dg(
1037        "bynk.resolve.self_outside_method",
1038        "`self` referenced outside a method or handler.",
1039        &["self_expr"],
1040    ),
1041    dg(
1042        "bynk.resolve.type_as_function",
1043        "A type name was called as if it were a function.",
1044        &["call"],
1045    ),
1046    d(
1047        "bynk.resolve.type_in_expr",
1048        "A type name was used where a value is expected.",
1049    ),
1050    dg(
1051        "bynk.resolve.unconsumed_context",
1052        "A context's service was called without a `consumes` declaration.",
1053        &["consumes_decl"],
1054    ),
1055    dg(
1056        "bynk.resolve.unknown_field",
1057        "Accessed a field the record does not have.",
1058        &["field_access"],
1059    ),
1060    dg(
1061        "bynk.resolve.unknown_function",
1062        "Called a function that does not exist.",
1063        &["call"],
1064    ),
1065    d(
1066        "bynk.resolve.unknown_name",
1067        "Referenced a name that is not in scope.",
1068    ),
1069    dg(
1070        "bynk.resolve.unknown_static_member",
1071        "Referenced an unknown static member (e.g. `T.x`).",
1072        &["field_access"],
1073    ),
1074    d(
1075        "bynk.resolve.unknown_type",
1076        "Referenced a type that does not exist.",
1077    ),
1078    dg(
1079        "bynk.send.in_pure_context",
1080        "A `~>` send was used in a pure (non-effectful) context.",
1081        &["effect_send_stmt"],
1082    ),
1083    dg(
1084        "bynk.send.non_effect",
1085        "A `~>` send was applied to a non-`Effect` value.",
1086        &["effect_send_stmt"],
1087    ),
1088    dg(
1089        "bynk.send.requires_unit",
1090        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1091        &["effect_send_stmt"],
1092    ),
1093    dg(
1094        "bynk.service.missing_from",
1095        "A `from`-less service has a handler other than `on call`.",
1096        &["service_decl"],
1097    ),
1098    dg(
1099        "bynk.service.mixed_protocols",
1100        "A service mixes handler forms that do not match its `from <protocol>`.",
1101        &["service_decl"],
1102    ),
1103    dg(
1104        "bynk.service.outside_context",
1105        "A `service` was declared outside a context.",
1106        &["service_decl"],
1107    ),
1108    dg(
1109        "bynk.service.return_not_effect",
1110        "A service handler's return type is not an `Effect`.",
1111        &["service_decl"],
1112    ),
1113    dg(
1114        "bynk.service.unknown_protocol",
1115        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1116        &["service_decl"],
1117    ),
1118    d(
1119        "bynk.service.websocket_header",
1120        "The `from WebSocket` header is malformed — it binds frame types as `WebSocket(in: <type>, out: <type>)` (real-time track slice 3).",
1121    ),
1122    d(
1123        "bynk.service.websocket_multiple",
1124        "A context holds more than one `from WebSocket` service — at v1 the Workers upgrade routes by the `Upgrade: websocket` header alone, so one WebSocket service per context (real-time track slice 3b).",
1125    ),
1126    d(
1127        "bynk.service.websocket_open_arity",
1128        "A `from WebSocket` service must hold exactly one `on open` handler (the edge upgrade), and at most one `on message` (inbound) and one `on close` (real-time track slice 3/3b-iii).",
1129    ),
1130    d(
1131        "bynk.store.annotation_kind_mismatch",
1132        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1133    ),
1134    d(
1135        "bynk.store.annotation_unsupported",
1136        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1137    ),
1138    d(
1139        "bynk.store.cache_needs_clock",
1140        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1141    ),
1142    d(
1143        "bynk.store.cache_ttl_required",
1144        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1145    ),
1146    d(
1147        "bynk.store.kind_arity",
1148        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1149    ),
1150    d(
1151        "bynk.store.kind_unsupported",
1152        "A known storage kind (`Queue`) is used before the slice that supports it.",
1153    ),
1154    d(
1155        "bynk.store.log_needs_clock",
1156        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1157    ),
1158    d(
1159        "bynk.store.unknown_annotation",
1160        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1161    ),
1162    d(
1163        "bynk.store.unknown_kind",
1164        "A `store` field's type is not a known storage kind.",
1165    ),
1166    d(
1167        "bynk.store.unknown_op",
1168        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1169    ),
1170    dg(
1171        "bynk.target.vendor_conflict",
1172        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
1173        &["consumes_decl"],
1174    ),
1175    dg(
1176        "bynk.target.vendor_required",
1177        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
1178        &["consumes_decl"],
1179    ),
1180    dg(
1181        "bynk.test.duplicate_case_name",
1182        "Two test cases share a description.",
1183        &["test_case"],
1184    ),
1185    dg(
1186        "bynk.test.unknown_target",
1187        "A `test` block targets a unit that does not exist.",
1188        &["test_decl"],
1189    ),
1190    d(
1191        "bynk.types.ambiguous_constructor",
1192        "`Ok`/`Err` is ambiguous between `Result` and `HttpResult`; qualify it.",
1193    ),
1194    dg(
1195        "bynk.types.argument_mismatch",
1196        "A function argument has the wrong type.",
1197        &["call"],
1198    ),
1199    dg(
1200        "bynk.types.call_arity",
1201        "A function value was applied with the wrong number of arguments.",
1202        &["call"],
1203    ),
1204    dg(
1205        "bynk.types.cannot_infer_option_type_param",
1206        "The value type of `None` could not be inferred.",
1207        &["none_expr"],
1208    ),
1209    d(
1210        "bynk.types.cannot_infer_result_type_params",
1211        "The type parameters of a `Result` could not be inferred.",
1212    ),
1213    d(
1214        "bynk.types.constructor_arity",
1215        "A variant constructor got the wrong number of arguments.",
1216    ),
1217    d(
1218        "bynk.types.constructor_base_mismatch",
1219        "A `.of` constructor was given an argument of the wrong base type.",
1220    ),
1221    dg(
1222        "bynk.types.duplicate_variant_arm",
1223        "A `match` has two arms for the same variant.",
1224        &["match_arm"],
1225    ),
1226    dg(
1227        "bynk.types.empty_refinement",
1228        "A refinement admits no values (contradictory predicates).",
1229        &["refinement"],
1230    ),
1231    dg(
1232        "bynk.types.err_value_mismatch",
1233        "An `Err` payload has the wrong type.",
1234        &["err_expr"],
1235    ),
1236    dg(
1237        "bynk.types.field_access_on_non_record",
1238        "Field access on a value that is not a record.",
1239        &["field_access"],
1240    ),
1241    dg(
1242        "bynk.types.field_refinement_not_base",
1243        "An inline field refinement requires a base or refined type.",
1244        &["record_field"],
1245    ),
1246    dg(
1247        "bynk.types.field_value_mismatch",
1248        "A record field was given a value of the wrong type.",
1249        &["record_construction"],
1250    ),
1251    dg(
1252        "bynk.types.function_at_boundary",
1253        "A function type appeared in a serialisable or boundary position (a record field, sum payload, service/agent handler signature, capability operation signature, agent state field, or agent key); functions cannot serialise or cross a boundary.",
1254        &["function_type_ref"],
1255    ),
1256    d(
1257        "bynk.types.held_at_boundary",
1258        "A held value (`Connection[F]`) appears in a serialisable or boundary position — a held resource is built and disposed in place, never persisted or sent across a boundary (§2.9, real-time track slice 2).",
1259    ),
1260    d(
1261        "bynk.types.held_not_comparable",
1262        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
1263    ),
1264    dg(
1265        "bynk.types.if_branch_mismatch",
1266        "The branches of an `if` have different types.",
1267        &["if_expr"],
1268    ),
1269    dg(
1270        "bynk.types.if_non_bool_cond",
1271        "An `if` condition is not a `Bool`.",
1272        &["if_expr"],
1273    ),
1274    d(
1275        "bynk.types.interpolation_non_scalar",
1276        "An interpolation hole holds a value with no string form.",
1277    ),
1278    dg(
1279        "bynk.types.invalid_regex",
1280        "A `Matches` predicate contains an invalid regular expression.",
1281        &["refinement"],
1282    ),
1283    dg(
1284        "bynk.types.inverted_range",
1285        "An `InRange` predicate has its bounds inverted.",
1286        &["refinement"],
1287    ),
1288    dg(
1289        "bynk.types.is_base_mismatch",
1290        "An `is` refinement check is applied to a value of the wrong base type.",
1291        &["is_expr"],
1292    ),
1293    dg(
1294        "bynk.types.is_non_sum",
1295        "`is` was applied to a value that is not a sum type.",
1296        &["is_expr"],
1297    ),
1298    dg(
1299        "bynk.types.is_unknown_variant",
1300        "`is` names a variant the type does not have.",
1301        &["is_expr"],
1302    ),
1303    dg(
1304        "bynk.types.json_uncodable",
1305        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
1306        &["method_call"],
1307    ),
1308    dg(
1309        "bynk.types.key_not_orderable",
1310        "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
1311        &[],
1312    ),
1313    dg(
1314        "bynk.types.lambda_mismatch",
1315        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
1316        &["lambda_expr"],
1317    ),
1318    dg(
1319        "bynk.types.let_annotation_mismatch",
1320        "A `let` value does not match its type annotation.",
1321        &["let_stmt"],
1322    ),
1323    dg(
1324        "bynk.types.list_element_mismatch",
1325        "A list-literal element has a different type from the list's element type.",
1326        &["list_literal"],
1327    ),
1328    dg(
1329        "bynk.types.match_arm_mismatch",
1330        "A `match` arm has a different type from the others.",
1331        &["match_arm"],
1332    ),
1333    dg(
1334        "bynk.types.match_non_sum_discriminant",
1335        "`match` was applied to a value that is not a sum type.",
1336        &["match_expr"],
1337    ),
1338    dg(
1339        "bynk.types.method_arity",
1340        "A method was called with the wrong number of arguments.",
1341        &["method_call"],
1342    ),
1343    dg(
1344        "bynk.types.method_not_found",
1345        "Called a method the type does not have.",
1346        &["method_call"],
1347    ),
1348    dg(
1349        "bynk.types.method_on_non_named_type",
1350        "A method was called on a built-in type that has no methods.",
1351        &["method_call"],
1352    ),
1353    dg(
1354        "bynk.types.mixed_pattern_bindings",
1355        "A pattern mixes named and positional bindings.",
1356        &["variant_pattern"],
1357    ),
1358    dg(
1359        "bynk.types.negative_length",
1360        "A length predicate was given a negative value.",
1361        &["refinement"],
1362    ),
1363    dg(
1364        "bynk.types.no_numeric_coercion",
1365        "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
1366        &["binary_expr", "refinement"],
1367    ),
1368    dg(
1369        "bynk.types.non_exhaustive_match",
1370        "A `match` does not cover every variant.",
1371        &["match_expr"],
1372    ),
1373    dg(
1374        "bynk.types.ok_value_mismatch",
1375        "An `Ok` payload has the wrong type.",
1376        &["ok_expr"],
1377    ),
1378    dg(
1379        "bynk.types.opaque_raw_outside",
1380        "`.raw` on an opaque type was used outside its defining commons.",
1381        &["field_access"],
1382    ),
1383    dg(
1384        "bynk.types.opaque_record_construction",
1385        "An opaque type was constructed with record syntax.",
1386        &["record_construction"],
1387    ),
1388    dg(
1389        "bynk.types.opaque_unsafe_outside",
1390        "`.unsafe` on an opaque type was used outside its defining context.",
1391        &["field_access"],
1392    ),
1393    dg(
1394        "bynk.types.pattern_arity",
1395        "A pattern binds the wrong number of payload fields.",
1396        &["variant_pattern"],
1397    ),
1398    dg(
1399        "bynk.types.pattern_type_mismatch",
1400        "A pattern's type does not match the matched value.",
1401        &["variant_pattern"],
1402    ),
1403    dg(
1404        "bynk.types.predicate_base_mismatch",
1405        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
1406        &["refinement"],
1407    ),
1408    d(
1409        "bynk.types.query_at_boundary",
1410        "A `Query` type appears in a storable or boundary-crossing position — a query is built and executed in place, never persisted or sent (ADR 0115).",
1411    ),
1412    dg(
1413        "bynk.types.question_error_mismatch",
1414        "`?` propagates an error type incompatible with the function's.",
1415        &["question_expr"],
1416    ),
1417    dg(
1418        "bynk.types.question_on_non_result",
1419        "`?` was applied to a non-`Result` value.",
1420        &["question_expr"],
1421    ),
1422    dg(
1423        "bynk.types.question_outside_result",
1424        "`?` used in a function that does not return a `Result`.",
1425        &["question_expr"],
1426    ),
1427    d(
1428        "bynk.types.return_mismatch",
1429        "A returned value does not match the declared return type.",
1430    ),
1431    dg(
1432        "bynk.types.some_value_mismatch",
1433        "A `Some` payload has the wrong type.",
1434        &["some_expr"],
1435    ),
1436    d(
1437        "bynk.types.stream_at_boundary",
1438        "A `Stream` type appears in a storable or boundary-crossing position — a stream is a live value-over-time source, never persisted or sent across a boundary (real-time track slice 0).",
1439    ),
1440    d(
1441        "bynk.types.stream_not_comparable",
1442        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
1443    ),
1444    d(
1445        "bynk.types.type_mismatch",
1446        "Two types that were required to match did not.",
1447    ),
1448    dg(
1449        "bynk.types.uninferable_element_type",
1450        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
1451        &["list_literal"],
1452    ),
1453    dg(
1454        "bynk.types.unkeyable_distinct",
1455        "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
1456        &[],
1457    ),
1458    dg(
1459        "bynk.types.unkeyable_map_key",
1460        "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
1461        &["generic_type_ref"],
1462    ),
1463    dg(
1464        "bynk.types.unknown_field",
1465        "Referenced a field the record type does not declare.",
1466        &["field_access"],
1467    ),
1468    dg(
1469        "bynk.types.unknown_pattern_field",
1470        "A pattern names a field the variant does not have.",
1471        &["variant_pattern"],
1472    ),
1473    dg(
1474        "bynk.types.unknown_static_member",
1475        "Referenced an unknown static member on a type.",
1476        &["field_access"],
1477    ),
1478    dg(
1479        "bynk.types.unknown_variant_in_pattern",
1480        "A pattern names a variant the sum type does not have.",
1481        &["variant_pattern"],
1482    ),
1483    dg(
1484        "bynk.types.unreachable_arm",
1485        "A `match` arm is unreachable.",
1486        &["match_arm"],
1487    ),
1488    d(
1489        "bynk.types.variant_arity",
1490        "A variant constructor got the wrong number of payload values.",
1491    ),
1492    d(
1493        "bynk.types.variant_missing_payload",
1494        "A variant requiring a payload was used without one.",
1495    ),
1496    d(
1497        "bynk.types.variant_payload_mismatch",
1498        "A variant payload has the wrong type.",
1499    ),
1500    dg(
1501        "bynk.uses.name_conflict",
1502        "A `uses` name collides with another name.",
1503        &["uses_decl"],
1504    ),
1505    dg(
1506        "bynk.uses.self_reference",
1507        "A commons `uses` itself.",
1508        &["uses_decl"],
1509    ),
1510    dg(
1511        "bynk.uses.target_is_context",
1512        "`uses` targets a context instead of a commons.",
1513        &["uses_decl"],
1514    ),
1515    dg(
1516        "bynk.uses.unknown_commons",
1517        "`uses` names a commons that does not exist.",
1518        &["uses_decl"],
1519    ),
1520    d(
1521        "bynk.ws.message_frame_param",
1522        "A WebSocket `on message` handler does not have exactly one parameter of the service's inbound (`in:`) frame type — the decoded frame (real-time track slice 3b-iii).",
1523    ),
1524    d(
1525        "bynk.ws.open_given_unsupported",
1526        "A WebSocket `on open` handler declares `given` capabilities — unsupported at v1, since on Workers the handler runs inside the connection-hosting Durable Object, which has no composition root to supply them (real-time track slice 3b).",
1527    ),
1528    d(
1529        "bynk.ws.open_transfer_shape",
1530        "A WebSocket `on open` handler does not transfer its `connection` into exactly one agent, so the Workers upgrade has no single Durable Object to route to (real-time track slice 3b).",
1531    ),
1532    d(
1533        "bynk.ws.route_param_mismatch",
1534        "A WebSocket `on message`/`on close` route parameter does not match the `on open` parameter at the same position — route values are recovered positionally from the connection, so they must be a type-compatible prefix of the `on open` parameters (real-time track slice 3b-iii).",
1535    ),
1536];
1537
1538/// A diagnostic with no single governing grammar construct.
1539const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
1540    DiagnosticInfo {
1541        code,
1542        summary,
1543        grammar_symbol: &[],
1544    }
1545}
1546
1547/// A diagnostic that constrains one or more grammar productions.
1548const fn dg(
1549    code: &'static str,
1550    summary: &'static str,
1551    grammar_symbol: &'static [&'static str],
1552) -> DiagnosticInfo {
1553    DiagnosticInfo {
1554        code,
1555        summary,
1556        grammar_symbol,
1557    }
1558}
1559
1560/// The category segment of a code (the part between the first two dots), e.g.
1561/// `"types"` for `"bynk.types.type_mismatch"`.
1562pub fn category(code: &str) -> &str {
1563    code.split('.').nth(1).unwrap_or("")
1564}
1565
1566/// A human-readable heading for a category segment.
1567fn category_title(cat: &str) -> &'static str {
1568    match cat {
1569        "agent" | "agents" => "Agents",
1570        "assert" => "Assertions",
1571        "boundary" => "Boundaries",
1572        "capability" => "Capabilities",
1573        "consumes" => "Consumes",
1574        "context" => "Contexts",
1575        "cron" => "Cron",
1576        "effect" => "Effects",
1577        "exports" => "Exports",
1578        "given" => "Given capabilities",
1579        "http" => "HTTP",
1580        "lex" => "Lexer",
1581        "mock" => "Mock and mocks",
1582        "parse" => "Parser",
1583        "project" => "Project",
1584        "provider" => "Providers",
1585        "queue" => "Queue",
1586        "record_spread" => "Record spread",
1587        "refine" => "Refinement",
1588        "resolve" => "Resolution",
1589        "service" => "Services",
1590        "test" => "Tests",
1591        "types" => "Type checking",
1592        "uses" => "Uses",
1593        _ => "Other",
1594    }
1595}
1596
1597/// Render the diagnostic index as a Markdown reference page, grouped by
1598/// category. This is the generator behind `docs/src/reference/diagnostics.md`.
1599pub fn render_markdown() -> String {
1600    use std::collections::BTreeMap;
1601
1602    // Group codes by their category title, preserving sorted code order.
1603    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
1604    for info in REGISTRY {
1605        by_category
1606            .entry(category_title(category(info.code)))
1607            .or_default()
1608            .push(info);
1609    }
1610
1611    let mut out = String::new();
1612    out.push_str("# Diagnostic index\n\n");
1613    out.push_str(
1614        "<!-- GENERATED FILE — do not edit by hand.\n     \
1615         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
1616         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
1617    );
1618    out.push_str(
1619        "Every diagnostic code the compiler can emit, with a one-line summary of \
1620         the cause, grouped by category. For step-by-step cause-and-fix guidance \
1621         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md).\n\n",
1622    );
1623    out.push_str(&format!(
1624        "There are **{}** codes in total.\n",
1625        REGISTRY.len()
1626    ));
1627
1628    for (title, infos) in &by_category {
1629        out.push_str(&format!("\n## {title}\n\n"));
1630        out.push_str("| Code | Summary | Construct |\n|---|---|---|\n");
1631        for info in infos {
1632            // The construct column deep-links each governing production to its
1633            // entry in the annotated grammar reference; generated from
1634            // `grammar_symbol` (each value is an embeddable rule, so the
1635            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
1636            let construct = info
1637                .grammar_symbol
1638                .iter()
1639                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
1640                .collect::<Vec<_>>()
1641                .join(", ");
1642            out.push_str(&format!(
1643                "| `{}` | {} | {} |\n",
1644                info.code, info.summary, construct
1645            ));
1646        }
1647    }
1648
1649    out
1650}
1651
1652/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
1653/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
1654/// at least one diagnostic appear. This is the generator behind
1655/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
1656/// preprocessor directive consumes.
1657pub fn render_grammar_semantics_json() -> String {
1658    use std::collections::BTreeMap;
1659
1660    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
1661    // the BTreeMap gives sorted rule names.
1662    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
1663    for info in REGISTRY {
1664        for sym in info.grammar_symbol {
1665            by_symbol.entry(sym).or_default().push(info);
1666        }
1667    }
1668
1669    let mut map = serde_json::Map::new();
1670    map.insert(
1671        "_generated".to_string(),
1672        serde_json::Value::String(
1673            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
1674             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
1675             bynkc --test diagnostics_registry"
1676                .to_string(),
1677        ),
1678    );
1679    for (sym, infos) in by_symbol {
1680        let arr: Vec<serde_json::Value> = infos
1681            .iter()
1682            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
1683            .collect();
1684        map.insert(sym.to_string(), serde_json::Value::Array(arr));
1685    }
1686
1687    let mut s =
1688        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
1689    s.push('\n');
1690    s
1691}