E07300: declaration supporting 'uninitialised' is not needed
What went wrong
You've explicitly declared something as 'uninitialized' where it is not needed. The '?' in 'name as String?' declares a variable WITHOUT a value, so it has no place where a value is always there:
- on a PARAMETER: '-> text as String?' - an incoming parameter always arrives with its argument
- beside a VALUE: 'name as String? : "x"' (or ':=', '=', ':~:') - the declaration gives the variable a value, so the '?' did nothing; it compiled to exactly the code the declaration compiles to without it
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 827 (Why does EK9 reject the ? modifier on function parameters?)
Rationale
EK9 handles uninitialized state through tri-state semantics. A variable declared with 'as TypeName?' starts without a value and the compiler proves it is assigned before use; one declared with a value starts with that value. A '?' that says both is a contradiction a reader cannot resolve - so the compiler does not accept it.
How to fix it
- Remove the '?': '-> text as String' / 'name as String: "x"'
- If the variable should really start WITHOUT a value, remove the value instead: 'name as String?'
Common causes
- Over-explicit declarations
- Reading '?' as "nullable", as in Kotlin or C#
- Confusion about initialization rules
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07300: declaration supporting 'uninitialised' is not needed
#!ek9 defines module error.e07300.bad defines class Holder prop as String? : "p" default operator ? defines function returnWithAValue() <- rtn as String? : String() rtn: "x" localViaAssign() <- rtn as String: String() label as String? := "x" rtn: label localViaEquals() <- rtn as String: String() label as String? = "x" rtn: label localViaMerge() <- rtn as String: String() label as String? :~: "x" rtn: label //Both forms that ARE meant - a value, or no value yet - stay as they were. stillFine() <- rtn as String: String() label as String: "x" pending as String? pending: label rtn: pending
Fixed: Write '?' only where there is no value yet
#!ek9 defines module error.e07300.good defines function //A value: no '?' withAValue() <- rtn as String: "x" //No value yet: the '?' says so, and it is assigned later noValueYet() <- rtn as String: String() pending as String? pending: "x" rtn: pending
Questions and answers
These Q&A entries show E07300 and its fix: