E07030: 'default' of operators on a trait is not supported

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: DEFAULT_AND_TRAIT · All error codes

What went wrong

You're trying to use 'default operator' in a TRAIT, but traits don't support auto-generated operators.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 116 (What does 'default operator' generate?)

How to fix it

  1. Move default operator to implementing class
  2. Or define abstract operator signature in trait
  3. Traits define interfaces, classes provide implementations

Common causes

  • Treating trait like a class
  • Trying to provide default behavior for operators
  • Misunderstanding trait vs class capabilities

See also

  • E07030: default operator in trait (this error)
  • E07040: 'by' delegation in trait
  • E07070: constructor in trait

Examples

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

Fails with E07030: 'default' of operators on a trait is not supported

#!ek9
defines module error.e07030.bad

  defines trait

    Describable
      describe() as pure abstract
        <- rtn as String?

      //A trait has no fields to generate an operator from
      default operator $

Fixed: Write the trait's operator, over the trait's own methods

#!ek9
defines module error.e07030.good

  defines trait

    Describable
      describe() as pure abstract
        <- rtn as String?

      //Give the trait's operator a body, written over the trait's own methods
      operator $ as pure
        <- rtn as String: describe()

Questions and answers

These Q&A entries show E07030 and its fix: