E01085: suffix operator used in prefix position - place AFTER expression

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

What went wrong

You're using a SUFFIX operator in PREFIX position. SUFFIX operators must come AFTER the expression they operate on.

EK9's main suffix operator:

  • ? (isSet) - checks if value is set/valid: value?

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 794 (Why does EK9 care about operator placement (prefix vs suf...)

Common causes

  • Coming from languages with prefix null checks (isset(), is_null())
  • Confusing with ternary operator syntax from other languages
  • Pattern matching habits from functional languages

How to fix it

Move the ? operator to AFTER the expression:

  • ?value --> value?
  • ?object.property --> object.property?

See also

Examples

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

Fails with E01085: suffix operator used in prefix position - place AFTER expression

#!ek9
defines module error.e01085.bad

  defines function

    isKnown()
      -> name as String
      <- rtn as Boolean: ?name

Fixed: Put the suffix operator after the expression: name?

#!ek9
defines module error.e01085.good

  defines function

    isKnown()
      -> name as String
      <- rtn as Boolean: name?

Questions and answers

These Q&A entries show E01085 and its fix: