Skip to content
Playground(another site)

bynk.generics.generic_sum_embeds

Error A generic sum type carries an embeds clause; embedding into a generic sum is not supported (#593).

embeds E as V lets ? wrap an E error in the variant V, picking the variant by the error's type. In a generic sum that conversion would have to hold for every instantiation, which is not supported. Drop the embeds clause and wrap the error by hand where it is needed, with .mapErr(Payment), or make the sum non-generic.

Example

type PayError = enum { Declined }
type Failure[T] =
| Payment(reason: PayError)
| Other(value: T)
embeds PayError as Payment // ✗ a generic sum cannot embed
type Failure[T] =
| Payment(reason: PayError)
| Other(value: T) // ✓ no `embeds`; wrap with `.mapErr(Payment)`

In the Book

See also

  • The grammar rule it governs: type_decl.
  • Every code in its category, Generics, on the diagnostic index.
  • bynk explain bynk.generics.generic_sum_embeds shows the same from the installed toolchain, without a network.