You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a package that contains a type alias and a method, that has a parameter, type of which is the type alias.
package foo
typeAlias=stringfuncFoo(sAlias) {}
When I parse the package using tools/packages, the type alias in the parameter is ignored and string type is set.
pkg, _:=packages.Load(&packages.Config{
Dir: "./foo",
Mode: packages.NeedName|packages.NeedSyntax|packages.NeedTypes,
})
fn:=pkg[0].Types.Scope().Lookup("Foo").(*types.Func)
sig:=fn.Type().(*types.Signature)
typ:=sig.Params().At(0).Type()
fmt.Println(typ.String()) // --> string, but actual type is Alias
This issue proposes to use actual type aliases in Types tree of *package.Package.
The text was updated successfully, but these errors were encountered:
dils2k
changed the title
proposal: golang.org/x/tools/packages: Show type aliases in packages.Package's Types tree.
proposal: golang.org/x/tools/packages: Use type aliases in packages.Package's Types tree.
Jan 6, 2024
seankhliao
changed the title
proposal: golang.org/x/tools/packages: Use type aliases in packages.Package's Types tree.
proposal: x/tools/packages: Use type aliases in packages.Package's Types tree.
Jan 6, 2024
This is the expected behavior for Go versions <= 1.22. Alias is just another name for string. For a long time there was no representation of Alias as a go/types.Type. This is expected to change starting in go1.23 #63223 (also behind a GODEBUG flag).
Support for this is expected to start in go/types in go1.23. The status for support from x/tools/go/packages for go1.23 is still in progress: #63223 (comment). IIUC the way I expect this will be available to packages users will be to compile with >= go1.23.
Proposal Details
I have a package that contains a type alias and a method, that has a parameter, type of which is the type alias.
When I parse the package using
tools/packages
, the type alias in the parameter is ignored andstring
type is set.This issue proposes to use actual type aliases in
Types
tree of*package.Package
.The text was updated successfully, but these errors were encountered: