Restrict tPrefix temporary variables's scope.

This commit is contained in:
Nigel Tao committed 2017-11-03 14:00:35 +11:00
1 parent acec19e969
commit 558d8ddbbd
3 files changed
+293 -219

No files matched your search

+18
View File
@@ -39,6 +39,24 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
return nil
}
mightIntroduceTemporaries := false
switch n.Kind() {
case a.KAssign:
n := n.Assign()
mightIntroduceTemporaries = n.LHS().Suspendible() || n.RHS().Suspendible()
case a.KVar:
v := n.Var().Value()
mightIntroduceTemporaries = v != nil && v.Suspendible()
}
if mightIntroduceTemporaries {
// Put n's code into its own block, to restrict the scope of the
// tPrefix temporary variables. This helps avoid "jump bypasses
// variable initialization" compiler warnings with the coroutine
// suspension points.
b.writes("{\n")
defer b.writes("}\n")
}
if genFilenameLineComments {
filename, line := n.Raw().FilenameLine()
if i := strings.LastIndexByte(filename, '/'); i >= 0 {