E01092: '?' tests whether a value is set - an assignment target cannot carry it

Category: E01xxx Parsing and excluded constructs · Reported in phase: PARSING · Classification: IS_SET_ON_ASSIGNMENT_TARGET · All error codes

What went wrong

A '?' sits between a variable and an assignment: 'label? := value'. '?' is the isSet operator - 'label?' TESTS whether label has a value. A test is not something a value can be assigned to, so the target of the assignment is the variable itself.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 79 (What is the assign-if-unset operator :=? in EK9?)
  • ek9 -q 1039 (When do I use <- and when do I use :=? to set a variable safely?)

How to fix it

Assign to the variable itself:

  • label? := value --> label := value

To assign ONLY while the variable has no value yet, use ':=?':

  • label? := value --> label :=? value

To test it first, put the '?' in the condition:

  • if label?

Common causes

  • Meaning "assign if unset" - that is ':=?'
  • Carrying 'x ??= y' or 'x?.y = z' habits from other languages
  • Reading the '?' of a declaration ('name as String?') as part of the name

See also

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E01092: '?' tests whether a value is set - an assignment target cannot carry it

#!ek9
defines module error.e01092.bad

  defines function

    labelled()
      <- label as String?
      label? := "first"

Fixed: Assign to the variable itself; ':=?' assigns only while it has no value

#!ek9
defines module error.e01092.good

  defines function

    labelled()
      <- label as String?
      label :=? "first"