Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse implicitely typed map struct keys, when imported from other package #74

Open
Gandem opened this issue Oct 21, 2017 · 1 comment

Comments

@Gandem
Copy link

Gandem commented Oct 21, 2017

Category

Bug report

Environment and versions used

  • Golang version: 1.9
  • Operating System: Mac OSX Sierra
  • godef version: current master @ b692db1

NB:

  • $GOPATH and $GOROOT are correctly setup
  • The bug should not be platform dependent

Issue

When a map that maps a struct to another struct is defined, if the map keys are typed implicitely, and the package is imported by another package, godef throws an error

Steps to reproduce

(A github repo is linked below for the test)

  • Create a new directory, for example $GOPATH/src/test
  • Create a main.go file :
package main

import "fmt"
import "test/someotherpackage"

func main() {
    fmt.Println(someotherpackage.Map)
}
  • Create another package, for example $GOPATH/src/test/someotherpackage
  • Create a test.go file :
package someotherpackage

type Test struct {
    X int
    Y int
}

var Map = map[Test]struct{}{
    {1,2} : struct{}{},
    {1,2} : struct{}{},
    {1,2} : struct{}{},
}
  • Run :
godef -debug -f main.go someotherpackage.Map

This produces the following stacktrace :

Stacktrace
2017/10/20 19:50:04 exprType tuple:false pkg: *ast.SelectorExpr someotherpackage.Map [
2017/10/20 19:50:04 exprType tuple:false pkg: *ast.Ident someotherpackage [
2017/10/20 19:50:04 exprType tuple:false pkg: *ast.ImportSpec "test/someotherpackage" [
2017/10/20 19:50:04 ] -> 0x0, Type{package "" *ast.ImportSpec "test/someotherpackage"}
2017/10/20 19:50:04 ] -> 0xc420011a40, Type{package "" *ast.ImportSpec "test/someotherpackage"}
2017/10/20 19:50:04 member Type{package "" *ast.ImportSpec "test/someotherpackage"} 'Map' {
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:9:11: expected '}', found ':'
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:10:5: expected declaration, found '{'
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:11:5: expected declaration, found '{'
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:12:1: expected declaration, found '}'
2017/10/20 19:50:04 } -> <nil>
2017/10/20 19:50:04 ] -> 0x0, Type{bad "" <nil> }
parseLocalPackage error: no more package files found
2017/10/20 19:50:04 exprType tuple:false pkg: *ast.SelectorExpr someotherpackage.Map [
2017/10/20 19:50:04 exprType tuple:false pkg: *ast.Ident someotherpackage [
2017/10/20 19:50:04 exprType tuple:false pkg: *ast.ImportSpec "test/someotherpackage" [
2017/10/20 19:50:04 ] -> 0x0, Type{package "" *ast.ImportSpec "test/someotherpackage"}
2017/10/20 19:50:04 ] -> 0xc420011a40, Type{package "" *ast.ImportSpec "test/someotherpackage"}
2017/10/20 19:50:04 member Type{package "" *ast.ImportSpec "test/someotherpackage"} 'Map' {
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:9:11: expected '}', found ':'
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:10:5: expected declaration, found '{'
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:11:5: expected declaration, found '{'
2017/10/20 19:50:04 	$GOPATH/src/test/someotherpackage/test.go:12:1: expected declaration, found '}'
2017/10/20 19:50:04 } -> <nil>
2017/10/20 19:50:04 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for someotherpackage.Map

Expected behaviour

It should find the declaration for someotherpackage.Map, as this is valid go syntax. The code compiles and runs fine !

Reproducible demo

The test can be found here : https://github.com/Gandem/test-issue-godef

Cloning the repo in $GOPATH/test should work to reproduce the issue.

Note : godef -debug -f test.go Map works fine when the command is run from $GOPATH/test/someotherpackage

@Gandem
Copy link
Author

Gandem commented Oct 23, 2017

I believe #56 fixes this issue, if anyone has the time to look at it ! (cc @rogpeppe ?)

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

No branches or pull requests

1 participant