Make Abstract

Change Modifier > Make Abstract adds 'as abstract' to a class, record, component or function directly - an alternative to implementing every outstanding member. Here C7 extends C1, which is abstract, but implements neither of C1's abstract members, so EK9 refuses it - E07130, explained in the Hovers panel. To play it in the IDE: Help > Lessons > Refactoring…, or ek9 -ide -lesson make-abstract.

The EK9 IDE as the lesson opens: the code to read and, in the Hovers panel, its error explained

Start from

The code the lesson starts from: copy it into a file of your own and follow the steps.

Fails with E07130: not declared abstract but still has abstract methods/operators

#!ek9
defines module error.e07130.bad

  defines trait

    //Create a trait with one concrete method and some abstract methods/operators
    T1
      concreteMethod()
        -> count as Integer
        <- rtn as Boolean: count?

      tMethod()
        -> amount as Float
        <- rtn as Boolean?

      operator + as pure
        -> amount as Float
        <- rtn as Float?

  defines class
    //This is valid as a method is abstract and so this class is also abstract
    C1 as abstract
      default C1()

      aMethod() as abstract
        -> count as Integer
        <- rtn as Boolean?

      //A concrete method
      bMethod()
        -> count as Integer
        <- rtn <- true

      //Note that in class, we have to state that this is abstract (unlike traits)
      operator - as pure abstract
        -> amount as Float
        <- rtn as Float?

    //This too is valid
    C2 with trait of T1 as abstract
      default C2()

    //But this is Ok because it marked as abstract
    C3 extends C1 as abstract
      default C3()

    //This is an error, just marking as open is not enough, this is abstract
    //But it is picked up in the SYMBOL_DEFINITION phase and is checked elsewhere.
    //So it is commented out here - but left in place to highlight it is not missing
    <!-
    C4 as open
      default C4()

      aMethod() as abstract
        -> count as Integer
        <- rtn as Boolean?
    -!>

    //This is an error, this is abstract because T1.tMethod is abstract
    C5 with trait of T1
      default C5()

    //This is an error, this is abstract because T1.tMethod is abstract and marking as open makes not difference.
    //So even though the operator is now implemented, this not enough.
    C6 with trait of T1 as open
      default C6()

      override operator + as pure
        -> amount as Float
        <- rtn as Float: amount

    //Another error because C1 is abstract and C7 has not implemented and so must also be marked as abstract.
    C7 extends C1
      default C7()

    //So still an error because the operator is still unimplemented.
    C8 extends C1
      default C8()

      //We now override and implement
      override aMethod()
        -> count as Integer
        <- rtn as Boolean: true

    //So still an error because the aMethod is still unimplemented.
    C9 extends C1
      default C9()

      //We now override and implement
      override operator - as pure
        -> amount as Float
        <- rtn as Float: 0.0

    //Now this will be OK, as everything is implemented.
    C10 extends C1
      default C10()

      override aMethod()
        -> count as Integer
        <- rtn as Boolean: true

      override operator - as pure
        -> amount as Float
        <- rtn as Float: 0.0

    //This is now OK because all abstract method are implemented.
    C11 with trait of T1
      default C11()

      override tMethod()
        -> amount as Float
        <- rtn as Boolean: true

      override operator + as pure
        -> amount as Float
        <- rtn as Float: amount

Step 1: Where it is

Put the caret on C7, on line 73.

The EK9 IDE once this is done: Put the caret on C7, on line 73

Step 2: Make Abstract

Right-click it - or choose Refactor > Refactor This… - and choose Change Modifier > Make Abstract.

The EK9 IDE once this is done: Right-click it - or choose Refactor > Refactor This… - and choose Change Modifier > Make Abstract

Step 3: Preview and apply

The preview shows every change the refactoring makes; then the IDE formats each file it changed. Choose Apply.

The result

That is Make Abstract: C7 now says 'as abstract', so it compiles without implementing C1's members itself - whatever extends C7 still owes them. C5, C8 and C9 are left, fixable the same way or by implementing the missing members (Implement Methods…, which fixes C6 the same error asks for); Make Open, Make Closed and Make Concrete sit beside it in the same right-click Change Modifier submenu. AI assistants use the ek9_make_abstract tool.

The EK9 IDE when the lesson has finished

Where this lesson comes from