E07480: is not a function delegate
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
- Provide function delegate or lambda
- 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
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"))