Syntax: Keywords
● Beginner2 min
Keywords are the words the language itself uses. They can't be used as names.
agentandarenaasassertbreakcapabilitycatchconstcontinuedeprecatedelseensureexampleextendexternfailfalsefnforifininterfaceinvariantletmatchnonenotorpubrequirereturnsecretselfspawntesttruetrytypeunsafeuseusesvarwhilewithvar declares nothing: it is reserved only so that writing it gives a clear message pointing to let. A few more words, such as result in a contract, are keywords only in one place and ordinary names everywhere else.
A keyword can't name a field either: the field could never be read, since r.agent can't be written.
type Robot {
agent: String
}
fn main() {
print("never runs")
}The compiler refused the program:
kavach run keyword-field.kav
error: `agent` is a keyword, so it can't name a field: pick another name