E07180: 'default' of operators requires this type to have appropriate operator

Category: E07xxx Full resolution · Reported in phase: FULL_RESOLUTION · Classification: MISSING_OPERATOR_IN_THIS · All error codes

What went wrong

You're using 'default operator X' but this type doesn't have a required prerequisite operator that the default implementation depends on.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 260 (What types can be used as Dict keys?)

Operator dependency chain

A type defines its SAMENESS once - '<=>' (ordered) or '==' (equatable only) - and the other comparisons are GENERATED from it, never requested:

from '<=>':  ==  <>  <  <=  >  >=
from '==':   <>

So asking for '<' on a type with no '<=>' has nothing to be generated from (this error). Declare the '<=>' instead - generated with 'default' or written by hand - and '<' comes with it. Asking for '<' beside a '<=>' is E07181 (redundant). A bare 'default operator' over a field that cannot be ordered (a Dict, a List) gives '==' compared field by field and no ordering operators.

Semantics note

  • 'default operator ?' returns true only if ALL fields are set (one unset field is enough to make the whole object unset)
  • 'default operator #?'/'$'/'$$' return UNSET if object is completely empty
  • Custom '?' does NOT affect how 'default #?'/'$'/'$$' behave

How to fix it

  1. Replace 'default operator <' with 'default operator <=>' (or a hand-written '<=>')
  2. Or use 'default operator' to generate all at once
  3. For an ordering by some other rule, write a comparator function ('sort by f')

Common causes

  • Asking for '<' (or '<=', '>', '>=') instead of declaring '<=>'
  • Not aware that comparisons are generated from the type's sameness

See also

  • E07180: default operator missing prerequisite (this error)
  • E07190: default operator missing in super class
  • E07181: comparisons are generated from the sameness, never requested

Examples

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

Fails with E07180: 'default' of operators requires this type to have appropriate operator

#!ek9
defines module error.e07180.bad

  defines class

    Reading
      taken <- Time()

      //An ordering operator is generated from '<=>', and there is none
      default operator <

      default operator ?

Fixed: Default '<=>' instead: the comparisons come from it

#!ek9
defines module error.e07180.good

  defines class

    Reading
      taken <- Time()

      //Choose ordered sameness: '<', '<=', '>', '>=', '==' and '<>' are all generated from it
      default operator <=>

      default operator ?

Found a problem?

If EK9 reported E07180 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.