/ tests / tests / compiler / async_blocks / correct_captures.adl
correct_captures.adl
 1  program test.alpha {
 2      const X: u32 = 5;
 3      mapping map: u32 => u32;
 4  
 5      async transition foo(p: u32, q: u8) -> Future {
 6          let x = 5u32;
 7          let y = (1u32, 2u8, 3u16);
 8          let w = (1u32, true);
 9          let z = [1u8; 3];
10          let (t1, t2) = (6u32, 8u8);
11          let f = async {
12              let w2 = w;
13              let sum1 = x + y.0 + (y.1 as u32) + (z[0] as u32) + (z[2] as u32) + w.0 + w2.0;
14              let y2 = y;
15              let sum1_again = x + y2.0 + (y2.1 as u32) + (z[0] as u32) + (z[2] as u32);
16              let sum2 = p + (q as u32) + t1 + t2 as u32 + X;
17              let total = sum1 + sum1_again + sum2;
18              map.set(0u32, total); // `total` is local so it shouldn't be in the param list of the produced async function 
19  
20              {
21                  let total2 = sum1 + sum1_again + sum2;
22                  map.set(0u32, total2); // `total2` is local so it shouldn't be in the param list of the produced async function 
23              }
24          };
25  
26          // No shadowing
27          let total = x;
28          assert(total >= 0u32);
29          let total2 = x;
30          assert(total2 >= 0u32);
31  
32  
33          return f;
34      }
35  }