E07240: non web service methods cannot be marked with the 'protected' access modifier
What went wrong
A non-web method in a SERVICE is marked 'protected'. Services don't support protected visibility for internal methods.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 1316 (Why can't a helper method in an EK9 service be marked...)
Rationale
Services are entry points - the protected visibility concept (subclass access) doesn't apply to service architectures.
How to fix it
- Use 'private' for internal methods
- Or leave public (default)
The [EXAMPLE] section below shows a 'protected' helper in a service and the same helper made 'private'.
Common causes
- Habit from class design
- Trying to hide helper methods
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07240: non web service methods cannot be marked with the 'protected' access modifier
#!ek9 defines module error.e07240.bad defines service Site for :/site open index() as GET for :/ <- response as HTTPResponse? body <- pageBody() response: (body) with trait HTTPResponse override content() <- rtn as Bytes: Bytes().withUtf8(body) override status() as pure <- rtn as Integer: 200 override contentType() as pure <- rtn as String: "text/plain" override cacheControl() as pure <- rtn as String: "no-cache" override contentLanguage() as pure <- rtn as String: "en" default operator ? //A service is never extended, so 'protected' means nothing here protected pageBody() <- rtn as String: "welcome"
Fixed: Make the helper private
#!ek9 defines module error.e07240.good defines service Site for :/site open index() as GET for :/ <- response as HTTPResponse? body <- pageBody() response: (body) with trait HTTPResponse override content() <- rtn as Bytes: Bytes().withUtf8(body) override status() as pure <- rtn as Integer: 200 override contentType() as pure <- rtn as String: "text/plain" override cacheControl() as pure <- rtn as String: "no-cache" override contentLanguage() as pure <- rtn as String: "en" default operator ? //A helper only the service calls is private private pageBody() <- rtn as String: "welcome"
Questions and answers
These Q&A entries show E07240 and its fix:
Found a problem?
If EK9 reported E07240 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.