Skip to content

Commit

Permalink
interp: fix redeclaration scope issue
Browse files Browse the repository at this point in the history
Fixes #1378
  • Loading branch information
cclerget authored Apr 9, 2022
1 parent 1cf9d34 commit 5665c9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions _test/issue-1378.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"fmt"
"time"
)

func main() {
t, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
if err != nil {
panic(err)
}
fn := func() error {
_, err := t.GobEncode()
return err
}
fmt.Println(fn())
}

// Output:
// <nil>
2 changes: 1 addition & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ func compDefineX(sc *scope, n *node) error {
for i, t := range types {
var index int
id := n.child[i].ident
if sym, _, ok := sc.lookup(id); ok && sym.kind == varSym && sym.typ.equals(t) {
if sym, level, ok := sc.lookup(id); ok && level == n.child[i].level && sym.kind == varSym && sym.typ.equals(t) {
// Reuse symbol in case of a variable redeclaration with the same type.
index = sym.index
} else {
Expand Down

0 comments on commit 5665c9a

Please sign in to comment.