bynk.generics.ambiguous_instantiation
Error A generic function with an Ord bound is used as a value, and its type arguments cannot be determined from the type expected at that reference; annotate the expected type (constrained-generics slice 1).
A generic function with an Ord bound, named as a value, is instantiated where it stands, from the function type expected there. When that type is still open, because the receiving parameter's own type is not fixed yet, there is no T to choose, and a guess could order by the wrong type. Wrap the function in a lambda, which is checked after the other arguments, or annotate the expected function type.
Example
fn same[T: Ord](x: T) -> T { x }
fn wrap[A](g: (A) -> A, x: A) -> A { g(x) }
fn pick() -> Int { wrap(same, 1) } // ✗ `A` is known only from the later argument
fn pick() -> Int { wrap((n) => same(n), 1) } // ✓ a lambda is checked after itIn the Book
See also
- The grammar rule it governs:
fn_decl. - Every code in its category, Generics, on the diagnostic index.
bynk explain bynk.generics.ambiguous_instantiationshows the same from the installed toolchain, without a network.