E07670: operator not supported, only +=, -=, :^:, :~: and ? are supported

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: SERVICE_OPERATOR_NOT_SUPPORTED · All error codes

What went wrong

A service declares an operator that does not map to an HTTP method. A service operator IS an HTTP endpoint, so only five operators are allowed, each meaning one verb: '+=' (POST - an add to the collection), '-=' (DELETE), ':^:' (PUT), ':~:' (PATCH) and '?' (HEAD). There is one form each: '+' and '-' are not service operators - write '+=' and '-='. Anything else needs a named method with its verb ('byId() as GET for :/{id}').

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1322 (Why does EK9 reject some operators inside a service de...)

How to fix it

  1. Use one of the five operators for the verb you mean - '+=' rather than '+', '-=' rather than '-' (the MCP editing tools rewrite these two for you)
  2. Or declare a named method with its verb: 'name() as GET for :/path'
  3. Move work that is not an endpoint to helper classes

The [EXAMPLE] section below shows '<~>' and '+' declared on a service, and the same service with '+=' (POST) and a named GET method.

See also

  • E07670: unsupported service operator (this error)
  • E07620: operator not defined for type

Examples

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

Fails with E07670: operator not supported, only +=, -=, :^:, :~: and ? are supported

#!ek9
defines module error.e07670.bad

  defines class

    TextResponse with trait of HTTPResponse
      text as String?

      default private TextResponse()

      TextResponse()
        -> body as String
        this.text: body

      override contentType() as pure
        <- rtn as String: "text/plain"

      override content()
        <- rtn as Bytes: Bytes().withUtf8(text)

      override status() as pure
        <- rtn as Integer: 200

      default operator ?

  defines service

    Addresses for :/addresses open

      //Only +=, -=, :^:, :~: and ? map to HTTP verbs
      operator <~> for :/
        -> incoming as String :=: CONTENT
        <- response as HTTPResponse: TextResponse(incoming)

      //One form each: a service adds with '+=' (POST), never '+'
      operator + for :/add //wrong: write '+='
        -> incoming as String :=: CONTENT
        <- response as HTTPResponse: TextResponse(incoming)

Fixed: Use an operator that maps to an HTTP verb, or a named method

#!ek9
defines module error.e07670.good

  defines class

    TextResponse with trait of HTTPResponse
      text as String?

      default private TextResponse()

      TextResponse()
        -> body as String
        this.text: body

      override contentType() as pure
        <- rtn as String: "text/plain"

      override content()
        <- rtn as Bytes: Bytes().withUtf8(text)

      override status() as pure
        <- rtn as Integer: 200

      default operator ?

  defines service

    Addresses for :/addresses open

      //'+=' is POST
      operator += for :/
        -> incoming as String :=: CONTENT
        <- response as HTTPResponse: TextResponse(incoming)

      //Or a named method with its verb
      byId() as GET for :/{id}
        -> id as String
        <- response as HTTPResponse: TextResponse(`address ${id}`)

Questions and answers

These Q&A entries show E07670 and its fix:

Found a problem?

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