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