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.

2. 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.

3. Change the return variable type initialisation.

   <- rtn as String?  becomes  <- rtn as String: String()
   Reason: return values must always be initialised. String() creates an unset String.

Each fix is one small change. Do not restructure the code or add features — just fix the errors.

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: generalist, quick, multiple, errors, fix, minimal