E06240: either all variable must be named or none, when passing parameters
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
- Either add names to ALL parameters
- Or remove names from ALL parameters
- 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
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: