E08180: not marked for injection nor initialised
What went wrong
A variable or property is declared with a type alone ('name as String'): no initial value, and no '?' to say it may start unset. Give it a value, declare it 'name as String?' and assign it later, or (a component) mark it for injection with '!'.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 22 (How do I declare a variable in EK9?)
- ek9 -q 1072 (Why does my abstract function get E08180 on the return...)
- ek9 -q 5 (How are EK9 source files structured?)
- ek9 -q 6 (How do I organize code into modules?)
- ek9 -q 16 (How does indentation work in EK9?)
- ek9 -q 25 (What is the promote operator?)
How to fix it
- Initialize it with a value ('name <- "Steve"', 'title as String: "untitled"')
- Or declare it unset with '?' and assign it later ('name as String?')
- Or, for a component, mark it for injection with '!' suffix
Common causes
- Forgot to initialize property
- Forgot to add '!' for injection
- Property intended to be set later but not marked
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08180: not marked for injection nor initialised
#!ek9 defines module error.e08180.bad defines record Book title as String default operator ? defines function greet() <- rtn as String? name as String rtn: "Hello " + name
Fixed: Give each declaration a value where it is declared
#!ek9 defines module error.e08180.good.fix defines record Book title as String: "untitled" default operator ? defines function greet() <- rtn as String? name <- "Steve" rtn: "Hello " + name
Fixed: Initialise it, or say it may be unset with ?
#!ek9 defines module error.e08180.good defines record Book title as String: "untitled" default operator ? defines function greet() <- rtn as String? name <- "Steve" rtn: "Hello " + name greetLater() -> known as Boolean <- rtn as String: "Hello" name as String? if known name: "Steve" else name: "friend" rtn: `${rtn} ${name}`
Questions and answers
These Q&A entries show E08180 and its fix:
- Q5: How are EK9 source files structured?
- Q6: How do I organize code into modules?
- Q16: How does indentation work in EK9?
- Q22: How do I declare a variable in EK9?
- Q25: What is the promote operator?
- Q28: How do I declare multiple variables at once?
- Q42: How does the Path type work in EK9 and what is it for?
- Q43: How do I escape characters in EK9 string interpolation?
- Q57: How can I change method behaviour on a class without subclassing?
- Q93: How do I define a class in EK9?
- Q94: How do I implement a constructor in EK9?
- Q104: Why does EK9 require explicit constructors for uninitialised properties?
- Q116: What does 'default operator' generate?
- Q139: When should I use try/catch vs Result for error handling?
- Q189: How do I convert an EK9 object to JSON?
- Q262: How do I implement the observer pattern in EK9?
- Q265: How do I implement a fluent API in EK9?
- Q266: How do I handle cross-cutting concerns in EK9?
- Q333: How do I manage transactions with try-with-resources in EK9?
- Q334: How do I add transactions with trait delegation in EK9?
- Q335: How do I use higher-order functions for transaction management?
- Q337: Can I use aspects for transactions like Spring @Transactional?
- Q338: How does EK9 prevent partial transaction commits?
- Q339: Which transaction management pattern should I use in EK9?
- Q340: Why are EK9 transaction patterns better for AI-generated code?
- Q670: Why must component fields be initialized or injected?
- Q692: How does EK9 ensure class fields are properly initialized?
- Q1072: Why does my abstract function get E08180 on the return value?
- Q1167: Write a function that returns a set or unset String depending on input.