E08010: used before definition
What went wrong
You're using an identifier (variable name) BEFORE it has been declared, or inside its own initialiser ('total as Integer: total + 1'). EK9 requires declaration before use. A PROPERTY read in a property initialiser before its own initialiser has run is not this error - that is E08060, however it is spelt.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 632 (How does EK9 ensure variables are used only after they ar...)
- ek9 -q 688 (How does EK9 enforce variable initialization order?)
How to fix it
- Declare before use
- Check for typos in identifier name
- Ensure variable is in accessible scope
Common causes
- Typo in variable name (using undeclared identifier)
- Using variable before its declaration line
- Scope confusion (variable declared in different block)
- A local's initialiser reading the local itself
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08010: used before definition
#!ek9 defines module error.e08010.bad defines function greeting() <- rtn as String? rtn: salutation + ", World" salutation <- "Hello"
Fixed: Declare the variable before the line that reads it
#!ek9 defines module error.e08010.good defines function greeting() <- rtn as String? salutation <- "Hello" rtn: salutation + ", World"
Questions and answers
These Q&A entries show E08010 and its fix:
Found a problem?
If EK9 reported E08010 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.