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

Anonymous structs and their fields have semantically incorrect symbol names #95

Open
varungandhi-src opened this issue Apr 26, 2024 · 0 comments
Labels
bug Something isn't working graph/scip-go team/graph

Comments

@varungandhi-src
Copy link
Contributor

varungandhi-src commented Apr 26, 2024

Currently, we create a stack of scopes for naming anonymous fields. This is wrong because it doesn't 'Find refs' to work across different instances of the same anonymous struct, which may be semantically linked to one another.

type Y struct {
    x struct { t int }
    z struct { t int }
}

func xz(y Y) {
    y.x = y.z // OK
}

The two anonymous struct types are the same type, but using the field name in the type name will make them different.

The correct algorithm should be something like:

  1. If the type is located inside a function body, it's name and the field names should be locals.
  2. Otherwise
    1. Sort all fields of the anonymous struct by name.
    2. Construct a unique string based on all the fields, their canonical types, and the struct tags. E.g. you could just feed these into a hasher. Use this string as the descriptor suffix.
    3. Depending on the outer context (e.g. if it's a private field, a private type, a function argument to a private function), the prefix should not include the package name and version to disable cross-repo navigation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working graph/scip-go team/graph
Projects
None yet
Development

No branches or pull requests

1 participant