go-lang-plugin-org / go-lang-idea-plugin

Google Go language IDE built using the IntelliJ Platform
https://plugins.jetbrains.com/plugin/5047
Other
4.56k stars 571 forks source link

Incorrect resolving #2111

Open dlsniper opened 8 years ago

dlsniper commented 8 years ago

Using 9b670063971f91221633cbb38008966c07855f79 in the following package go get -v -u -t golang.org/x/net, the following line resolves incorrectly to the builtin package https://github.com/golang/net/blob/28273ec927bee3bea305f112fc28ceee575ea893/icmp/endpoint.go#L56

it should resolve to x/net/ipv4/package.go:23 but it resolves to Go sdk net/net.go:306.

zolotov commented 8 years ago
package main

type baseType interface {
    Method() string
}

type middleType struct {
    baseType
}

func (c *middleType) /*def*/Method() string {
    return "Hi!"
}

type leafType struct {
    middleType
}

func main() {
    var leaf = leafType{}
    println(leaf./*ref*/Method())

    var middle = middleType{}
    println(middle./*ref*/Method())
}
ignatov commented 8 years ago

@dlsniper Please provide an isolated sample next time.

dlsniper commented 8 years ago

Will do. Also, please ping me / label these with Feedback required when you think I need to provide a better example for issues as sometimes I open issues but I don't have too much time to investigate on my own.

dlsniper commented 8 years ago

I'm sorry it took a bit but reverse engineering this was fun :) However, here it is:

package main

type PacketCnn interface {
    ReadFrom(b []byte) (n int, addr int, err error)
}

type dgramOpt struct {
    PacketCnn
}

type payloadHandler struct {
    PacketCnn
}

func (c *payloadHandler) /*def*/ReadFrom(b []byte) (a, d, e, f int) {
    println("hello")
    return 1, 2, 3, 4
}

type ipv4PacketConn struct {
    dgramOpt
    payloadHandler
}

var a PacketCnn = &PacketConn{p4: &ipv4PacketConn{}}

type PacketConn struct {
    c  PacketCnn
    p4 *ipv4PacketConn
}

func (c *PacketConn) ReadFrom(b []byte) (n int, addr int, err error) {
    _, _, _, _ = c.p4./*ref*/ReadFrom(b)
    return 1, 1, nil
}

func main() {
    _, _, _ = a.ReadFrom([]byte{})
}
dlsniper commented 8 years ago

I've updated the example a bit to be clear that things actually work (and trim it down as well).

ignatov commented 8 years ago

It's all about DFS/BFS.