E07570: must return a String

Category: E07xxx Full resolution · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: MUST_RETURN_STRING · All error codes

What went wrong

A function or method is required to return String but returns a different type.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 779 (Why must certain operators return a value in EK9?)

How to fix it

  1. Change return type to String

Common causes

  • String conversion operator ($) returning wrong type
  • Text formatting function type mismatch

See also

  • E07570: String return required (this error)
  • E07520: Boolean return required
  • E07550: Integer return required

Examples

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

Fails with E07570: must return a String

#!ek9
defines module error.e07570.bad

  defines class

    Label
      text <- "label"

      //'$' converts to a String
      default operator ?

      operator $ as pure
        <- rtn as Integer: length text

Fixed: Return a String

#!ek9
defines module error.e07570.good

  defines class

    Label
      text <- "label"

      default operator ?

      operator $ as pure
        <- rtn as String: text

Questions and answers

These Q&A entries show E07570 and its fix: