E07902: a plain "..." String literal is required here - a backtick String is not a compile-time literal

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

What went wrong

A String EK9 reads at compile time is written as a backtick String. A constant, a constraint, a text's language (defines text for "de") and a service parameter's name (HEADER "X-Token") are all compile-time values, so each must be a plain "..." literal. A backtick String - interpolated or not - is not a compile-time literal. Before this error its raw source text became the value: a constant held `Welcome to ${APP_NAME}` with its backticks, and a header was looked up by a name that included them.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1394 (Why must a constant's String be written with double quotes?)

How to fix it

Write the value with double quotes:

  • GREETING <- `Welcome` --> GREETING <- "Welcome"
  • defines text for `de` --> defines text for "de"
  • token as String :=: HEADER `X` --> token as String :=: HEADER "X"

Text built by interpolation belongs where it is evaluated - a function, a method, or a local variable - not in a constant.

Common causes

  • Using backticks for every String out of habit
  • Trying to build a constant from other constants with ${...}
  • A constraint written with an interpolated value to compare against

See also

Examples

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

Fails with E07902: a plain "..." String literal is required here - a backtick String is not a compile-time literal

#!ek9
defines module error.e07902.bad

  defines constant

    APP_NAME <- "Ledger"

    GREETING <- `Welcome to ${APP_NAME}`

    PLAIN_BACKTICK <- `no interpolation, still not a literal`

  defines type

    Code as String constrain as
      <> `x${APP_NAME}`

Fixed: Use a plain literal, and interpolate where it is evaluated

#!ek9
defines module error.e07902.good

  defines constant
    APP_NAME <- "Ledger"

  defines function

    //Interpolate where the text is evaluated
    greeting()
      <- rtn as String: `Welcome to ${APP_NAME}`

Questions and answers

These Q&A entries show E07902 and its fix:

Found a problem?

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