diff --git a/_test/time14.go b/_test/time14.go new file mode 100644 index 000000000..9f28c57d0 --- /dev/null +++ b/_test/time14.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "time" +) + +var t time.Time + +func f() time.Time { + time := t + return time +} + +func main() { + fmt.Println(f()) +} + +// Output: +// 0001-01-01 00:00:00 +0000 UTC diff --git a/interp/cfg.go b/interp/cfg.go index b8dbd29ab..714f6f67b 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -1381,7 +1381,7 @@ func (interp *Interpreter) cfg(root *node, importPath string) ([]*node, error) { n.val = sc.def for i, c := range n.child { var typ *itype - typ, err = nodeType(interp, sc, returnSig.child[1].fieldType(i)) + typ, err = nodeType(interp, sc.upperLevel(), returnSig.child[1].fieldType(i)) if err != nil { return } diff --git a/interp/scope.go b/interp/scope.go index 4a8e728f8..7dcbe60ad 100644 --- a/interp/scope.go +++ b/interp/scope.go @@ -113,6 +113,14 @@ func (s *scope) pop() *scope { return s.anc } +func (s *scope) upperLevel() *scope { + level := s.level + for s != nil && s.level == level { + s = s.anc + } + return s +} + // lookup searches for a symbol in the current scope, and upper ones if not found // it returns the symbol, the number of indirections level from the current scope // and status (false if no result).