1use crate::error::Severity;
19
20pub struct DiagnosticInfo {
24 pub code: &'static str,
25 pub summary: &'static str,
26 pub grammar_symbol: &'static [&'static str],
34 pub severity: Severity,
42}
43
44pub const BOOK_BASE_URL: &str = "https://bynk-lang.org";
48
49pub struct Explain {
64 pub code: &'static str,
67 pub blurb: &'static str,
70 pub example: &'static str,
72 pub page: &'static str,
77 pub anchor: &'static str,
79}
80
81impl Explain {
82 pub fn href(&self) -> String {
85 let mut url = format!("{BOOK_BASE_URL}{}/", self.page);
86 if !self.anchor.is_empty() {
87 url.push('#');
88 url.push_str(self.anchor);
89 }
90 url
91 }
92
93 pub fn in_site_link(&self) -> String {
99 let mut link = format!("{}/", self.page);
100 if !self.anchor.is_empty() {
101 link.push('#');
102 link.push_str(self.anchor);
103 }
104 link
105 }
106}
107
108pub const EXPLANATIONS: &[Explain] = &[
113 Explain {
114 code: "bynk.given.undeclared_capability",
115 blurb: "A handler may only use a capability it has itself declared with \
116 `given`. Effects in Bynk are explicit: the `given` clause is the \
117 handler's honest, checkable statement of every capability it \
118 reaches for, so a reader (and the compiler) can see a handler's \
119 full reach from its signature alone. Using a capability that is \
120 not in `given` is the missing half of that contract.",
121 example: "on get \"/now\" -> Text { // ✗ uses Clock without declaring it\n \
122 Clock.now()\n}\n\n\
123 on get \"/now\" given Clock -> Text { // ✓ declared, then used\n \
124 Clock.now()\n}",
125 page: "/book/guides/effects-and-capabilities/understand-the-capability-model",
126 anchor: "",
127 },
128 Explain {
129 code: "bynk.given.unknown_capability",
130 blurb: "A `given` clause names a capability that no provider declares. A \
131 capability is a typed interface to the outside world; it has to be \
132 *declared* (as a `capability`, or brought in from a consumed \
133 context) before a handler can ask for it. This usually means a \
134 typo in the capability name, or a missing `uses`/`consumes` that \
135 would bring the capability into scope.",
136 example: "on get \"/\" given Clok -> Text { … } // ✗ no capability named `Clok`\n\n\
137 on get \"/\" given Clock -> Text { … } // ✓ matches the declared capability",
138 page: "/book/reference/capabilities",
139 anchor: "declaring-a-capability",
140 },
141 Explain {
142 code: "bynk.resolve.missing_field",
143 blurb: "A record must be constructed with every one of its fields. Bynk \
144 records have no defaults and no partial construction: a value of a \
145 record type is only valid once all its fields are present, so a \
146 downstream reader never has to wonder whether a field was set. \
147 Omitting a field is therefore an error, not a fill-in-later.",
148 example: "type User = { name: Text, age: Int }\n\n\
149 User { name: \"Ada\" } // ✗ missing `age`\n\
150 User { name: \"Ada\", age: 36 } // ✓ every field present",
151 page: "/book/reference/types",
152 anchor: "record-types",
153 },
154 Explain {
155 code: "bynk.resolve.unknown_field",
156 blurb: "A field access names a field the record type does not have. A \
157 record's fields are fixed by its type declaration; only those \
158 names exist on the value. This is usually a typo in the field \
159 name, or an access meant for a different type.",
160 example: "type User = { name: Text }\n\n\
161 user.nmae // ✗ no field `nmae`\n\
162 user.name // ✓ the declared field",
163 page: "/book/reference/types",
164 anchor: "record-types",
165 },
166 Explain {
167 code: "bynk.resolve.unknown_name",
168 blurb: "A name was referenced that is not in scope. Every name in Bynk \
169 must be introduced before use — as a `let` binding, a parameter, \
170 a `fn`, a type, or a member brought in through `uses`/`consumes`. \
171 An unknown name is typically a typo, a missing declaration, or a \
172 reference to something defined in a module that has not been \
173 brought into scope.",
174 example: "let greeting = \"hi\"\n\
175 greetng // ✗ no name `greetng` in scope\n\
176 greeting // ✓ the bound name",
177 page: "/book/guides/program-structure/how-a-program-is-shaped",
178 anchor: "",
179 },
180 Explain {
181 code: "bynk.resolve.unknown_type",
182 blurb: "A type name was referenced that does not exist. Types must be \
183 declared (with `type`), be one of Bynk's built-in types, or be \
184 brought into scope from another module before they can be named. \
185 An unknown type is usually a typo or a missing declaration/import.",
186 example: "fn greet(u: Usr) -> Text { … } // ✗ no type `Usr`\n\
187 fn greet(u: User) -> Text { … } // ✓ the declared type",
188 page: "/book/reference/types",
189 anchor: "",
190 },
191];
192
193pub fn explain(code: &str) -> Option<&'static Explain> {
196 EXPLANATIONS.iter().find(|e| e.code == code)
197}
198
199pub fn lookup(code: &str) -> Option<&'static DiagnosticInfo> {
203 REGISTRY.iter().find(|d| d.code == code)
204}
205
206pub const REGISTRY: &[DiagnosticInfo] = &[
208 d(
209 "bynk.actor.bearer_identity_not_string_constructible",
210 "A `Bearer` actor's identity is not a string-constructible type.",
211 ),
212 d(
213 "bynk.actor.bearer_missing_secret",
214 "A `Bearer` actor does not name its signing secret.",
215 ),
216 d(
217 "bynk.actor.binder_shadows_param",
218 "A `by` actor binder collides with a handler parameter of the same name.",
219 ),
220 d(
221 "bynk.actor.by_on_agent",
222 "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
223 ),
224 d(
225 "bynk.actor.duplicate_sum_scheme",
226 "Two peers in a multi-actor sum share an authentication scheme.",
227 ),
228 d(
229 "bynk.actor.identity_not_sealed",
230 "An actor identity type is not a context-ownable (sealed) value type.",
231 ),
232 d(
233 "bynk.actor.missing_by_on_http",
234 "An HTTP handler lacks the required `by` actor clause.",
235 ),
236 d(
237 "bynk.actor.oidc_identity_not_string_constructible",
238 "An `Oidc` actor's identity is not a string-constructible type.",
239 ),
240 d(
241 "bynk.actor.oidc_missing_audience",
242 "An `Oidc` actor does not name its `audience`.",
243 ),
244 d(
245 "bynk.actor.oidc_missing_issuer",
246 "An `Oidc` actor does not name its `issuer`.",
247 ),
248 d(
249 "bynk.actor.oidc_missing_jwks",
250 "An `Oidc` actor does not name its `jwks` endpoint.",
251 ),
252 d(
253 "bynk.actor.oidc_not_in_sum",
254 "An `Oidc` actor appears as a member of a multi-actor sum.",
255 ),
256 d(
257 "bynk.actor.outside_context",
258 "An `actor` was declared outside a context (e.g. in a commons).",
259 ),
260 d(
261 "bynk.actor.refinement_base_unsupported",
262 "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
263 ),
264 d(
265 "bynk.actor.refinement_in_sum",
266 "A refinement actor appears as a member of a multi-actor sum.",
267 ),
268 d(
269 "bynk.actor.refinement_predicate_unsupported",
270 "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
271 ),
272 d(
273 "bynk.actor.scheme_not_admissible",
274 "An actor's scheme is not admissible on this handler's protocol.",
275 ),
276 d(
277 "bynk.actor.signature_identity_unsupported",
278 "A `Signature` actor declared an `identity`, which is not yet supported.",
279 ),
280 d(
281 "bynk.actor.signature_missing_header",
282 "A `Signature` actor does not name its signature header.",
283 ),
284 d(
285 "bynk.actor.signature_missing_secret",
286 "A `Signature` actor does not name its signing secret.",
287 ),
288 d(
289 "bynk.actor.signature_requires_body",
290 "A `Signature` handler does not take a `body` parameter.",
291 ),
292 d(
293 "bynk.actor.signature_tolerance_without_timestamp",
294 "A `Signature` actor set `tolerance` without a `timestamp` header.",
295 ),
296 d(
297 "bynk.actor.sum_requires_binder",
298 "A multi-actor sum `by` clause has no binder to match the resolved actor.",
299 ),
300 d(
301 "bynk.actor.unknown_actor",
302 "A handler's `by` clause names an actor that is not declared.",
303 ),
304 d(
305 "bynk.actor.unknown_scheme",
306 "An actor declares an authentication scheme that is not compiler-known.",
307 ),
308 d(
309 "bynk.actor.unreachable_sum_arm",
310 "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
311 ),
312 dg(
313 "bynk.adapter.consumes_context",
314 "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
315 &["consumes_decl"],
316 ),
317 dg(
318 "bynk.adapter.consumes_requires_selection",
319 "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
320 &["consumes_decl"],
321 ),
322 dg(
323 "bynk.adapter.disallowed_item",
324 "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
325 &["adapter_decl"],
326 ),
327 dg(
328 "bynk.adapter.duplicate_binding",
329 "An `adapter` declared more than one `binding` clause.",
330 &["binding_decl"],
331 ),
332 dg(
333 "bynk.adapter.no_binding",
334 "An `adapter` declares an external provider but no `binding` module to supply it.",
335 &["adapter_decl"],
336 ),
337 dg(
338 "bynk.adapter.provider_has_body",
339 "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
340 &["provider_decl"],
341 ),
342 dg(
343 "bynk.agent.construction_arity",
344 "An agent was constructed with the wrong number of key arguments.",
345 &["agent_decl"],
346 ),
347 dg(
348 "bynk.agent.handler_arity",
349 "An agent handler was called with the wrong number of arguments.",
350 &["agent_decl"],
351 ),
352 dg(
353 "bynk.agent.handler_not_found",
354 "Called a handler the agent does not declare.",
355 &["agent_decl"],
356 ),
357 dg(
358 "bynk.agent.key_mismatch",
359 "An agent key argument has the wrong type.",
360 &["agent_decl"],
361 ),
362 dg(
363 "bynk.agent.outside_context",
364 "An `agent` was declared outside a context.",
365 &["agent_decl"],
366 ),
367 dg(
368 "bynk.agent.return_not_effect",
369 "An agent handler's return type is not an `Effect`.",
370 &["agent_decl"],
371 ),
372 dg(
373 "bynk.agents.bad_state_initialiser",
374 "An agent `store` field initialiser is not a static value of the field's type.",
375 &["store_field"],
376 ),
377 dg(
378 "bynk.agents.non_zeroable_state_field",
379 "An agent `store` field has no initialiser and no implicit zero value.",
380 &["store_field"],
381 ),
382 d(
383 "bynk.boundary.structural_mismatch",
384 "Data crossing a context boundary did not match the expected shape.",
385 ),
386 dg(
387 "bynk.capability.op_arity",
388 "A capability operation was called with the wrong number of arguments.",
389 &["capability_decl"],
390 ),
391 dg(
392 "bynk.capability.outside_context",
393 "A `capability` was declared outside a context.",
394 &["capability_decl"],
395 ),
396 dg(
397 "bynk.capability.unknown_operation",
398 "Referenced an operation the capability does not declare.",
399 &["capability_decl"],
400 ),
401 d(
402 "bynk.cell.invalid_target",
403 "A `:=` write targets something that is not a `store Cell` field.",
404 ),
405 d(
406 "bynk.cell.self_reference",
407 "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
408 ),
409 dg(
410 "bynk.consumes.alias_conflict",
411 "Two `consumes` aliases collide.",
412 &["consumes_decl"],
413 ),
414 dg(
415 "bynk.consumes.capability_name_clash",
416 "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
417 &["consumes_decl"],
418 ),
419 dg(
420 "bynk.consumes.in_commons",
421 "`consumes` appears in a `commons` (it is only valid in a context).",
422 &["consumes_decl"],
423 ),
424 dg(
425 "bynk.consumes.name_conflict",
426 "A `consumes` name collides with another name in scope.",
427 &["consumes_decl"],
428 ),
429 dg(
430 "bynk.consumes.self_reference",
431 "A context `consumes` itself.",
432 &["consumes_decl"],
433 ),
434 dg(
435 "bynk.consumes.service_arity",
436 "A consumed service was called with the wrong number of arguments.",
437 &["consumes_decl"],
438 ),
439 dg(
440 "bynk.consumes.target_is_commons",
441 "`consumes` targets a `commons` instead of a context.",
442 &["consumes_decl"],
443 ),
444 dg(
445 "bynk.consumes.unknown_context",
446 "`consumes` names a context that does not exist.",
447 &["consumes_decl"],
448 ),
449 dg(
450 "bynk.consumes.unknown_service",
451 "Called a service the consumed context does not declare.",
452 &["consumes_decl"],
453 ),
454 d(
455 "bynk.context.consumes_cycle",
456 "Contexts form a `consumes` dependency cycle.",
457 ),
458 d(
459 "bynk.context.external_construction",
460 "A context-owned type was constructed from outside that context.",
461 ),
462 dg(
463 "bynk.context.external_provider",
464 "A bodiless (external) provider was declared outside an `adapter`.",
465 &["provider_decl"],
466 ),
467 d(
468 "bynk.context.opaque_inspection",
469 "An opaquely-exported type was inspected from outside its context.",
470 ),
471 d(
472 "bynk.context.rebrand_construction",
473 "A `uses`-sourced commons record or sum type was constructed directly inside a context, where the emitter's per-context rebrand leaves its constructors out of scope.",
474 ),
475 d(
476 "bynk.contract.duplicate_name",
477 "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
478 ),
479 d(
480 "bynk.contract.impure_predicate",
481 "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
482 ),
483 d(
484 "bynk.contract.not_bool",
485 "A contract predicate does not have type `Bool`.",
486 ),
487 d(
488 "bynk.contract.restated_by_test",
489 "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
490 ),
491 d(
492 "bynk.contract.result_in_requires",
493 "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
494 ),
495 dg(
496 "bynk.cron.bad_params",
497 "A cron handler declares more than one parameter, or a non-`Int` one.",
498 &["cron_handler"],
499 ),
500 dg(
501 "bynk.cron.duplicate_schedule",
502 "Two cron handlers declare the same schedule.",
503 &["cron_handler"],
504 ),
505 dg(
506 "bynk.cron.invalid_schedule",
507 "A cron expression is not five whitespace-separated fields.",
508 &["cron_handler"],
509 ),
510 dg(
511 "bynk.cron.return_not_effect_result",
512 "A cron handler does not return `Effect[Result[(), E]]`.",
513 &["cron_handler"],
514 ),
515 d(
516 "bynk.duration.literal_overflow",
517 "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
518 ),
519 dg(
520 "bynk.effect.bind_in_pure_context",
521 "An `<-` bind was used in a pure (non-effectful) context.",
522 &["effect_let_stmt"],
523 ),
524 dg(
525 "bynk.effect.bind_on_non_effect",
526 "An `<-` bind was applied to a non-`Effect` value.",
527 &["effect_let_stmt"],
528 ),
529 d(
530 "bynk.effect.capability_in_pure_context",
531 "A capability was used in a pure context.",
532 ),
533 d(
534 "bynk.effect.cross_context_in_pure_context",
535 "A cross-context call was made in a pure context.",
536 ),
537 dg(
538 "bynk.effect.do_in_pure_context",
539 "A `do` statement was used in a pure (non-effectful) context.",
540 &["do_stmt"],
541 ),
542 dg(
543 "bynk.effect.do_on_non_effect",
544 "A `do` statement was applied to a non-`Effect` value.",
545 &["do_stmt"],
546 ),
547 dg(
548 "bynk.effect.do_requires_unit",
549 "A `do` statement was applied to a valued `Effect[T]`; `do` performs a unit effect, so a real result would be dropped — use `let _ <- e` instead.",
550 &["do_stmt"],
551 ),
552 dg(
553 "bynk.effect.fn_value_in_pure_context",
554 "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
555 &["call"],
556 ),
557 d(
558 "bynk.event.bad_field_default",
559 "An event field's default expression (`field: T = expr`) is not a static, wire-representable value of the field's declared type — a literal (including one admitted to a refined type), a sum variant, `Some`/`None`/`Ok`/`Err`, a record, or `T.unsafe(lit)` for an opaque type whose literal also satisfies the refinement.",
560 ),
561 d(
562 "bynk.event.bad_params",
563 "An `on event` handler declared the wrong number of parameters, or a second parameter whose type is not `EventEnvelope` — it takes the event payload and, optionally, the runtime envelope.",
564 ),
565 d(
566 "bynk.event.bad_schema_version",
567 "An event's `@schema(N)` annotation is malformed — `N` must be a single, positive, positional `Int` literal, and `@schema` may appear at most once on an event.",
568 ),
569 d(
570 "bynk.event.default_outside_event",
571 "A field default (`field: T = expr`) was written on a record field outside an `event` declaration — a default is only meaningful on an event's own field, since it exists to let an older wire event missing this key still deserialise.",
572 ),
573 d(
574 "bynk.event.emit_not_an_event",
575 "`Events.emit[E]` named a type `E` that is declared in this context, but is not itself an `event` — only an `event` type may be emitted.",
576 ),
577 d(
578 "bynk.event.emit_outside_owner",
579 "`Events.emit[E]` named an event `E` not declared in the emitting context — only an event's declaring context may emit it.",
580 ),
581 d(
582 "bynk.event.handler_param_type_mismatch",
583 "An `on event(e: T)` handler's declared parameter type does not match its `from Events(E)` header's event type.",
584 ),
585 d(
586 "bynk.event.non_additive_schema_change",
587 "An event's field shape changed in a way the schema registry cannot evolve additively — a field was removed, retyped, added without a default, or lost a default it previously had. Give the new shape a new event type name, or make the change additive.",
588 ),
589 d(
590 "bynk.event.outside_context",
591 "An `event` was declared outside a context.",
592 ),
593 d(
594 "bynk.event.pattern_duplicate_field",
595 "A `from Events(E { ... })` subscription pattern listed the same field more than once.",
596 ),
597 d(
598 "bynk.event.pattern_type_mismatch",
599 "A `from Events(E { ... })` subscription pattern field's matched value is not compatible with that field's declared type.",
600 ),
601 d(
602 "bynk.event.pattern_unknown_field",
603 "A `from Events(E { ... })` subscription pattern named a field that `E` does not declare.",
604 ),
605 d(
606 "bynk.event.pattern_unknown_variant",
607 "A `from Events(E { ... })` subscription pattern's variant value names a variant that does not exist on the field's declared sum type.",
608 ),
609 d(
610 "bynk.event.pattern_variant_payload",
611 "A `from Events(E { ... })` subscription pattern's variant value names a variant that carries a payload — only nullary variants are admitted, since testing the tag alone would silently ignore the payload.",
612 ),
613 d(
614 "bynk.event.schema_version_mismatch",
615 "An event's `@schema(N)` annotation disagrees with the version the schema registry computes from the event's build history.",
616 ),
617 d(
618 "bynk.event.unknown_annotation",
619 "An `event` declaration carried an `@`-annotation other than `@schema` — event annotations are a closed set.",
620 ),
621 d(
622 "bynk.event.unknown_subscription",
623 "A `from Events(E)` subscription named `E`, which is not a declared event in this context or any consumed context.",
624 ),
625 dg(
626 "bynk.expect.not_bool",
627 "`expect` was given a non-`Bool` predicate.",
628 &["expect_expr"],
629 ),
630 dg(
631 "bynk.expect.outside_case",
632 "`expect` was used outside a `case` body.",
633 &["expect_expr"],
634 ),
635 dg(
636 "bynk.exports.capability_not_provided",
637 "An exported capability has no provider in its context.",
638 &["exports_decl"],
639 ),
640 dg(
641 "bynk.exports.conflicting_visibility",
642 "A type is exported with conflicting visibilities.",
643 &["exports_decl"],
644 ),
645 dg(
646 "bynk.exports.duplicate_export",
647 "The same name is exported more than once.",
648 &["exports_decl"],
649 ),
650 dg(
651 "bynk.exports.duplicate_in_clause",
652 "A name appears twice in one `exports` clause.",
653 &["exports_decl"],
654 ),
655 dg(
656 "bynk.exports.undeclared_capability",
657 "`exports capability` names a capability that is not declared.",
658 &["exports_decl"],
659 ),
660 dg(
661 "bynk.exports.undeclared_type",
662 "`exports` names a type that is not declared.",
663 &["exports_decl"],
664 ),
665 dg(
666 "bynk.generics.duplicate_type_param",
667 "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
668 &[],
669 ),
670 dg(
671 "bynk.generics.generic_non_record",
672 "A `type` declaration carries type parameters on a refined or opaque body; only a record (`type Name[T] = { … }`) or sum (`type Name[T] = | … | …`) body may be generic (v0.157/#593, ADRs 0183/0197).",
673 &["type_decl"],
674 ),
675 dg(
676 "bynk.generics.generic_record_at_boundary",
677 "A `Val[…]` fabricates a value of a generic type; per-instantiation value fabrication is not yet wired (ADR 0197). Since v0.174 a generic-record instantiation may otherwise cross a boundary through its monomorphised codec.",
678 &[],
679 ),
680 dg(
681 "bynk.generics.generic_sum_embeds",
682 "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
683 &["type_decl"],
684 ),
685 dg(
686 "bynk.generics.method_on_generic_type",
687 "A *static* method is attached to a generic type; static methods on generic types are deferred (they have no receiver to supply the type's parameters). Instance methods on generic types are supported (#594).",
688 &["fn_decl"],
689 ),
690 dg(
691 "bynk.generics.no_bounds",
692 "A type parameter carries a bound (`[A: …]`); bounded generics are not in v0.20a.",
693 &["fn_decl"],
694 ),
695 dg(
696 "bynk.generics.recursive_generic_at_boundary",
697 "A recursive generic record (one that transitively contains itself, through any wrapper or generic argument) appears at a boundary; it has no finite set of monomorphised codecs, so it is not yet boundary-serialisable (ADR 0197).",
698 &[],
699 ),
700 dg(
701 "bynk.generics.type_arg_count",
702 "A user-declared generic type is applied to the wrong number of type arguments, or a generic type is named without its `[…]` arguments (v0.157, ADR 0183).",
703 &["applied_type_ref"],
704 ),
705 dg(
706 "bynk.generics.type_arg_mismatch",
707 "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
708 &["call"],
709 ),
710 dg(
711 "bynk.generics.uninferable_type_arg",
712 "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.",
713 &["call"],
714 ),
715 dg(
716 "bynk.given.cross_context_unknown_capability",
717 "`given B.Cap` names a capability the consumed context does not export.",
718 &["given_clause"],
719 ),
720 dg(
721 "bynk.given.undeclared_capability",
722 "A handler uses a capability it did not declare with `given`.",
723 &["given_clause"],
724 ),
725 dg(
726 "bynk.given.unknown_capability",
727 "`given` names a capability that does not exist.",
728 &["given_clause"],
729 ),
730 warn(dg(
731 "bynk.given.unused_capability",
732 "A `given` capability is never used (warning).",
733 &["given_clause"],
734 )),
735 d(
736 "bynk.held.branch_divergence",
737 "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).",
738 ),
739 d(
740 "bynk.held.consume_on_borrow",
741 "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).",
742 ),
743 d(
744 "bynk.held.leak",
745 "A held value (`Connection[F]`) is still owned at scope exit — it must be disposed (stored, closed, or transferred) before the handler or function returns (§2.9.1, real-time track slice 2).",
746 ),
747 d(
748 "bynk.held.query_accessor_on_held_map",
749 "A key-aware query accessor (`.entries`/`.keys`/`.values`) is used on a held `Map[K, Connection]` — a held resource is iterated with the broadcast ops (`forEach`/`parTraverse`), not a key query.",
750 ),
751 d(
752 "bynk.held.unsupported_map_op",
753 "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).",
754 ),
755 d(
756 "bynk.held.unsupported_storage",
757 "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).",
758 ),
759 d(
760 "bynk.held.use_after_consume",
761 "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).",
762 ),
763 d(
764 "bynk.history.not_an_agent",
765 "A `for all run: History[T]` names a `T` that is not an agent — only an agent has handlers to sequence and reachable states to observe (testing track slice 7, ADR 0155).",
766 ),
767 d(
768 "bynk.history.not_generable",
769 "A `for all run: History[Agent]` targets an agent with a handler parameter whose type cannot be generated (e.g. a `Matches` refinement), so its call-history cannot be driven (testing track slice 7, ADR 0155).",
770 ),
771 d(
772 "bynk.history.outside_property",
773 "`History[Agent]` appears outside a `property`'s `for all` binding — it is a test-only generator, not a value type (testing track slice 7, ADR 0155).",
774 ),
775 d(
776 "bynk.history.restates_invariant",
777 "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
778 ),
779 dg(
780 "bynk.http.body_on_get_or_delete",
781 "A GET or DELETE handler declares a `body` parameter.",
782 &["http_handler"],
783 ),
784 d(
785 "bynk.http.cache_bad_max_age",
786 "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
787 ),
788 d(
789 "bynk.http.cache_bad_scope",
790 "A `@cache` annotation's `scope` is not `public` or `private`.",
791 ),
792 d(
793 "bynk.http.cache_duplicate",
794 "A handler carries more than one `@cache` annotation.",
795 ),
796 d(
797 "bynk.http.cache_on_non_get",
798 "A `@cache` annotation is placed on a handler that is not `on http GET`.",
799 ),
800 d(
801 "bynk.http.cache_unknown_arg",
802 "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`).",
803 ),
804 d(
805 "bynk.http.cors_invalid_field",
806 "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
807 ),
808 d(
809 "bynk.http.cors_invalid_origins",
810 "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
811 ),
812 d(
813 "bynk.http.cors_not_http",
814 "A `cors { }` policy appears on a service that is not `from http`.",
815 ),
816 d(
817 "bynk.http.cors_unknown_field",
818 "A `cors { }` policy declares a field outside the closed set.",
819 ),
820 d(
821 "bynk.http.cors_wildcard_credentials",
822 "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
823 ),
824 dg(
825 "bynk.http.duplicate_route",
826 "Two handlers share the same method and route.",
827 &["http_handler"],
828 ),
829 dg(
830 "bynk.http.extra_param",
831 "A handler parameter is neither a path parameter nor `body`.",
832 &["http_handler"],
833 ),
834 dg(
835 "bynk.http.invalid_path",
836 "An HTTP route path is malformed.",
837 &["http_handler"],
838 ),
839 d(
840 "bynk.http.limit_bad_max_body",
841 "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
842 ),
843 d(
844 "bynk.http.limit_duplicate",
845 "A handler carries more than one `@limit` annotation.",
846 ),
847 d(
848 "bynk.http.limit_on_bodyless",
849 "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
850 ),
851 d(
852 "bynk.http.limit_unknown_arg",
853 "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
854 ),
855 d(
856 "bynk.http.limits_invalid_field",
857 "A `limits` policy field (`maxBody`) has the wrong value shape.",
858 ),
859 d(
860 "bynk.http.limits_not_http",
861 "A `limits { }` policy appears on a service that is not `from http`.",
862 ),
863 d(
864 "bynk.http.limits_unknown_field",
865 "A `limits { }` policy declares a field outside the closed set.",
866 ),
867 dg(
868 "bynk.http.path_param_not_stringy",
869 "A path parameter's type is not constructible from a string.",
870 &["http_handler"],
871 ),
872 dg(
873 "bynk.http.reserved_prefix",
874 "A route uses the reserved `/_bynk/` prefix.",
875 &["http_handler"],
876 ),
877 dg(
878 "bynk.http.return_not_effect_http_result",
879 "An HTTP handler does not return `Effect[HttpResult[T]]`.",
880 &["http_handler"],
881 ),
882 d(
883 "bynk.http.security_invalid_field",
884 "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
885 ),
886 d(
887 "bynk.http.security_not_http",
888 "A `security { }` policy appears on a service that is not `from http`.",
889 ),
890 d(
891 "bynk.http.security_unknown_field",
892 "A `security { }` policy declares a field outside the closed set.",
893 ),
894 dg(
895 "bynk.http.unbound_path_param",
896 "A `:name` route segment has no matching handler parameter.",
897 &["http_handler"],
898 ),
899 d(
900 "bynk.http.unknown_handler_annotation",
901 "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
902 ),
903 d(
904 "bynk.index.bad_argument",
905 "An `@indexed` argument is not a `by: <field>` label.",
906 ),
907 warn(d(
908 "bynk.index.missing",
909 "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
910 )),
911 d(
912 "bynk.index.unkeyable_key",
913 "An `@indexed(by: k)` field is not value-keyable.",
914 ),
915 d(
916 "bynk.index.unknown_key",
917 "An `@indexed(by: k)` field is not a field of the map's value type.",
918 ),
919 warn(d(
920 "bynk.index.unused",
921 "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
922 )),
923 d(
924 "bynk.invariant.cross_agent_reference",
925 "An invariant predicate references another agent; invariants are per-agent.",
926 ),
927 d(
928 "bynk.invariant.duplicate_name",
929 "An agent declares two invariants with the same name.",
930 ),
931 d(
932 "bynk.invariant.impure_predicate",
933 "An invariant predicate uses an effectful or test-only construct.",
934 ),
935 d(
936 "bynk.invariant.not_bool",
937 "An invariant predicate does not have type `Bool`.",
938 ),
939 dg(
940 "bynk.lambda.unannotated_param",
941 "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
942 &["lambda_expr"],
943 ),
944 dg(
945 "bynk.lex.bad_escape",
946 "An invalid escape sequence in a string literal.",
947 &["string_literal"],
948 ),
949 dg(
950 "bynk.lex.float_literal_overflow",
951 "A float literal does not fit a finite 64-bit float.",
952 &["float_literal"],
953 ),
954 dg(
955 "bynk.lex.integer_overflow",
956 "An integer literal is out of range.",
957 &["number_literal"],
958 ),
959 dg(
960 "bynk.lex.interpolation_too_deep",
961 "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
962 &["string_literal"],
963 ),
964 d(
965 "bynk.lex.unclosed_doc_block",
966 "A documentation block is not closed.",
967 ),
968 d(
969 "bynk.lex.unexpected_character",
970 "An unexpected character in the source.",
971 ),
972 dg(
973 "bynk.lex.unterminated_interpolation",
974 "An interpolation hole `\\(…)` is not closed on its line.",
975 &["string_literal"],
976 ),
977 dg(
978 "bynk.lex.unterminated_string",
979 "A string literal is not terminated.",
980 &["string_literal"],
981 ),
982 warn(d(
983 "bynk.list.deprecated_function",
984 "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
985 )),
986 d(
987 "bynk.locale.multiple_message_bundles",
988 "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
989 ),
990 d(
991 "bynk.messages.format_mismatch",
992 "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
993 ),
994 d(
995 "bynk.messages.incomplete",
996 "A locale is missing a code the reference locale declares.",
997 ),
998 d(
999 "bynk.messages.invalid_locale_tag",
1000 "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
1001 ),
1002 d(
1003 "bynk.messages.malformed_icu_syntax",
1004 "A message template's ICU placeholder syntax is invalid — unbalanced arm braces, an unknown format keyword, `#` outside a plural arm, a missing mandatory `other` arm, or an explicitly out-of-scope construct (`selectordinal`, `offset:`/`=N`, a CLDR skeleton).",
1005 ),
1006 d(
1007 "bynk.messages.missing_locale_dependency",
1008 "A commons declaring `messages` doesn't `uses bynk.locale` and/or `uses bynk.locale.types`, which its generated `render` and the types its signature names need.",
1009 ),
1010 d(
1011 "bynk.messages.missing_reference",
1012 "A message bundle has no `@reference` block.",
1013 ),
1014 d(
1015 "bynk.messages.multiple_reference",
1016 "A message bundle has more than one `@reference` block.",
1017 ),
1018 d(
1019 "bynk.messages.outside_commons",
1020 "A `messages` declaration appears outside a commons.",
1021 ),
1022 d(
1023 "bynk.messages.placeholder_mismatch",
1024 "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
1025 ),
1026 d(
1027 "bynk.namespace.reserved",
1028 "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
1029 ),
1030 d(
1031 "bynk.observe.bad_count",
1032 "An observation call count is not a non-negative integer literal (`called once` / `called <n> times`).",
1033 ),
1034 d(
1035 "bynk.observe.impure_with",
1036 "A `with` predicate uses an effectful or test-only construct; it must be pure.",
1037 ),
1038 d(
1039 "bynk.observe.not_a_seam",
1040 "An observation targets a capability the unit under test does not consume.",
1041 ),
1042 d(
1043 "bynk.observe.outside_case",
1044 "An observation appears outside a `case` body.",
1045 ),
1046 d(
1047 "bynk.observe.trace_outside_test",
1048 "`trace(Cap.op)` appears outside a `case` body.",
1049 ),
1050 d(
1051 "bynk.observe.unknown_op",
1052 "An observation names an operation the capability does not declare.",
1053 ),
1054 d(
1055 "bynk.observe.with_not_bool",
1056 "A `with` predicate does not have type `Bool`.",
1057 ),
1058 dg(
1059 "bynk.parse.consumes_after_decls",
1060 "`consumes` appears after other declarations.",
1061 &["consumes_decl"],
1062 ),
1063 d(
1064 "bynk.parse.dangling_handler_annotation",
1065 "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
1066 ),
1067 dg(
1068 "bynk.parse.duplicate_cors",
1069 "A service declares more than one `cors { }` policy.",
1070 &["service_decl"],
1071 ),
1072 dg(
1073 "bynk.parse.duplicate_limits",
1074 "A service declares more than one `limits { }` policy.",
1075 &["service_decl"],
1076 ),
1077 dg(
1078 "bynk.parse.duplicate_security",
1079 "A service declares more than one `security { }` policy.",
1080 &["service_decl"],
1081 ),
1082 dg(
1083 "bynk.parse.empty_agent",
1084 "An `agent` body is empty.",
1085 &["agent_decl"],
1086 ),
1087 dg(
1088 "bynk.parse.empty_capability",
1089 "A `capability` body is empty.",
1090 &["capability_decl"],
1091 ),
1092 d(
1093 "bynk.parse.empty_interpolation",
1094 "An interpolation hole `\\(…)` contains no expression.",
1095 ),
1096 dg(
1097 "bynk.parse.empty_match",
1098 "A `match` has no arms.",
1099 &["match_expr"],
1100 ),
1101 dg(
1102 "bynk.parse.empty_service",
1103 "A `service` body is empty.",
1104 &["service_decl"],
1105 ),
1106 d(
1107 "bynk.parse.event_pattern_empty",
1108 "A `from Events(E { ... })` subscription pattern listed no fields — use `from Events(E)` (no braces) for an unfiltered subscription.",
1109 ),
1110 dg(
1111 "bynk.parse.expected_agent_key",
1112 "Expected a `key` declaration in an agent.",
1113 &["agent_decl"],
1114 ),
1115 d(
1116 "bynk.parse.expected_agent_storage",
1117 "An agent declares no storage — it has no `store` fields.",
1118 ),
1119 dg(
1120 "bynk.parse.expected_base_type",
1121 "Expected a base type.",
1122 &["base_type"],
1123 ),
1124 dg(
1125 "bynk.parse.expected_capability_op",
1126 "Expected a capability operation.",
1127 &["capability_op"],
1128 ),
1129 d("bynk.parse.expected_expression", "Expected an expression."),
1130 dg(
1131 "bynk.parse.expected_handler",
1132 "Expected a handler.",
1133 &["handler"],
1134 ),
1135 d("bynk.parse.expected_item", "Expected a declaration."),
1136 dg(
1137 "bynk.parse.expected_predicate",
1138 "Expected a refinement predicate.",
1139 &["refinement"],
1140 ),
1141 dg(
1142 "bynk.parse.expected_provider_op",
1143 "Expected a provider operation.",
1144 &["provider_op"],
1145 ),
1146 d("bynk.parse.expected_token", "Expected a specific token."),
1147 d("bynk.parse.expected_type", "Expected a type."),
1148 d(
1149 "bynk.parse.expected_unit_header",
1150 "Expected a `commons` or `context` header.",
1151 ),
1152 dg(
1153 "bynk.parse.expected_visibility",
1154 "Expected a visibility keyword.",
1155 &["exports_decl"],
1156 ),
1157 dg(
1158 "bynk.parse.exports_after_decls",
1159 "`exports` appears after other declarations.",
1160 &["exports_decl"],
1161 ),
1162 d(
1163 "bynk.parse.extra_tokens",
1164 "Unexpected tokens after an otherwise complete construct.",
1165 ),
1166 dg(
1167 "bynk.parse.generic_arg_count",
1168 "Wrong number of generic type arguments.",
1169 &["generic_type_ref"],
1170 ),
1171 dg(
1172 "bynk.parse.handler_in_agent",
1173 "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
1174 &["handler"],
1175 ),
1176 d(
1177 "bynk.parse.invariant_after_handler",
1178 "An `invariant` was declared after a handler; invariants precede handlers.",
1179 ),
1180 dg(
1181 "bynk.parse.malformed_float_literal",
1182 "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
1183 &["float_literal"],
1184 ),
1185 d(
1186 "bynk.parse.nesting_too_deep",
1187 "An expression or type nests deeper than the parser's fixed limit.",
1188 ),
1189 dg(
1190 "bynk.parse.non_associative",
1191 "A non-associative operator was chained (e.g. `a == b == c`).",
1192 &["binary_expr"],
1193 ),
1194 warn(d(
1195 "bynk.parse.orphan_doc_block",
1196 "A documentation block is not attached to a declaration (warning).",
1197 )),
1198 dg(
1199 "bynk.parse.refined_pattern_inner",
1200 "A refined pattern's inner form is something other than `_`.",
1201 &["refined_pattern"],
1202 ),
1203 dg(
1204 "bynk.parse.reserved_keyword",
1205 "A reserved keyword was used as an identifier.",
1206 &["identifier"],
1207 ),
1208 dg(
1209 "bynk.parse.self_outside_method",
1210 "`self` used outside a method or handler.",
1211 &["self_expr"],
1212 ),
1213 d(
1214 "bynk.parse.storage_after_phase",
1215 "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
1216 ),
1217 d(
1218 "bynk.parse.transition_after_handler",
1219 "A `transition` is declared after an agent handler; step invariants precede the handlers.",
1220 ),
1221 d(
1222 "bynk.parse.unexpected_adapter",
1223 "An `adapter` appeared where it is not allowed.",
1224 ),
1225 dg(
1226 "bynk.parse.unexpected_context",
1227 "A `context` appeared where it is not allowed.",
1228 &["context_decl"],
1229 ),
1230 d("bynk.parse.unexpected_eof", "Unexpected end of input."),
1231 dg(
1232 "bynk.parse.unexpected_suite",
1233 "A `suite` appeared where it is not allowed.",
1234 &["suite_decl"],
1235 ),
1236 d(
1237 "bynk.parse.unknown_effect_method",
1238 "An unknown method on `Effect`.",
1239 ),
1240 dg(
1241 "bynk.parse.unknown_handler_kind",
1242 "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
1243 &["handler"],
1244 ),
1245 dg(
1246 "bynk.parse.unknown_predicate",
1247 "An unknown refinement predicate.",
1248 &["predicate_name"],
1249 ),
1250 d(
1251 "bynk.parse.unknown_tier",
1252 "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
1253 ),
1254 dg(
1255 "bynk.parse.uses_after_decls",
1256 "`uses` appears after other declarations.",
1257 &["uses_decl"],
1258 ),
1259 dg(
1260 "bynk.parse.variant_name_case",
1261 "A sum-type or enum variant name is not capitalised.",
1262 &["sum_variant", "enum_type"],
1263 ),
1264 d(
1265 "bynk.project.file_and_directory",
1266 "A unit exists as both a file and a directory.",
1267 ),
1268 d(
1269 "bynk.project.inconsistent_commons_name",
1270 "A source file's path does not match its declared name.",
1271 ),
1272 d(
1273 "bynk.project.kind_conflict",
1274 "A name is declared as both a commons and a context.",
1275 ),
1276 d(
1277 "bynk.project.no_root",
1278 "No project root could be determined.",
1279 ),
1280 d(
1281 "bynk.project.no_sources",
1282 "The project contains no source files.",
1283 ),
1284 d(
1285 "bynk.project.read_failed",
1286 "A source file could not be read.",
1287 ),
1288 d(
1289 "bynk.project.schema_registry_corrupt",
1290 "`bynk.schema.lock` (the events schema registry) is missing its version field, empty, truncated, or otherwise unparseable — restore it from version control rather than deleting it, since deleting it would silently re-baseline every event's history.",
1291 ),
1292 dg(
1293 "bynk.property.restates_refinement",
1294 "A `property` merely re-checks a refinement its type already guarantees.",
1295 &["for_all"],
1296 ),
1297 dg(
1298 "bynk.property.where_not_bool",
1299 "A `for all ... where` filter does not type to `Bool`.",
1300 &["for_all"],
1301 ),
1302 dg(
1303 "bynk.provider.dependency_cycle",
1304 "Providers form a capability dependency cycle through `given`.",
1305 &["provider_decl"],
1306 ),
1307 dg(
1308 "bynk.provider.extra_operation",
1309 "A `provides` block implements an operation not in the capability.",
1310 &["provider_decl"],
1311 ),
1312 dg(
1313 "bynk.provider.generic_op_requires_external",
1314 "A Bynk-bodied `provides` implements a capability operation that declares its own type parameter — only an external (bodiless) provider can.",
1315 &["provider_decl"],
1316 ),
1317 dg(
1318 "bynk.provider.missing_operation",
1319 "A `provides` block is missing a capability operation.",
1320 &["provider_decl"],
1321 ),
1322 dg(
1323 "bynk.provider.outside_context",
1324 "`provides` was declared outside a context.",
1325 &["provider_decl"],
1326 ),
1327 dg(
1328 "bynk.provider.signature_mismatch",
1329 "A `provides` operation's signature does not match the capability.",
1330 &["provider_decl"],
1331 ),
1332 dg(
1333 "bynk.provider.unknown_capability",
1334 "`provides` names a capability that does not exist.",
1335 &["provider_decl"],
1336 ),
1337 d(
1338 "bynk.query.join_key_mismatch",
1339 "A `joinOn`/`leftJoin` left and right key function return different types.",
1340 ),
1341 dg(
1342 "bynk.query.sum_needs_numeric",
1343 "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
1344 &[],
1345 ),
1346 dg(
1347 "bynk.queue.bad_params",
1348 "An `on message` handler does not take exactly one `message` parameter.",
1349 &["queue_handler"],
1350 ),
1351 dg(
1352 "bynk.queue.duplicate_consumer",
1353 "Two `on message` handlers consume the same queue.",
1354 &["queue_handler"],
1355 ),
1356 dg(
1357 "bynk.queue.invalid_name",
1358 "A `from queue(\"…\")` binding has an empty queue name.",
1359 &["queue_handler"],
1360 ),
1361 dg(
1362 "bynk.queue.return_not_queue_result",
1363 "An `on message` handler does not return `Effect[QueueResult]`.",
1364 &["handler"],
1365 ),
1366 dg(
1367 "bynk.record_spread.field_type_mismatch",
1368 "A record-spread override has the wrong type for the field.",
1369 &["record_spread"],
1370 ),
1371 dg(
1372 "bynk.record_spread.non_record_base",
1373 "The base of a record spread is not a record.",
1374 &["record_spread"],
1375 ),
1376 dg(
1377 "bynk.record_spread.type_mismatch",
1378 "A record spread's base is a different record type.",
1379 &["record_spread"],
1380 ),
1381 dg(
1382 "bynk.record_spread.unknown_field",
1383 "A record spread overrides a field the record does not have.",
1384 &["record_spread"],
1385 ),
1386 dg(
1387 "bynk.refine.literal_violates",
1388 "A literal does not satisfy the refined type's predicate.",
1389 &["refined_type"],
1390 ),
1391 dg(
1392 "bynk.requires.unpinned_dependency",
1393 "An adapter `binding … requires { … }` entry has an unpinned version range.",
1394 &["binding_decl"],
1395 ),
1396 d(
1397 "bynk.resolve.ambiguous_variant",
1398 "A variant name is ambiguous across several sum types.",
1399 ),
1400 dg(
1401 "bynk.resolve.arity_mismatch",
1402 "A function was called with the wrong number of arguments.",
1403 &["call"],
1404 ),
1405 d("bynk.resolve.duplicate_actor", "Two actors share a name."),
1406 dg(
1407 "bynk.resolve.duplicate_agent",
1408 "Two agents share a name.",
1409 &["agent_decl"],
1410 ),
1411 dg(
1412 "bynk.resolve.duplicate_capability",
1413 "Two capabilities share a name.",
1414 &["capability_decl"],
1415 ),
1416 dg(
1417 "bynk.resolve.duplicate_field",
1418 "A record declares a field twice.",
1419 &["record_type"],
1420 ),
1421 dg(
1422 "bynk.resolve.duplicate_field_init",
1423 "A record construction initialises a field twice.",
1424 &["record_construction"],
1425 ),
1426 dg(
1427 "bynk.resolve.duplicate_fn",
1428 "Two functions share a name.",
1429 &["fn_decl"],
1430 ),
1431 d(
1432 "bynk.resolve.duplicate_message_code",
1433 "A message bundle declares the same code twice in one block.",
1434 ),
1435 d(
1436 "bynk.resolve.duplicate_message_locale",
1437 "Two `messages` blocks in one bundle declare the same locale tag.",
1438 ),
1439 dg(
1440 "bynk.resolve.duplicate_method",
1441 "Two methods share a name.",
1442 &["fn_decl"],
1443 ),
1444 dg(
1445 "bynk.resolve.duplicate_param",
1446 "A parameter name is repeated.",
1447 &["param"],
1448 ),
1449 dg(
1450 "bynk.resolve.duplicate_provider",
1451 "A capability is provided more than once.",
1452 &["provider_decl"],
1453 ),
1454 dg(
1455 "bynk.resolve.duplicate_service",
1456 "Two services share a name.",
1457 &["service_decl"],
1458 ),
1459 dg(
1460 "bynk.resolve.duplicate_type",
1461 "Two types share a name.",
1462 &["type_decl"],
1463 ),
1464 dg(
1465 "bynk.resolve.duplicate_variant",
1466 "A sum type declares a variant twice.",
1467 &["sum_type"],
1468 ),
1469 d(
1470 "bynk.resolve.fn_without_call",
1471 "A function was referenced without being called.",
1472 ),
1473 dg(
1474 "bynk.resolve.let_shadows_fn",
1475 "A `let` binding shadows a function.",
1476 &["let_stmt"],
1477 ),
1478 dg(
1479 "bynk.resolve.let_shadows_type",
1480 "A `let` binding shadows a type.",
1481 &["let_stmt"],
1482 ),
1483 d(
1484 "bynk.resolve.method_unknown_type",
1485 "A method is defined on an unknown type.",
1486 ),
1487 dg(
1488 "bynk.resolve.missing_field",
1489 "A record construction omits a required field.",
1490 &["record_construction"],
1491 ),
1492 d(
1493 "bynk.resolve.name_conflict",
1494 "Two declarations share a name.",
1495 ),
1496 dg(
1497 "bynk.resolve.not_a_record_type",
1498 "Record syntax was used on a non-record type.",
1499 &["record_construction"],
1500 ),
1501 dg(
1502 "bynk.resolve.opaque_record_construction",
1503 "An opaque type was constructed with record syntax.",
1504 &["record_construction"],
1505 ),
1506 dg(
1507 "bynk.resolve.param_as_function",
1508 "A value (such as a parameter) was called as a function.",
1509 &["call"],
1510 ),
1511 dg(
1512 "bynk.resolve.recursive_record_field",
1513 "A record directly contains a field of its own type.",
1514 &["record_type"],
1515 ),
1516 dg(
1517 "bynk.resolve.reserved_builtin_type",
1518 "A type declaration reuses a compiler-known built-in type name.",
1519 &["type_decl"],
1520 ),
1521 dg(
1522 "bynk.resolve.self_outside_method",
1523 "`self` referenced outside a method or handler.",
1524 &["self_expr"],
1525 ),
1526 dg(
1527 "bynk.resolve.type_as_function",
1528 "A type name was called as if it were a function.",
1529 &["call"],
1530 ),
1531 d(
1532 "bynk.resolve.type_in_expr",
1533 "A type name was used where a value is expected.",
1534 ),
1535 dg(
1536 "bynk.resolve.unconsumed_context",
1537 "A context's service was called without a `consumes` declaration.",
1538 &["consumes_decl"],
1539 ),
1540 dg(
1541 "bynk.resolve.unknown_field",
1542 "Accessed a field the record does not have.",
1543 &["field_access"],
1544 ),
1545 dg(
1546 "bynk.resolve.unknown_function",
1547 "Called a function that does not exist.",
1548 &["call"],
1549 ),
1550 d(
1551 "bynk.resolve.unknown_name",
1552 "Referenced a name that is not in scope.",
1553 ),
1554 dg(
1555 "bynk.resolve.unknown_static_member",
1556 "Referenced an unknown static member (e.g. `T.x`).",
1557 &["field_access"],
1558 ),
1559 d(
1560 "bynk.resolve.unknown_type",
1561 "Referenced a type that does not exist.",
1562 ),
1563 warn(d(
1564 "bynk.secrets.computed_name",
1565 "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
1566 )),
1567 dg(
1568 "bynk.send.in_pure_context",
1569 "A `~>` send was used in a pure (non-effectful) context.",
1570 &["effect_send_stmt"],
1571 ),
1572 dg(
1573 "bynk.send.non_effect",
1574 "A `~>` send was applied to a non-`Effect` value.",
1575 &["effect_send_stmt"],
1576 ),
1577 dg(
1578 "bynk.send.requires_unit",
1579 "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1580 &["effect_send_stmt"],
1581 ),
1582 dg(
1583 "bynk.service.missing_from",
1584 "A `from`-less service has a handler other than `on call`.",
1585 &["service_decl"],
1586 ),
1587 dg(
1588 "bynk.service.mixed_protocols",
1589 "A service mixes handler forms that do not match its `from <protocol>`.",
1590 &["service_decl"],
1591 ),
1592 dg(
1593 "bynk.service.outside_context",
1594 "A `service` was declared outside a context.",
1595 &["service_decl"],
1596 ),
1597 dg(
1598 "bynk.service.return_not_effect",
1599 "A service handler's return type is not an `Effect`.",
1600 &["service_decl"],
1601 ),
1602 dg(
1603 "bynk.service.unknown_protocol",
1604 "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1605 &["service_decl"],
1606 ),
1607 d(
1608 "bynk.service.websocket_header",
1609 "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
1610 ),
1611 d(
1612 "bynk.service.websocket_multiple",
1613 "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).",
1614 ),
1615 d(
1616 "bynk.service.websocket_open_arity",
1617 "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).",
1618 ),
1619 d(
1620 "bynk.store.annotation_kind_mismatch",
1621 "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1622 ),
1623 d(
1624 "bynk.store.annotation_unsupported",
1625 "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1626 ),
1627 d(
1628 "bynk.store.cache_needs_clock",
1629 "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1630 ),
1631 d(
1632 "bynk.store.cache_ttl_required",
1633 "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1634 ),
1635 d(
1636 "bynk.store.kind_arity",
1637 "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1638 ),
1639 d(
1640 "bynk.store.kind_unsupported",
1641 "A known storage kind (`Queue`) is used before the slice that supports it.",
1642 ),
1643 d(
1644 "bynk.store.log_needs_clock",
1645 "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1646 ),
1647 d(
1648 "bynk.store.unknown_annotation",
1649 "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1650 ),
1651 d(
1652 "bynk.store.unknown_kind",
1653 "A `store` field's type is not a known storage kind.",
1654 ),
1655 d(
1656 "bynk.store.unknown_map_accessor",
1657 "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
1658 ),
1659 d(
1660 "bynk.store.unknown_op",
1661 "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1662 ),
1663 d(
1664 "bynk.stub.bad_sequence",
1665 "A `stub … returns each […]` sequence is malformed (e.g. empty).",
1666 ),
1667 d(
1668 "bynk.stub.generic_op",
1669 "A test `stub` targets a capability operation that declares its own type parameter — not supported at v1.",
1670 ),
1671 d(
1672 "bynk.stub.not_a_seam",
1673 "A test `stub` overrides a capability the unit under test does not consume.",
1674 ),
1675 d(
1676 "bynk.stub.rhs_type",
1677 "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
1678 ),
1679 d(
1680 "bynk.stub.unknown_op",
1681 "A test `stub` names an operation the capability does not declare.",
1682 ),
1683 dg(
1684 "bynk.suite.duplicate_case_name",
1685 "Two `case`s share a description.",
1686 &["case"],
1687 ),
1688 dg(
1689 "bynk.suite.unknown_target",
1690 "A `suite` targets a unit that does not exist.",
1691 &["suite_decl"],
1692 ),
1693 d(
1694 "bynk.target.browser_bundle_only",
1695 "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
1696 ),
1697 dg(
1698 "bynk.target.vendor_conflict",
1699 "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
1700 &["consumes_decl"],
1701 ),
1702 dg(
1703 "bynk.target.vendor_required",
1704 "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
1705 &["consumes_decl"],
1706 ),
1707 dg(
1708 "bynk.test.actor_identity_required",
1709 "A call-site `by <Actor>` omits the identity an identity-carrying actor requires.",
1710 &["case"],
1711 ),
1712 dg(
1713 "bynk.test.actor_no_identity",
1714 "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
1715 &["case"],
1716 ),
1717 dg(
1718 "bynk.test.credential_needs_system",
1719 "A case drives `by Nobody` (the no-credential principal, which tests the auth seam's 401) outside a `system`-tier case, where there is no real seam to reject it.",
1720 &["case"],
1721 ),
1722 dg(
1723 "bynk.test.nobody_needs_secured_route",
1724 "A case drives `by Nobody` at a route that is not Bearer-secured (e.g. a public `Visitor` route) — there is no auth seam to reject the missing credential.",
1725 &["case"],
1726 ),
1727 dg(
1728 "bynk.test.principal_identity_mismatch",
1729 "A call-site `by <Actor>` acts as an actor whose identity is incompatible with the addressed handler's actor.",
1730 &["case"],
1731 ),
1732 dg(
1733 "bynk.test.principal_on_wrong_method",
1734 "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
1735 &["case"],
1736 ),
1737 dg(
1738 "bynk.test.principal_required",
1739 "A test drives an identity-carrying handler with no call-site `by <Actor>(<identity>)`.",
1740 &["case"],
1741 ),
1742 dg(
1743 "bynk.test.service_bad_address",
1744 "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
1745 &["case"],
1746 ),
1747 dg(
1748 "bynk.test.service_call_arity",
1749 "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
1750 &["case"],
1751 ),
1752 dg(
1753 "bynk.test.service_no_call_handler",
1754 "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
1755 &["case"],
1756 ),
1757 dg(
1758 "bynk.test.service_unknown_route",
1759 "A test body addresses an http route / cron schedule / queue message the service does not declare.",
1760 &["case"],
1761 ),
1762 dg(
1763 "bynk.test.unknown_actor",
1764 "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
1765 &["case"],
1766 ),
1767 dg(
1768 "bynk.test.wire_needs_system",
1769 "A `Wire(...)` raw argument is used outside a `system`-tier service address; `Wire` hands pre-validation input to the boundary and is meaningless at `unit` or in any other position.",
1770 &["case"],
1771 ),
1772 d(
1773 "bynk.tier.property_has_tier",
1774 "A `property` carries an `as <tier>` clause; tiers are a `case`-only affordance.",
1775 ),
1776 d(
1777 "bynk.tier.system_needs_wire",
1778 "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
1779 ),
1780 d(
1781 "bynk.transition.cross_agent_reference",
1782 "A transition predicate references another agent; step invariants are per-agent.",
1783 ),
1784 d(
1785 "bynk.transition.duplicate_name",
1786 "An agent declares two transitions with the same name.",
1787 ),
1788 d(
1789 "bynk.transition.impure_predicate",
1790 "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
1791 ),
1792 d(
1793 "bynk.transition.no_step_reference",
1794 "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
1795 ),
1796 d(
1797 "bynk.transition.not_bool",
1798 "A transition predicate does not have type `Bool`.",
1799 ),
1800 d(
1801 "bynk.types.ambiguous_constructor",
1802 "`Ok`/`Err` is ambiguous between `Result` and `HttpResult`; qualify it.",
1803 ),
1804 dg(
1805 "bynk.types.argument_mismatch",
1806 "A call, method, capability, or constructor argument has the wrong type.",
1807 &["call"],
1808 ),
1809 dg(
1810 "bynk.types.call_arity",
1811 "A function value was applied with the wrong number of arguments.",
1812 &["call"],
1813 ),
1814 dg(
1815 "bynk.types.cannot_infer_option_type_param",
1816 "The value type of `None` could not be inferred.",
1817 &["none_expr"],
1818 ),
1819 d(
1820 "bynk.types.cannot_infer_result_type_params",
1821 "The type parameters of a `Result` could not be inferred.",
1822 ),
1823 dg(
1824 "bynk.types.catastrophic_regex",
1825 "A `Matches` predicate nests unbounded quantifiers, risking catastrophic backtracking (ReDoS).",
1826 &["refinement"],
1827 ),
1828 dg(
1829 "bynk.types.combinator_return_mismatch",
1830 "A callback passed to a combinator (`map`/`andThen`/`flatMap`/`traverseAll`/…) returns the wrong type.",
1831 &["call"],
1832 ),
1833 d(
1834 "bynk.types.constructor_arity",
1835 "A variant constructor got the wrong number of arguments.",
1836 ),
1837 d(
1838 "bynk.types.constructor_base_mismatch",
1839 "A `.of` constructor was given an argument of the wrong base type.",
1840 ),
1841 dg(
1842 "bynk.types.duplicate_literal_arm",
1843 "A `match` has two arms for the same literal value.",
1844 &["match_arm"],
1845 ),
1846 dg(
1847 "bynk.types.duplicate_variant_arm",
1848 "A `match` has two arms for the same variant.",
1849 &["match_arm"],
1850 ),
1851 d(
1852 "bynk.types.embeds_ambiguous",
1853 "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
1854 ),
1855 d(
1856 "bynk.types.embeds_unknown_variant",
1857 "An `embeds … as V` clause names a variant the sum does not declare.",
1858 ),
1859 d(
1860 "bynk.types.embeds_variant_shape",
1861 "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
1862 ),
1863 dg(
1864 "bynk.types.empty_refinement",
1865 "A refinement admits no values (contradictory predicates).",
1866 &["refinement"],
1867 ),
1868 dg(
1869 "bynk.types.err_value_mismatch",
1870 "An `Err` payload has the wrong type.",
1871 &["err_expr"],
1872 ),
1873 dg(
1874 "bynk.types.field_access_on_non_record",
1875 "Field access on a value that is not a record.",
1876 &["field_access"],
1877 ),
1878 dg(
1879 "bynk.types.field_refinement_not_base",
1880 "An inline field refinement requires a base or refined type.",
1881 &["record_field"],
1882 ),
1883 dg(
1884 "bynk.types.field_value_mismatch",
1885 "A record field was given a value of the wrong type.",
1886 &["record_construction"],
1887 ),
1888 dg(
1889 "bynk.types.function_at_boundary",
1890 "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.",
1891 &["function_type_ref"],
1892 ),
1893 dg(
1894 "bynk.types.guard_not_bool",
1895 "A match-arm `if` guard is not a `Bool` expression.",
1896 &["match_arm"],
1897 ),
1898 d(
1899 "bynk.types.held_at_boundary",
1900 "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).",
1901 ),
1902 d(
1903 "bynk.types.held_not_comparable",
1904 "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
1905 ),
1906 dg(
1907 "bynk.types.if_branch_mismatch",
1908 "The branches of an `if` have different types.",
1909 &["if_expr"],
1910 ),
1911 dg(
1912 "bynk.types.if_non_bool_cond",
1913 "An `if` condition is not a `Bool`.",
1914 &["if_expr"],
1915 ),
1916 dg(
1917 "bynk.types.if_without_else_requires_unit",
1918 "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
1919 &["if_expr"],
1920 ),
1921 d(
1922 "bynk.types.interpolation_non_scalar",
1923 "An interpolation hole holds a value with no string form.",
1924 ),
1925 dg(
1926 "bynk.types.invalid_regex",
1927 "A `Matches` predicate contains an invalid regular expression.",
1928 &["refinement"],
1929 ),
1930 dg(
1931 "bynk.types.inverted_range",
1932 "An `InRange` predicate has its bounds inverted.",
1933 &["refinement"],
1934 ),
1935 dg(
1936 "bynk.types.is_base_mismatch",
1937 "An `is` refinement check is applied to a value of the wrong base type.",
1938 &["is_expr"],
1939 ),
1940 dg(
1941 "bynk.types.is_literal_pattern",
1942 "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
1943 &["is_expr"],
1944 ),
1945 dg(
1946 "bynk.types.is_non_sum",
1947 "`is` was applied to a value that is not a sum type.",
1948 &["is_expr"],
1949 ),
1950 dg(
1951 "bynk.types.is_refined_pattern",
1952 "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
1953 &["is_expr"],
1954 ),
1955 dg(
1956 "bynk.types.is_unknown_variant",
1957 "`is` names a variant the type does not have.",
1958 &["is_expr"],
1959 ),
1960 dg(
1961 "bynk.types.json_uncodable",
1962 "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
1963 &["method_call"],
1964 ),
1965 dg(
1966 "bynk.types.key_not_orderable",
1967 "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
1968 &[],
1969 ),
1970 dg(
1971 "bynk.types.lambda_mismatch",
1972 "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
1973 &["lambda_expr"],
1974 ),
1975 dg(
1976 "bynk.types.let_annotation_mismatch",
1977 "A `let` value does not match its type annotation.",
1978 &["let_stmt"],
1979 ),
1980 dg(
1981 "bynk.types.list_element_mismatch",
1982 "A list-literal element has a different type from the list's element type.",
1983 &["list_literal"],
1984 ),
1985 dg(
1986 "bynk.types.match_arm_mismatch",
1987 "A `match` arm has a different type from the others.",
1988 &["match_arm"],
1989 ),
1990 dg(
1991 "bynk.types.match_non_sum_discriminant",
1992 "`match` was applied to a value that is not a sum type.",
1993 &["match_expr"],
1994 ),
1995 dg(
1996 "bynk.types.method_arity",
1997 "A method was called with the wrong number of arguments.",
1998 &["method_call"],
1999 ),
2000 dg(
2001 "bynk.types.method_not_found",
2002 "Called a method the type does not have.",
2003 &["method_call"],
2004 ),
2005 dg(
2006 "bynk.types.method_on_non_named_type",
2007 "A method was called on a built-in type that has no methods.",
2008 &["method_call"],
2009 ),
2010 dg(
2011 "bynk.types.mixed_pattern_bindings",
2012 "A pattern mixes named and positional bindings.",
2013 &["variant_pattern"],
2014 ),
2015 dg(
2016 "bynk.types.negative_length",
2017 "A length predicate was given a negative value.",
2018 &["refinement"],
2019 ),
2020 dg(
2021 "bynk.types.no_numeric_coercion",
2022 "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
2023 &["binary_expr", "refinement"],
2024 ),
2025 dg(
2026 "bynk.types.non_exhaustive_match",
2027 "A `match` does not cover every variant.",
2028 &["match_expr"],
2029 ),
2030 dg(
2031 "bynk.types.ok_value_mismatch",
2032 "An `Ok` payload has the wrong type.",
2033 &["ok_expr"],
2034 ),
2035 dg(
2036 "bynk.types.opaque_raw_outside",
2037 "`.raw` on an opaque type was used outside its defining commons.",
2038 &["field_access"],
2039 ),
2040 dg(
2041 "bynk.types.opaque_record_construction",
2042 "An opaque type was constructed with record syntax.",
2043 &["record_construction"],
2044 ),
2045 dg(
2046 "bynk.types.opaque_unsafe_outside",
2047 "`.unsafe` on an opaque type was used outside its defining context.",
2048 &["field_access"],
2049 ),
2050 dg(
2051 "bynk.types.or_pattern_binding_mismatch",
2052 "An or-pattern's alternatives don't all bind the same set of names.",
2053 &["match_arm", "is_expr"],
2054 ),
2055 dg(
2056 "bynk.types.or_pattern_type_mismatch",
2057 "An or-pattern's alternatives give a shared binding different types (or refinements).",
2058 &["match_arm", "is_expr"],
2059 ),
2060 dg(
2061 "bynk.types.pattern_arity",
2062 "A pattern binds the wrong number of payload fields.",
2063 &["variant_pattern"],
2064 ),
2065 dg(
2066 "bynk.types.pattern_type_mismatch",
2067 "A pattern's type does not match the matched value.",
2068 &["variant_pattern"],
2069 ),
2070 dg(
2071 "bynk.types.predicate_base_mismatch",
2072 "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
2073 &["refinement"],
2074 ),
2075 d(
2076 "bynk.types.query_at_boundary",
2077 "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).",
2078 ),
2079 dg(
2080 "bynk.types.question_error_mismatch",
2081 "`?` propagates an error type incompatible with the function's.",
2082 &["question_expr"],
2083 ),
2084 dg(
2085 "bynk.types.question_on_non_result",
2086 "`?` was applied to a non-`Result` value.",
2087 &["question_expr"],
2088 ),
2089 dg(
2090 "bynk.types.question_option_outside_http",
2091 "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
2092 &["question_expr"],
2093 ),
2094 dg(
2095 "bynk.types.question_outside_result",
2096 "`?` used in a function that does not return a `Result`.",
2097 &["question_expr"],
2098 ),
2099 d(
2100 "bynk.types.return_mismatch",
2101 "A returned value does not match the declared return type.",
2102 ),
2103 dg(
2104 "bynk.types.some_value_mismatch",
2105 "A `Some` payload has the wrong type.",
2106 &["some_expr"],
2107 ),
2108 d(
2109 "bynk.types.stream_at_boundary",
2110 "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).",
2111 ),
2112 d(
2113 "bynk.types.stream_not_comparable",
2114 "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
2115 ),
2116 d(
2117 "bynk.types.type_mismatch",
2118 "Two types that were required to match did not.",
2119 ),
2120 dg(
2121 "bynk.types.uninferable_element_type",
2122 "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
2123 &["list_literal"],
2124 ),
2125 dg(
2126 "bynk.types.unkeyable_distinct",
2127 "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2128 &[],
2129 ),
2130 dg(
2131 "bynk.types.unkeyable_map_key",
2132 "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2133 &["generic_type_ref"],
2134 ),
2135 dg(
2136 "bynk.types.unknown_field",
2137 "Referenced a field the record type does not declare.",
2138 &["field_access"],
2139 ),
2140 dg(
2141 "bynk.types.unknown_pattern_field",
2142 "A pattern names a field the variant does not have.",
2143 &["variant_pattern"],
2144 ),
2145 dg(
2146 "bynk.types.unknown_static_member",
2147 "Referenced an unknown static member on a type.",
2148 &["field_access"],
2149 ),
2150 dg(
2151 "bynk.types.unknown_variant_in_pattern",
2152 "A pattern names a variant the sum type does not have.",
2153 &["variant_pattern"],
2154 ),
2155 dg(
2156 "bynk.types.unreachable_arm",
2157 "A `match` arm is unreachable.",
2158 &["match_arm"],
2159 ),
2160 d(
2161 "bynk.types.variant_arity",
2162 "A variant constructor got the wrong number of payload values.",
2163 ),
2164 d(
2165 "bynk.types.variant_missing_payload",
2166 "A variant requiring a payload was used without one.",
2167 ),
2168 d(
2169 "bynk.types.variant_payload_mismatch",
2170 "A variant payload has the wrong type.",
2171 ),
2172 dg(
2173 "bynk.uses.name_conflict",
2174 "A `uses` name collides with another name.",
2175 &["uses_decl"],
2176 ),
2177 dg(
2178 "bynk.uses.self_reference",
2179 "A commons `uses` itself.",
2180 &["uses_decl"],
2181 ),
2182 dg(
2183 "bynk.uses.target_is_context",
2184 "`uses` targets a context instead of a commons.",
2185 &["uses_decl"],
2186 ),
2187 dg(
2188 "bynk.uses.unknown_commons",
2189 "`uses` names a commons that does not exist.",
2190 &["uses_decl"],
2191 ),
2192 dg(
2193 "bynk.val.agent_not_generable",
2194 "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
2195 &["for_all"],
2196 ),
2197 dg(
2198 "bynk.val.arity",
2199 "`Val[T]` was given the wrong number of pin arguments.",
2200 &["val_expr"],
2201 ),
2202 dg(
2203 "bynk.val.literal_violates",
2204 "A pinned `Val[T]` value violates the type's refinement.",
2205 &["val_expr"],
2206 ),
2207 dg(
2208 "bynk.val.needs_pin",
2209 "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
2210 &["val_expr"],
2211 ),
2212 dg(
2213 "bynk.val.outside_test",
2214 "`Val[T]` was used outside a test case body.",
2215 &["val_expr"],
2216 ),
2217 dg(
2218 "bynk.val.pin_not_literal",
2219 "A `Val[T]` pin argument is not a compile-time literal.",
2220 &["val_expr"],
2221 ),
2222 dg(
2223 "bynk.val.pin_unsupported",
2224 "A pin was given for a type kind that does not support pinning.",
2225 &["val_expr"],
2226 ),
2227 dg(
2228 "bynk.val.unknown_type",
2229 "`Val[T]` names a type that does not resolve.",
2230 &["val_expr"],
2231 ),
2232 dg(
2233 "bynk.val.unsupported_kind",
2234 "`Val[T]` cannot fabricate a value for this kind of type.",
2235 &["val_expr"],
2236 ),
2237 d(
2238 "bynk.ws.message_frame_param",
2239 "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).",
2240 ),
2241 d(
2242 "bynk.ws.open_given_unsupported",
2243 "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).",
2244 ),
2245 d(
2246 "bynk.ws.open_transfer_shape",
2247 "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).",
2248 ),
2249 d(
2250 "bynk.ws.route_param_mismatch",
2251 "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).",
2252 ),
2253];
2254
2255const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
2257 DiagnosticInfo {
2258 code,
2259 summary,
2260 grammar_symbol: &[],
2261 severity: Severity::Error,
2262 }
2263}
2264
2265const fn dg(
2267 code: &'static str,
2268 summary: &'static str,
2269 grammar_symbol: &'static [&'static str],
2270) -> DiagnosticInfo {
2271 DiagnosticInfo {
2272 code,
2273 summary,
2274 grammar_symbol,
2275 severity: Severity::Error,
2276 }
2277}
2278
2279const fn warn(mut info: DiagnosticInfo) -> DiagnosticInfo {
2283 info.severity = Severity::Warning;
2284 info
2285}
2286
2287pub fn category(code: &str) -> &str {
2290 code.split('.').nth(1).unwrap_or("")
2291}
2292
2293fn category_title(cat: &str) -> &'static str {
2295 match cat {
2296 "agent" | "agents" => "Agents",
2297 "boundary" => "Boundaries",
2298 "capability" => "Capabilities",
2299 "consumes" => "Consumes",
2300 "context" => "Contexts",
2301 "contract" => "Contracts",
2302 "cron" => "Cron",
2303 "effect" => "Effects",
2304 "expect" => "Expectations",
2305 "exports" => "Exports",
2306 "given" => "Given capabilities",
2307 "http" => "HTTP",
2308 "lex" => "Lexer",
2309 "messages" => "Message bundles",
2310 "mock" => "Mocks (collaborators)",
2311 "observe" => "Observation",
2312 "parse" => "Parser",
2313 "project" => "Project",
2314 "property" => "Properties (generative tests)",
2315 "provider" => "Providers",
2316 "queue" => "Queue",
2317 "record_spread" => "Record spread",
2318 "refine" => "Refinement",
2319 "resolve" => "Resolution",
2320 "service" => "Services",
2321 "suite" => "Suites and cases",
2322 "transition" => "Transitions (step invariants)",
2323 "types" => "Type checking",
2324 "uses" => "Uses",
2325 "val" => "Value fabrication",
2326 _ => "Other",
2327 }
2328}
2329
2330pub fn render_markdown() -> String {
2334 use std::collections::BTreeMap;
2335
2336 let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2338 for info in REGISTRY {
2339 by_category
2340 .entry(category_title(category(info.code)))
2341 .or_default()
2342 .push(info);
2343 }
2344
2345 let mut out = String::new();
2346 out.push_str("# Diagnostic index\n\n");
2347 out.push_str(
2348 "<!-- GENERATED FILE — do not edit by hand.\n \
2349 Source: bynkc/src/diagnostics.rs (`render_markdown`).\n \
2350 Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
2351 );
2352 out.push_str(
2353 "Every diagnostic code the compiler can emit, with a one-line summary of \
2354 the cause, grouped by category. For step-by-step cause-and-fix guidance \
2355 on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md).\n\n",
2356 );
2357 out.push_str(&format!(
2358 "There are **{}** codes in total.\n",
2359 REGISTRY.len()
2360 ));
2361
2362 for (title, infos) in &by_category {
2363 out.push_str(&format!("\n## {title}\n\n"));
2364 out.push_str("| Code | Summary | Construct | Severity |\n|---|---|---|---|\n");
2365 for info in infos {
2366 let construct = info
2371 .grammar_symbol
2372 .iter()
2373 .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
2374 .collect::<Vec<_>>()
2375 .join(", ");
2376 let code_cell = match explain(info.code) {
2381 Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
2382 None => format!("`{}`", info.code),
2383 };
2384 let severity = match info.severity {
2389 Severity::Error => "—",
2390 Severity::Warning => "Warning",
2391 };
2392 out.push_str(&format!(
2393 "| {} | {} | {} | {} |\n",
2394 code_cell, info.summary, construct, severity
2395 ));
2396 }
2397 }
2398
2399 out
2400}
2401
2402pub fn render_grammar_semantics_json() -> String {
2408 use std::collections::BTreeMap;
2409
2410 let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2413 for info in REGISTRY {
2414 for sym in info.grammar_symbol {
2415 by_symbol.entry(sym).or_default().push(info);
2416 }
2417 }
2418
2419 let mut map = serde_json::Map::new();
2420 map.insert(
2421 "_generated".to_string(),
2422 serde_json::Value::String(
2423 "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
2424 Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
2425 bynkc --test diagnostics_registry"
2426 .to_string(),
2427 ),
2428 );
2429 for (sym, infos) in by_symbol {
2430 let arr: Vec<serde_json::Value> = infos
2431 .iter()
2432 .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
2433 .collect();
2434 map.insert(sym.to_string(), serde_json::Value::Array(arr));
2435 }
2436
2437 let mut s =
2438 serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
2439 s.push('\n');
2440 s
2441}