Skip to content

Go: three smaller call-edge inaccuracies (type conversions, external test packages, build tags) #2581

Closed

Description

@inth3shadows

Summary

Three low-severity Go shapes where a calls edge is recorded that the source does not make, or goes to the wrong one of two definitions. Each one came up while checking edges in a real 284-file Go module. They are filed together because each is small. They have different causes.

  1. A type conversion Category(s), with type Category string, is recorded as a calls edge to the type.
  2. A call in an external test package (package a_test) binds to the package a test helper of the same name, not to the a_test helper in the same directory.
  3. A function defined twice under complementary build constraints (//go:build unix / //go:build !unix) gets one edge, always to the !unix file, including on Linux.

Reproduction (verified)

On main at 8fe3156, built from source, Linux (WSL2), Node 22.23.2, Go 1.26, WASM extractor (CODEGRAPH_KERNEL=0). Each case is its own module with go 1.22 in go.mod, and each passes go vet (case 3 also passes with GOOS=windows). Command: codegraph init -i. Then calls edges from the SQLite index, excluding main as the source, as source file:line, source, target kind, target, target file:line, resolvedBy.

1. Type conversion recorded as a call

package main

type Category string

func use(s string) Category {
	return Category(s) // a conversion, not a call
}

func main() { use("") }

Observed:

main.go:6 use -> type_alias Category main.go:3 (exact-match)

Expected: no calls edge. If a dependency on the type is wanted, a references edge to Category would describe it.

2. External test package binds the internal package's helper

// a.go
package a

func Real() {}
// a_internal_test.go
package a

import "testing"

func corpus(t *testing.T) []string { return nil }

func TestInternal(t *testing.T) { _ = corpus(t) }
// b_ext_helpers_test.go
package a_test

import "testing"

func corpus(t *testing.T, root string) []string { return nil }
// a_ext_test.go
package a_test

import "testing"

func TestExt(t *testing.T) { _ = corpus(t, "") }

Observed:

a_ext_test.go:5      TestExt      -> function corpus a_internal_test.go:5 (exact-match)
a_internal_test.go:7 TestInternal -> function corpus a_internal_test.go:5 (exact-match)

Expected: TestExt -> corpus in b_ext_helpers_test.go:5. package a and package a_test are different packages, so the package a helper is not visible from a_ext_test.go at all. The second edge is correct.

3. Build-constrained definitions: one edge, to the non-host file

// main.go
package main

func main() { println(sep()) }
// sep_unix.go
//go:build unix

package main

func sep() string { return "/" }
// sep_other.go
//go:build !unix

package main

func sep() string { return "\\" }

Observed, the same on three fresh indexes:

main.go:3 main -> function sep sep_other.go:5 (exact-match)

Both sep nodes are indexed. Expected: an edge to each definition, since either one can be the callee depending on the build. If only one edge is kept, it should not be chosen arbitrarily. Today the !unix variant is the only callee shown, on a Linux machine. Impact and callers for sep_unix.go::sep show nothing.

Likely cause (inferred from reading the code)

I traced each edge with an instrumented build of the same source. The edges are returned by matchByExactName: case 1 by its single-candidate branch (name-matcher.ts#L7970-L7980), and cases 2 and 3 by findBestMatch (L7991-L8003). The rest comes from reading the code:

  1. Conversion. A bare Go call keeps every non-method candidate (isRustGoCallTarget, L5238), and that includes type nodes. In Go, a calls ref whose target is a type is a conversion, so it could be re-kinded or dropped. Go: factory calls and GORM-style chains resolve to unrelated symbols #2543's proposed fix explicitly preserves same-package conversions resolving to the type, so changing the edge kind may be preferable to dropping the resolution.
  2. External test package. Both helpers are in the same directory and the same language, so findBestMatch's scoring (L15644) does not separate them, and the tie goes to candidate order. I found no code under src/ that reads a Go file's package clause, so a and a_test are treated as one package.
  3. Build tags. Same scoring tie as case 2, and I found no code under src/ that reads //go:build lines.

Related

Not checked

  • The native kernel (CODEGRAPH_KERNEL unset).
  • A conversion to a struct type, a pointer type ((*T)(p)) or a generic type. The Go framework resolver may produce instantiates for some of these.
  • An external test package that also imports the package under test and calls a.corpus. That should be unaffected, because the qualified-name path handles it.
  • Filename-only constraints (sep_windows.go with no //go:build line), and the legacy // +build form.

Activity

  1. added a commit that references this issue on Oct 22, 2026
    68584cd
  2. colbymchenry commented on Oct 22, 2026

    @colbymchenry
    Owner

    Thanks for the detailed report and the instrumented traces. All three shapes still reproduced on current main.

    #2784 is merged to main and fixes each one:

    • A conversion like Category(s) is now recorded as a use of the type instead of a call.
    • A call in an external test package (package a_test) reaches its own package's helper.
    • A function defined once per platform under build constraints links to the definition a default Linux build uses. If the calling file is itself written for a platform, it links to that platform's definition.

    Re-index your Go projects once the next release is out.

  3. added a commit that references this issue on Oct 22, 2026
    800e582
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions