go.tools/go/types: initialize local x early in case of bailout panic

- added respective test case

Fixes golang/go#5770.

R=adonovan
CC=golang-dev
https://golang.org/cl/10531043
This commit is contained in:
Robert Griesemer 2013-06-24 21:29:47 -07:00
parent 124e603d87
commit 25da72adcd
2 changed files with 33 additions and 0 deletions

View File

@ -1031,6 +1031,11 @@ func (check *checker) callExpr(x *operand) {
// cycleOk indicates whether it is ok for a type expression to refer to itself.
//
func (check *checker) rawExpr(x *operand, e ast.Expr, hint Type, iota int, cycleOk bool) {
// make sure x has a valid state for deferred functions in case of bailout
// (was issue 5770)
x.mode = invalid
x.typ = Typ[Invalid]
if trace {
c := ""
if cycleOk {

28
go/types/issues_test.go Normal file
View File

@ -0,0 +1,28 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file implements tests for various issues.
package types
import (
"go/parser"
"strings"
"testing"
)
func TestIssue5770(t *testing.T) {
src := `package p; type S struct{T}`
f, err := parser.ParseFile(fset, "", src, 0)
if err != nil {
t.Error(err)
return
}
_, err = Check(f.Name.Name, fset, f) // do not crash
want := "undeclared name: T"
if err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("got: %v; want: %s", err, want)
}
}