Why does EK9 reject the ? modifier on function parameters?
← Code Quality · Ref: Q827
EK9 requires function parameters to always be initialised. Declaring a parameter with ? (potentially unset) is not needed because the caller must always provide a value.
THE RULE
Parameters cannot use the ? unset modifier:
process()
-> input as String? // ERROR: E07300
Parameters are always set by the caller. The ? modifier would be misleading.
THE FIX
Remove the ? modifier:
process()
-> input as String // CORRECT: always initialised
WHY THIS MATTERS
EK9 pushes for everything to be initialised. Parameters are provided by callers, so they are always set when the function body executes. Allowing ? on parameters would create false optionality.
See Q310 for code quality. See Q126 for function patterns.
Example
defines module qa.quality.null.not.needed defines function processInput() as pure -> input as String <- rtn as String: `Processed: ${input}` defines program NullNotNeededDemo() stdout <- Stdout() result <- processInput("hello") stdout.println(result)
Common mistakes
E07300 — Function parameters are always provided by the caller and cannot be unset. Remove the ? modifier. See ek9 -h E07300 for details.
Incorrect:
-> input as String?
Correct:
-> input as String
Other ways to ask this
- What is E07300 DECLARED_AS_NULL_NOT_NEEDED?
- Why can't I declare a parameter as potentially unset in EK9?
- How does EK9 enforce parameter initialisation?
Coming from another language?
Java: parameters are always non-null unless explicitly @Nullable. Kotlin: parameters can be nullable with ?. Rust: parameters are always initialised. Go: parameters always have zero values. EK9: parameters are always initialised — ? modifier not allowed.
Keywords: null, unset, E07300, optional, initialised, declared, parameter