E07250: component methods cannot be marked with the 'protected' access modifier

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

What went wrong

A method in a COMPONENT is marked 'protected'. Components don't support protected visibility.

Worked examples

Compilable examples demonstrating this error and the correct fix:

How to fix it

  1. Use 'private' for internal methods
  2. Or use 'public' for external access
  3. Components don't support class inheritance patterns

Common causes

  • Treating component like regular class
  • Copy/paste from class code

See also

  • E07250: protected in component (this error)
  • E07240: protected in service

Examples

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

Fails with E07250: component methods cannot be marked with the 'protected' access modifier

#!ek9
defines module error.e07250.bad

  defines component

    Store
      fetch()
        -> key as String
        <- rtn as String: normalise(key)

      //A component is never extended, so 'protected' means nothing here
      protected normalise()
        -> key as String
        <- rtn as String: key.trim()

Fixed: Make it private (or public)

#!ek9
defines module error.e07250.good

  defines component

    Store
      fetch()
        -> key as String
        <- rtn as String: normalise(key)

      private normalise()
        -> key as String
        <- rtn as String: key.trim()

Questions and answers

These Q&A entries show E07250 and its fix:

Found a problem?

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