E01072: 'return' does not exist in EK9 - declare return values with '<-' and compiler ensures all paths initialize
What went wrong
The 'return' statement does not exist in EK9.
Worked examples
Compilable examples demonstrating this error and the correct fix:
Rationale
EK9 excludes early returns based on critical security evidence:
- Apple SSL Bug (2014, CVE-2014-1266): Duplicate 'goto fail' bypassed SSL validation
- An early exit between acquiring a resource and releasing it skips the release
- Multiple return points make code harder to reason about
How to fix it
Declare return variable with '<-' and let compiler enforce all paths initialize it. Use guards for conditional processing.
See also
- E01070: 'break' not supported (use stream pipelines with 'head')
- E01071: 'continue' not supported (use stream pipelines with 'filter')
- E01072: 'return' not supported (use return declarations)
- E01073: 'null' not supported (use tri-state semantics)
- E01074: semicolons not needed (indentation-based syntax)
https://ek9.io/flowControl.html#guard_decision_tree https://ek9.io/forAI.json#$.excludedFeatures.features[?(@.keyword=="return")]
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E01072: 'return' does not exist in EK9 - declare return values with '<-' and compiler ensures all paths initialize
#!ek9 defines module error.e01072.bad defines constant LIMIT <- 100 defines function //Return with a value tryReturnWithValue() -> text as String <- result as String: String() return text //Return without a value (void return) tryReturnWithoutValue() -> message as String if message? Stdout().println(message) return //Early return in conditional tryEarlyReturn() -> name as String <- result as String: String() if not name? return "anonymous" //Return inside a for loop tryReturnInForLoop() -> items as List of Integer <- result as Integer: Integer() for item in items if item > LIMIT return item //Return inside a while loop tryReturnInWhileLoop() -> items as List of Integer <- result as Integer: Integer() iter <- items.iterator() while iter.hasNext() item <- iter.next() if item > LIMIT return item
Fixed: Assign the returning variable where each return was
#!ek9 defines module error.e01072.good.fix defines constant LIMIT <- 100 defines function //Return with a value tryReturnWithValue() -> text as String <- result as String: String() result: text //Return without a value (void return) tryReturnWithoutValue() -> message as String if message? Stdout().println(message) //Early return in conditional tryEarlyReturn() -> name as String <- result as String: String() if not name? result: "anonymous" //Return inside a for loop tryReturnInForLoop() -> items as List of Integer <- result as Integer: Integer() for item in items if item > LIMIT result :=? item //Return inside a while loop tryReturnInWhileLoop() -> items as List of Integer <- result as Integer: Integer() iter <- items.iterator() while iter.hasNext() item <- iter.next() if item > LIMIT result :=? item
Fixed: Declare the returning variable and assign it; the compiler checks every path
#!ek9 defines module error.e01072.good defines function describe() -> name as String <- description as String: "anonymous" if name? description: "named " + name firstOver() -> items as List of Integer threshold as Integer <- found as Integer: Integer() for item in items if item > threshold found :=? item
Questions and answers
These Q&A entries show E01072 and its fix:
- Q19: Can I use EK9 for scripting?
- Q49: How do I define a function in EK9?
- Q61: How do if/else statements work in EK9?
- Q62: How do I chain multiple if/else-if conditions?
- Q63: How does switch/case work in EK9?
- Q68: Can switch return a value (switch as expression)?
- Q71: How do pattern matching and regex work in switch?
- Q72: What are given/when — alternative switch keywords?
- Q73: How does exhaustive enum switch work?
- Q74: How do guard variables work in if statements?
- Q75: How do guard variables work in switch statements?
- Q76: How do guard variables work in for loops?
- Q78: How do guard variables work in try blocks?
- Q80: Can a for-range loop return a value (for-range as expression)?
- Q81: Can while and do-while loops return values (loop expressions)?
- Q82: Can a for-in loop return a value (for-in as expression)?
- Q83: Which control flow constructs can be used as expressions in EK9?
- Q144: Why doesn't EK9 have break, continue, or return statements?
- Q145: How do I exit a loop early or skip iterations in EK9?
- Q146: How do I structure functions without early return in EK9?
- Q147: Why doesn't EK9 have switch fallthrough and how do I group cases?
- Q148: How do I migrate complex control flow from Java or Python to EK9?
- Q274: Why does AI generate return statements in EK9?
- Q597: How do function parameters work in EK9?
- Q748: How do I migrate Swift control flow patterns to EK9?
- Q997: How do I write a function that returns a value in EK9?
- Q998: Show me different function signatures in EK9 — no params, one param, multiple params, with return.
- Q999: Write an EK9 function that takes a list of integers and returns the sum of all positive values.
- Q1006: I'm a Python developer. What are the key differences I need to know for EK9?
- Q1025: How do := and :=? work differently as guard operators in EK9 control flow?
- Q1032: My function uses return to send back a value. How do I fix it?
- Q1153: Assign different labels based on a score using if/else.
- Q1168: Write a pure validation function that checks if an age is between 0 and 150.
- Q1196: How do I guard a date lookup so the block only runs if a date is found?
- Q1267: How do I find the first matching item in a list without break or return in EK9?