E06230: variables being captured must be named when not just using identifiers
What went wrong
When capturing values in dynamic functions/classes, expressions, function calls, and literals MUST have a name. Only simple variable identifiers can be captured without naming.
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
- Add name before colon: (name: expression)
- Or assign expression to variable first, then capture variable
Rationale
The captured value needs a name so it can be referenced in the function body. Simple variables already have names; expressions/literals don't.
Common causes
- Capturing function call result without naming it
- Capturing a literal value without naming it
- Forgetting that expressions aren't auto-named
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06230: variables being captured must be named when not just using identifiers
#!ek9 defines module error.e06230.bad defines function threshold() as pure <- rtn as Integer: 42 discriminator() as abstract -> text as String <- rtn as Boolean? defines program UnnamedCaptures() //A capture that is not just a variable needs a name the body can use longer <- (threshold()) is discriminator as function rtn: length text > threshold shorter <- (100) is discriminator as function rtn: length text < max
Fixed: Name each captured expression: (min: threshold()), (max: 100)
#!ek9 defines module error.e06230.good defines function threshold() as pure <- rtn as Integer: 42 discriminator() as abstract -> text as String <- rtn as Boolean? defines program NamedCaptures() stdout <- Stdout() longer <- (min: threshold()) is discriminator as function rtn: length text > min shorter <- (max: 100) is discriminator as function rtn: length text < max stdout.println(`${longer("a sentence")} ${shorter("a sentence")}`)
Questions and answers
These Q&A entries show E06230 and its fix:
Found a problem?
If EK9 reported E06230 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.