mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.28k stars 346 forks source link

interp: fix unset global inside function #807

Closed dtrudg closed 2 years ago

dtrudg commented 2 years ago

In dc2e11e unset of a global var inside a function was broken, as the special handling of export or readonly in function scope introduced in that commit also incorrectly captured unset, calling a parent.Set with the previous value.

Ensure we do not capture unset in the function scope global handling.

Unset of a global can fall-through this code. Globals are unset correctly further down the Set function, so we do not need to invoke a parent.Set at all.

Fixes mvdan#806

dtrudg commented 2 years ago

@mvdan @cclerget - I believe that this is a valid fix for #806 - cheers.

mvdan commented 2 years ago

Thanks! I'll most likely tag v3.4.3 including this fix in a few days. In the meantime, you can either use master or the v3.4 branch, which is where I'm cherry-picking the bugfix changes on top of v3.4.2.