E05140: function signature does not match 'super' function

Category: E05xxx Explicit type symbol definition · Reported in phase: FULL_RESOLUTION · Classification: FUNCTION_SIGNATURE_DOES_NOT_MATCH_SUPER · All error codes

What went wrong

When extending a function (with 'is' or 'extends' - the two are the same), the parameters must match the parent function's exactly: the same count, the same types, in the same order. Only the return type may differ, and only by being narrower (covariant).

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 592 (What happens if a function extension has a signature mi...)
  • ek9 -q 594 (What are the rules for when a function can or cannot be...)
  • ek9 -q 588 (How do functions extend other functions in EK9?)

How to fix it

  1. Check parent function's signature exactly
  2. Match parameter count, order, and types
  3. Match return type (can be covariant - more specific is OK)

Signature matching rules

  • Parameter count: must be identical
  • Parameter types: must be identical (a wider type, such as Any for String, is a mismatch too)
  • Return type: must be identical (or covariant - narrower is OK)
  • Parameter names: don't need to match (names are local)

Common causes

  • Wrong parameter type (Integer vs String)
  • Missing or extra parameters
  • Return type mismatch
  • Widening a parameter type in the extending function

See also

  • E05140: function signature mismatch (this error)
  • E05100/E05110: method override signature issues (class context)

Examples

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

Fails with E05140: function signature does not match 'super' function

#!ek9
defines module error.e05140.bad

  defines function

    //Base function expecting String parameter
    Function1() as open
      -> text as String
      <- rtn as Boolean: text?

    //Abstract function expecting String parameter
    AbstractFunction1() as abstract
      -> text as String
      <- rtn as Boolean?

    //ERROR: Parameter type mismatch (Integer vs String)
    InvalidFunction1() is Function1
      -> count as Integer
      <- rtn <- true

    //ERROR: Parameter type mismatch (Float vs String)
    InvalidFunction2() is AbstractFunction1
      -> amount as Float
      <- rtn <- true

Fixed: A function that extends another takes exactly the same parameters

#!ek9
defines module error.e05140.good

  defines function

    Function1() as open
      -> text as String
      <- rtn as Boolean: text?

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

    //The same signature
    ValidFunction1() is Function1
      -> text as String
      <- rtn as Boolean: text?

    //The same signature - it may stay abstract
    ValidFunction2() is AbstractFunction1 as abstract
      -> text as String
      <- rtn as Boolean?