let statement

LetStatement :
   let IDENTIFIER | TupleTarget : Type = Expression

TupleTarget :
   ( TupleTargetItem (, TupleTargetItem) + )

TupleTargetItem :
   IDENTIFIER | TupleTarget

A let statement introduces a new set of variables. Any variables introduced by a variable declaration are visible from the point of declaration until the end of the enclosing block scope.

Note: Support for nested tuples isn't yet implemented but can be tracked via this GitHub issue.


contract Foo:

  pub fn bar():
    let val1: u256 = 1
    let (val2):(u256) = (1,)
    let (val3, val4):(u256, bool) = (1, false)
    let (val5, val6, (val7, val8)):(u256, bool, (u256, u256)) = (1, false, (2, 4))