Skip to content

fix crash when find the map's element which its defination in other f…#9

Open
tw4452852 wants to merge 1 commit into
rogpeppe:masterfrom
tw4452852:map
Open

fix crash when find the map's element which its defination in other f…#9
tw4452852 wants to merge 1 commit into
rogpeppe:masterfrom
tw4452852:map

Conversation

@tw4452852
Copy link
Copy Markdown

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

@tw4452852
Copy link
Copy Markdown
Author

Assume there are two files:

// 1.go
type A struct{}
// 2.go
m := make(map[string]A)
if elm, ok := m["test"]; ok {
     // do something
}

if we find elm definition, godef will crash.

@rogpeppe
Copy link
Copy Markdown
Owner

LGTM, thanks! Please fix conflicts and I will merge.

…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>
@tw4452852
Copy link
Copy Markdown
Author

Done.

Comment thread go/types/types.go
_, t := ctxt.exprType(expr, false, pkg)
if t.Kind == ast.Typ {
debugp("expected value, got type %v", t)
t = badType
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants