E05160: 'super is not 'pure', requires this definition not to be marked as 'pure'

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

What went wrong

The parent method/function is NOT marked pure, but your override IS marked 'pure'. You cannot add purity constraints that the parent doesn't guarantee.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 562 (Why can't I add 'as pure' to an override when the parent ...)
  • ek9 -q 56 (What are higher-order functions and why should I use them?)

How to fix it

Drop the extra purity, or move the guarantee up to the parent where callers can actually rely on it.

With tooling, ek9_query_purity_impact (the file and the error line) shows the contract group read-only, so you can see which other overrides share it before touching anything. ek9_fix_purity_contract with mode 'remove-pure-from-override' then applies the change - use dryRun:true first - cascading to further-derived overrides automatically.

By hand:

  1. Remove 'as pure' from your override method
  2. Or make the parent method pure (if you control it) - every override must then be pure as well, per E05150
  3. Accept that this method may have side effects

Rationale

Callers using Parent type expect process() MAY have side effects. If child adds 'pure' but is accessed through parent reference, caller might incorrectly rely on purity that isn't guaranteed.

Common causes

  • Adding purity to "improve" the override
  • Parent design doesn't support purity (has side effects)
  • Not realizing purity must come from parent

See also

  • E05160: override adds purity parent lacks (this error)
  • E05150: override removes purity parent requires (opposite)
  • E05290: parents disagree on purity (a super and a trait, or two traits)

Examples

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

Fails with E05160: 'super is not 'pure', requires this definition not to be marked as 'pure'

#!ek9
defines module error.e05160.bad

  defines function

    //Super function is NOT pure
    Function1() as open
      -> text as String
      <- rtn as Boolean: text?

    //ERROR: Cannot add purity when super is not pure
    InvalidFunction6() is Function1 as pure
      -> text as String
      <- rtn as Boolean: text?

Fixed: Match the super function's purity: not pure when it is not

#!ek9
defines module error.e05160.good

  defines function

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

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

Questions and answers

These Q&A entries show E05160 and its fix: