My code has three errors. Fix them all with minimal changes.
← Getting Started · Ref: Q1054
Here are the three fixes:
1. Change := to <- on line where greeting is first created.
greeting := "Hello" becomes greeting <- "Hello" Reason: := updates existing variables. <- creates new ones. Using := on a new name is E50001 (not resolved).
2. Recommendation (not a compile error): add 'as pure' to the function that has no side effects.
formatName() becomes formatName() as pure Reason: functions that only compute from inputs should be pure - the code compiles without it, but pure gives the compiler and readers a guarantee.
3. Change the return variable type initialisation.
<- rtn as String? becomes <- rtn as String: String() Reason: a return value must be initialised on every path. Without the initialiser the compiler reports E08050 (return value is not always initialised) because the if has no else. String() creates an unset String.
Each fix is one small change. Do not restructure the code or add features — just fix the errors (fixes 1 and 3) and apply the recommendation (fix 2) only if asked.
Example
defines module qa.gettingstarted.multistepfix defines function formatName() as pure -> name as String <- rtn as String: String() if name? rtn := "Dear " + name defines program MultiStepFixDemo() stdout <- Stdout() greeting <- "Hello" stdout.println(greeting) formatted <- formatName("Alice") stdout.println(formatted)
Common mistakes
E50001 — Use <- to create a new variable. The := operator expects the variable to already exist.
Incorrect:
greeting := "Hello"
Correct:
greeting <- "Hello"
Other ways to ask this
- Fix these multiple errors in my EK9 code
- Quick fix: several mistakes in one function
- Correct all the problems in this code at once
Coming from another language?
EK9 error fixing is incremental. Fix one error at a time. The compiler will guide you to the next one.
Keywords: multiple, quick, generalist, minimal, fix, errors