google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.34k stars 212 forks source link

resolve: retain globals across REPL chunks #247

Closed alandonovan closed 5 years ago

alandonovan commented 5 years ago

Previously, in the REPL, the globals bound by one chunk would become the "predeclared" bindings of the next chunk. However, this produced the wrong result for [x = x + 1] because both occurrences of x would resolve to the same global x, which was undefined when the right-hand side expression was evaluated, leading to a dynamic error. It would fail for [x += 1] for a similar reason.

This change extends the resolver to allow clients to provide it with a non-empty set of module globals. Thus the globals of one chunk remain the globals of the next chunk, and the predeclared set is always empty.

The new API functions are intended for use only by the REPL.

Fixes #233

alandonovan commented 5 years ago

@laurentlb @brandjon