-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed as not planned
Closed as not planned
Copy link
Labels
ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.Issue is not actionable because of missing required information, which needs to be provided.
Milestone
Description
I am not sure why an aliased type, MyInt below is not being parsed as types.Alias with golang.org/x/tools/go/packages.Load.
In example.com/project/foo/file.go:
package foo
type MyInt = int
var _ = MyInt(1)
In foo_test.go:
import (
"go/types"
"golang.org/x/tools/go/packages"
)
func TestLoad(t *testing.T) {
cfg := packages.Config{
Mode: packages.NeedName |
packages.NeedFiles | packages.NeedImports | packages.NeedDeps |
packages.NeedModule | packages.NeedTypes | packages.NeedSyntax,
BuildFlags: []string{"-tags", ""},
Tests: false,
}
pkgs, err := packages.Load(&cfg, "example.com/project/foo")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if len(pkgs) != 1 {
t.Errorf("expected 1 package, got %d", len(pkgs))
}
obj := pkgs[0].Types.Scope().Lookup("MyInt")
if obj == nil {
t.Errorf("expected type MyInt, got nil")
}
typ := obj.Type()
_, ok := typ.(*types.Alias)
if !ok {
t.Errorf("expected type MyInt to be an alias, got %T", typ)
}
}
Am I missing something?
I am using Go 1.24.2
Metadata
Metadata
Assignees
Labels
ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.Issue is not actionable because of missing required information, which needs to be provided.