Skip to content

Commit

Permalink
fix crash when find the map's element which its defination in other f…
Browse files Browse the repository at this point in the history
…iles

when we find a map's element which its defination is located in another file,
it will crash.

Signed-off-by: Tw <tw19881113@gmail.com>
  • Loading branch information
tw4452852 committed May 30, 2016
1 parent 93a5898 commit 88f9022
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions go/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func (ctxt *exprTypeContext) exprType(n ast.Node, expectTuple bool, pkg string)
_, t := ctxt.exprType(expr, false, pkg)
if t.Kind == ast.Typ {
debugp("expected value, got type %v", t)
t = badType
}
return obj, t

Expand Down Expand Up @@ -310,7 +309,7 @@ func (ctxt *exprTypeContext) exprType(n ast.Node, expectTuple bool, pkg string)
return nil, ctxt.certify(n.Elt, ast.Var, t.Pkg)
case *ast.MapType:
t := ctxt.certify(n.Value, ast.Var, t.Pkg)
if expectTuple {
if expectTuple && t.Kind != ast.Bad {
return nil, ctxt.newType(MultiValue{[]ast.Expr{t.Node.(ast.Expr), predecl("bool")}}, ast.Var, t.Pkg)
}
return nil, t
Expand Down
2 changes: 1 addition & 1 deletion godef.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() {
case ast.Expr:
if !*tflag {
// try local declarations only
if obj, typ := types.ExprType(e, types.DefaultImporter, types.FileSet); obj != nil {
if obj, typ := types.ExprType(e, types.DefaultImporter, types.FileSet); obj != nil && typ.Kind != ast.Bad {
done(obj, typ)
}
}
Expand Down

0 comments on commit 88f9022

Please sign in to comment.