E07480: is not a function delegate

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

What went wrong

The context expects a function delegate (callable), but you provided something that isn't callable.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 942 (How do I pass a function as a parameter in EK9?)

How to fix it

  1. Provide function delegate or lambda
  2. Use function reference

The [EXAMPLE] section below shows a generic's 'T' called as if it were a function, and a parameter declared as a function type ('check as Check') that can be called.

Common causes

  • Passing value instead of function
  • Wrong type

See also

  • E07480: non-callable where callable expected (this error)
  • E07490: function missing return

Examples

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

Fails with E07480: is not a function delegate

#!ek9
defines module error.e07480.bad

  defines class

    <?-
      A totally un-constrained generic type where T could be anything (as long as it has the ? operator).
      So pretty much a normal generic type. But in this case I plan to use T with a function.
    -?>
    UnConstrained of type T
      default UnConstrained()

      default UnConstrained()
        -> item as T

      call() as pure
        ->
          item as T
          input as String
        <- rtn as Boolean: item(input)

      check() as pure
        -> item as T
        <- rtn as Boolean: item?

      //But this you cannot do, you cannot use T as both a possible aggregate and a possible function delegate.

  defines function

    <?-
      Function can be used directly or as a signature for polymorphism.
    -?>
    SomeFunction() as open
      -> text as String
      <- rtn as Boolean: text?

    <?-
      Extend SomeFunction and alter implementation.
    -?>
    AnotherFunction is SomeFunction
      -> text as String
      <- rtn as Boolean: true

    <?-
      Higher order function that returns 'SomeFunction', but actually gives a Function that extends 'SomeFunction'.
    -?>
    getSomeFunction()
      <- rtn as SomeFunction: AnotherFunction

    <?-
      Now strangely this will work, because a Function can be checked for non-nullness with a build in operator of ?
      So it really only makes sense to have generics that are collections that can hold things like functions.
      Unlike classes where it is possible to undertaken operations using the 'T'.
    -?>
    UseOfGenericClassWithFunctionDemo1()
      demo <- UnConstrained() of SomeFunction

      result1 <- demo.check(SomeFunction)
      require result1

      //Call a higher function to return a function.
      result2 <- demo.check(getSomeFunction())
      require result2

Fixed: Call a value whose type is a function

#!ek9
defines module error.e07480.good

  defines class

    Checker
      //check is a function delegate, so it can be called
      run()
        ->
          check as Check
          input as String
        <- rtn as Boolean: check(input)

  defines function

    Check() as abstract
      -> text as String
      <- rtn as Boolean?

    notEmpty() is Check
      -> text as String
      <- rtn as Boolean: text?

  defines program

    RunCheck()
      stdout <- Stdout()
      stdout.println($Checker().run(notEmpty, "Steve"))

Found a problem?

If EK9 reported E07480 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.