E06050: a generic type requires correct constructor argument to match parametric types (and order)

Category: E06xxx Type hierarchy checks · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: GENERIC_TYPE_REQUIRES_CORRECT_CONSTRUCTOR_ARGUMENT_TYPES · All error codes

What went wrong

Constructor argument types don't match the generic type parameters. When constructing a generic type, the arguments you pass must match the types specified in the 'of' clause.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 644 (How must constructor argument types match generic type pa...)
  • ek9 -q 683 (What are the complete constructor rules for generic types?)

How to fix it

  1. Check the 'of' clause to see expected types and order
  2. Ensure constructor arguments match those types exactly
  3. Match the ORDER of types in the 'of' clause

Type matching rules

  • Types must match exactly or be compatible subtypes
  • Order matters: 'of (A, B)' means first arg is A, second is B
  • Count matters: must provide exactly as many args as type params

Common causes

  • Swapping argument order (common with Result and Dict)
  • Passing wrong type (Integer where String expected)
  • Forgetting which type parameter is which

See also

  • E06050: constructor argument type mismatch (this error)
  • E06020: wrong NUMBER of type parameters
  • E06030: generic definition alignment issue

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E06050: a generic type requires correct constructor argument to match parametric types (and order)

#!ek9
defines module error.e06050.bad

  defines class

    Pair of type (S, T)

      default Pair()

      default Pair()
        ->
          //The constructor's parameters follow the type parameters in order: S, then T
          first as T
          second as T

      check()
        -> item as T
        <- rtn as Boolean: item?

Fixed: Take each type parameter once, in the order they are declared: (S, T)

#!ek9
defines module error.e06050.good

  defines class

    Pair of type (S, T)

      default Pair()

      default Pair()
        ->
          first as S
          second as T

      check()
        -> item as T
        <- rtn as Boolean: item?

Questions and answers

These Q&A entries show E06050 and its fix: