E04070: as it is not 'template/generic' in nature

Category: E04xxx Reference checks · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: NOT_A_TEMPLATE · All error codes

What went wrong

You're providing type parameters (e.g., 'of String') to a type that isn't generic/parameterized. Only generic types accept type parameters. Non-generic types have fixed structure and don't need/accept 'of' clauses.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1309 (Why does EK9 reject 'of TypeName' on a non-generic typ...)

[GENERIC VS NON-GENERIC] Generic types (accept 'of' clause):

  • List of T, Dict of (K, V), Optional of T, Result of (T, E)
  • User-defined: 'Container of type T' syntax

Non-generic types (NO 'of' clause):

  • String, Integer, Float, Boolean, Character
  • Custom classes without 'of type T' declaration

How to fix it

  1. Check if the type is generic (look for 'of type T' in its definition)
  2. If non-generic, remove the 'of TypeName' clause
  3. If you need generic behavior, create a generic class or use built-in generic

Common causes

  • Confusing class name with generic type
  • Copy-pasting from generic code to non-generic context
  • Assuming all collection-like classes are generic

See also

  • E04070: using 'of' on NON-generic type (this error)
  • E04080: MISSING 'of' on generic type (opposite problem)
  • E06020: wrong NUMBER of type parameters on generic

Examples

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

Fails with E04070: as it is not 'template/generic' in nature

#!ek9
defines module error.e04070.bad

  defines function

    aNonGenericFunction()
      -> text as String
      <- rtn as String: text

    badClassUseOfNonGeneric()
      //Failure 1
      notActuallyGeneric <- Date() of String

      //Failure 2
      alsoNotGeneric as Date of String?

    badFunctionUseOfNonGeneric()
      //Failure 3
      handler <- () is aNonGenericFunction of Date as function

      //Failure 4
      functionName as aNonGenericFunction of String?

Fixed: Only a generic type or function takes 'of': use Date and the function as they are

#!ek9
defines module error.e04070.good

  defines function

    aNonGenericFunction()
      -> text as String
      <- rtn as String: text

    classUse()
      today <- Date()
      names <- List() of String
      require today? and names?

    functionUse()
      <- rtn as String: aNonGenericFunction("plain")

Questions and answers

These Q&A entries show E04070 and its fix:

Found a problem?

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