Change Signature

Change Signature changes a function's parameters - adds, removes or reorders them - and every call to it with them. Here unusedOneOfTwo never uses notUsed, so EK9 refuses it (E08091, explained in the Hovers panel); removing it must take its argument out of the call in describeReady too. To play it in the IDE: Help > Lessons > Refactoring…, or ek9 -ide -lesson change-signature.

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 E08091: parameter is declared but never used in the function/method body

#!ek9
defines module error.e08091.bad

  defines function

    unusedSingleParam()
      ->
        ignored as String
      <- result as String: "done"

    unusedOneOfTwo()
      ->
        used as String
        notUsed as Integer
      <- result as String: used

    describeReady()
      <- rtn as String: unusedOneOfTwo("ready", 3)

    usedParam()
      -> input as String
      <- result as String: input

    abstractBase() as abstract
      -> input as String
      <- result as String?

Step 1: Where it is

Put the caret on unusedOneOfTwo, on line 11.

The EK9 IDE once this is done: Put the caret on unusedOneOfTwo, on line 11

Step 2: Change Signature

Choose Refactor > Change Signature…

The EK9 IDE once this is done: Choose Refactor > Change Signature…

Choose notUsed in the parameters, then Remove, then Preview.

The EK9 IDE just before choosing Preview: Choose notUsed in the parameters, then Remove, then Preview

Step 3: Preview and apply

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

The EK9 IDE just before choosing Apply: The preview shows every change the refactoring makes; then the IDE formats each file it changed

The result

That is Change Signature: notUsed is gone from unusedOneOfTwo, and its argument from the call in describeReady. The error left - ignored, in unusedSingleParam - is the same refactoring: try it yourself (nothing calls it, so only its declaration changes). Cmd+F6 opens it (Ctrl+F6 elsewhere); AI assistants use the ek9_change_signature tool.

The EK9 IDE when the lesson has finished

Where this lesson comes from