E04060: not an aggregate type

Category: E04xxx Reference checks · Reported in phase: FULL_RESOLUTION · Classification: IS_NOT_AN_AGGREGATE_TYPE · All error codes

What went wrong

You're trying to call a method on something that isn't an object (class, record, or trait instance). Only aggregates have methods. Functions are callable but don't have methods you can invoke.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 830 (Why does EK9 reject non-aggregate types in certain contexts?)

Types with methods

  • Classes: have instance methods and operators
  • Records: have constructors and operators
  • Traits: have defined and default methods
  • Built-in types: String, Integer, List, Dict etc.

Types without methods

  • Functions: only callable via (), no dot-methods
  • Enumerations: no methods (enumValue.toString() won't work)

How to fix it

  1. Check what type your variable actually holds
  2. If it's a function, call it directly: fn() or result <- fn()
  3. If you need methods, ensure you're working with an aggregate type

Common causes

  • Confusing function reference with class instance
  • Using wrong variable (one holds function, expected class)
  • Thinking function is like a class with methods
  • Forgetting that function call result has methods, not the function itself

See also

  • E04060: calling method on non-aggregate (this error)
  • E50060: method doesn't exist on aggregate (METHOD_NOT_RESOLVED)

Examples

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

Fails with E04060: not an aggregate type

#!ek9
defines module error.e04060.bad

  defines function

    greeting()
      <- rtn as String: "hello"

    farewell()
      <- rtn as String: "goodbye"

    sortFunctions()
      stdout <- Stdout()

      //'sort' orders values by their '<=>' - a function has none
      cat [greeting, farewell] | sort > stdout

Fixed: Sort values that have a '<=>': call the functions first, then sort what they return

#!ek9
defines module error.e04060.good

  defines function

    greeting()
      <- rtn as String: "hello"

    farewell()
      <- rtn as String: "goodbye"

    sortMessages()
      stdout <- Stdout()
      cat [greeting, farewell] | call | sort > stdout

Questions and answers

These Q&A entries show E04060 and its fix: