E07156: 'locale' is reserved in a text construct - it names the auto-provided Locale field
What went wrong
'locale' is reserved inside a text construct. It names the Locale field that EK9 provides automatically on every text block, so it cannot be declared or reused as a name of your own.
How to fix it
- Rename your declaration to something else, 'userLocale' or 'language' for example (the [EXAMPLE] section below shows a parameter and a method named 'locale', and the same text with other names)
- To read the locale the text block was resolved for, just use the provided field - do not declare it: a text body can interpolate '${locale}'
Rationale
Every 'defines text ... for "<locale>"' block is compiled with its locale available to the body. Allowing a second 'locale' in scope would make it ambiguous which one a body referred to, so the name is reserved outright rather than shadowed.
Common causes
- Declaring a 'locale' variable or parameter inside a text body
- Naming a text method parameter 'locale'
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07156: 'locale' is reserved in a text construct - it names the auto-provided Locale field
#!ek9 defines module error.e07156.bad defines text for "en" ParamNamedLocaleText greeting() -> locale as String "Fixed greeting" MethodNamedLocaleText locale() "Fixed text"
Fixed: Choose another name: 'locale' is the text's own Locale
#!ek9 defines module error.e07156.good defines text for "en" GreetingText greeting() -> language as String `Hello, you asked for ${language}` salutation() "Fixed text"