Skip to content

Commit

Permalink
across: cover var scoping and shadowing
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
  • Loading branch information
vito committed Jul 21, 2020
1 parent ba81898 commit cfec275
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 029-across-step/proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,50 @@ Note: this is the first time a step *modifier* has had additional sibling
fields. In the event of a field conflict, the `do:` step may be utilized as a
work-around.

### Var scoping and shadowing

The inner step will be run with a local var scope that inherits from the outer
scope and is initialized with the across step's var values.

Given that it runs with its own scope, it follows that the vars in the local
scope, along with any vars newly set within the scope, are not accessible
outside of the `across` step.

When a var set by the `across` step shadows outer vars, a warning will be
printed.

Example:

```yaml
plan:
- get_var: foo
trigger: true
- run: print
type: debug
params: {value: ((.:foo))}
- across:
- var: foo
values: [one, two]
do:
- run: print
type: debug
params: {value: ((.:foo))}
- run: print
type: debug
params: {value: ((.:foo))}
```

Assuming the `get_var` step produces a value of `zero`, this build plan should
result in the following output:

```
zero
WARNING: across step shadows local var 'foo'
one
two
zero
```


## Open Questions

Expand Down

0 comments on commit cfec275

Please sign in to comment.