mirror of
https://github.com/golang/go
synced 2024-11-05 19:46:11 -07:00
897f6677ae
The Uses, Defs and Scope information provided by go/types is inadequate for answering "what if?" queries about the structure of the lexical environment. In this code, for example, var x int func f() { print(x) x := "" print(x) } the two referring Idents x appear at the same lexical depth, inside the function f's Scope object, yet they resolve to different objects. This package associates a lexical.Environment instance with every reference to capture these differences. Each environment is a linked list of enclosing Blocks, and for each block, a number indicating what prefix of its bindings are visible. (Zero for the first 'x' reference above, 1 for the second.) + Smoke test over stdlib. This functionality could be integrated with the type checker in lieu of the not-so-useful types.Info.Scopes data, at little extra cost in code or in running time/space. We should talk about that. LGTM=sameer R=gri, sameer CC=golang-codereviews https://golang.org/cl/143790043 |
||
---|---|---|
.. | ||
lexical_test.go | ||
lexical.go |