E06240: either all variable must be named or none, when passing parameters

Category: E06xxx Type hierarchy checks · Reported in phase: SYMBOL_DEFINITION · Classification: EITHER_ALL_PARAMETERS_NAMED_OR_NONE · All error codes

What went wrong

When using named parameters, you must be consistent - either ALL parameters are named, or NONE are named. Mixing named and positional causes ambiguity.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 115 (How do dynamic classes work in EK9?)

How to fix it

  1. Either add names to ALL parameters
  2. Or remove names from ALL parameters
  3. Check for partially converted code

Rationale

Named parameters are matched by name, positional by position. Mixing creates ambiguous binding - should second arg match by position or skip to named?

Common causes

  • Partially converting to named parameters
  • Accidentally adding name to one parameter
  • Copy/paste from different calling style

See also

  • E06240: mixed named/positional parameters (this error)
  • E06250: wrong parameter name used

Examples

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

Fails with E06240: either all variable must be named or none, when passing parameters

#!ek9
defines module error.e06240.bad

  defines trait

    RangeCheck
      within()
        -> text as String
        <- result as Boolean?

  defines program

    MixedCaptures()
      max <- 100

      //One capture named, one not
      check <- (min: 10, max) with trait of RangeCheck as class
        override within()
          -> text as String
          <- result as Boolean: length text > min and length text < max

Fixed: Name every capture, or none

#!ek9
defines module error.e06240.good

  defines trait

    RangeCheck
      within()
        -> text as String
        <- result as Boolean?

  defines program

    AllNamed()
      stdout <- Stdout()
      max <- 100

      check <- (min: 10, max: max) with trait of RangeCheck as class
        override within()
          -> text as String
          <- result as Boolean: length text > min and length text < max
        default operator ?

      stdout.println($check.within("short"))

Fixed: Or capture plain variables only, all unnamed

#!ek9
defines module error.e06240.good.positional

  defines trait

    RangeCheck
      within()
        -> text as String
        <- result as Boolean?

  defines program

    AllPositional()
      stdout <- Stdout()
      min <- 10
      max <- 100

      check <- (min, max) with trait of RangeCheck as class
        override within()
          -> text as String
          <- result as Boolean: length text > min and length text < max
        default operator ?

      stdout.println($check.within("short"))

Questions and answers

These Q&A entries show E06240 and its fix: