bynk.resolve.ambiguous_variant
Error A bare variant name is declared by several sum types in scope, and no expected type picks one.
A bare variant name such as Failed("down") builds a value of the sum that declares it. When two sums in scope declare the name (two of your own, or two that a consumed unit exports, like an adapter's error enums), the compiler reads the expected type: an annotated let, a parameter, a return type, or a stub's operation. It builds the sum that type names. With nothing expecting either sum it cannot know which you meant, and it never picks one, so the name is refused. Qualify it as TypeName.Variant, or give the value a type. A match arm needs neither, because it reads its scrutinee's sum.
Example
type DbError = | Constraint(message: String) | Failed(message: String)type MailError = | RateLimited | Failed(message: String)
let e = Failed("down") // ✗ `DbError` or `MailError`?
fn mail() -> Result[Int, MailError] { Err(Failed("down")) // ✓ the return type picks `MailError`}
DbError.Failed("down") // ✓ qualifiedIn the Book
See also
- Every code in its category, Resolution, on the diagnostic index.
bynk explain bynk.resolve.ambiguous_variantshows the same from the installed toolchain, without a network.