Keywords
V has 44 reserved keywords (3 are literals). The following tokens are always interpreted as keywords and cannot be used as identifiers:
as
- used in sum types
- specify an alias for an import
- specify a inner type for a enum
asm
– used in inline assemblyassert
– used in testingatomic
– used in atomicsbreak
– terminates the execution of a loopconst
– declares a constantcontinue
– proceeds to the next step of the nearest enclosing loopdefer
– defines deferred blockelse
– defines the branch of an if expression that is executed when the condition is false.enum
– declares an enumfalse
– literal falsely boolean valuefn
– declares a functionfor
– begins a for loopgo
– starts a separate threadgoto
– jumps to a labelif
– begins an if expressionimport
– imports a modulein
interface
– declares an interfaceis
- used in sum types
- used in interfaces
isreftype
– checks if a type is a reference typelock
– used in lockingmatch
– begins a match expressionmodule
– declares a modulemut
- declares a mutable variable
- starts a mutable fields block
- declares method receiver as mutable
none
– literal value of the none typeor
- defines the branch for result or option type
- defines the branch for array fetch that is executed when the index is out of bounds
- defines the branch for map fetch that is executed when the key is not found
pub
- makes a declaration public
- starts a public fields block
return
– returns a value from a functionrlock
– used in lockingselect
– used in select statementshared
– used in shared variablessizeof
– returns the size of a typespawn
– starts a separate threadstatic
– used in static variablesstruct
– declares a structtrue
– literal truthy boolean valuetype
– declares a type alias or sum typestypeof
– returns the type of expressionunion
– declares a unionunsafe
– starts an unsafe blockvolatile
– used in volatile variables__global
– declares a global variable__offsetof
– returns the offset of a field
Special identifiers
The following identifiers are defined by the compiler in specific contexts, and they can be used as regular identifiers in other contexts:
it
is used inside aarray
ormap
method calls to refer to its parameter implicitly.a
andb
is used inside asort()
method forarray
to refer left and right elements respectively.