My code uses := for the first variable. Fix it with the minimum change.

← Getting Started · Ref: Q1029

Change := to <-. That is the only change needed.

BEFORE (wrong):

  greeting := "Hello"

AFTER (fixed):

  greeting <- "Hello"

The <- operator declares a new variable. The := operator updates an existing one. If the variable does not exist yet, you must use <- to create it.

For subsequent assignments to the same variable, := is correct:

  greeting <- "Hello"     first time: <- to create
  greeting := "Hi there"  after: := to update

Example

defines module qa.gettingstarted.quickfixes

  defines program

    QuickFixDemo()
      stdout <- Stdout()

      //Correct: <- to declare
      greeting <- "Hello"
      stdout.println(greeting)

      //Correct: := to update
      greeting := "Hi there"
      stdout.println(greeting)

Common mistakes

E50001 — Use <- to declare a new variable. Using := on a name that does not exist yet means it cannot be resolved.

Incorrect:

      greeting := "Hello"

Correct:

      greeting <- "Hello"
Other ways to ask this
  • Quick fix: I used := instead of <- to declare a variable
  • What is the minimal fix when := is used before <-?
  • I get an error on my first assignment. What is the simplest fix?

Coming from another language?

The fix is always minimal: change := to <- for the first use of a variable.

Keywords: generalist, quick, assign, fix, minimal, declare