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

go/types: Alias.String should not mention the aliased type #64584

Closed
adonovan opened this issue Dec 6, 2023 · 2 comments
Closed

go/types: Alias.String should not mention the aliased type #64584

adonovan opened this issue Dec 6, 2023 · 2 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Dec 6, 2023

The current behavior of the new go/types.Alias.String method is to print the aliased type in a comment, but I'm not convinced it should. We don't do this for named types, and it undermines one of the main benefits of aliases, which is brevity. The alias name alone seems clear enough, as it's what appears in the source.

@gri @findleyr

$ go build -o alias ./alias.go
$ ./alias
func([]int)
$ GODEBUG=gotypesalias=1  ./alias 
func([]command-line-arguments.A /* = int */)
package main

import (
	"fmt"
	"log"
	"os"

	"golang.org/x/tools/go/packages"
)

type A = int

var x func([]A)

func main() {
	cfg := &packages.Config{Mode: packages.LoadAllSyntax}
	pkgs, err := packages.Load(cfg, "./alias.go")
	if err != nil {
		log.Fatal(err)
	}
	if packages.PrintErrors(pkgs) > 0 {
		os.Exit(1)
	}
	fmt.Println(pkgs[0].Types.Scope().Lookup("x").Type())
}
@griesemer griesemer self-assigned this Dec 6, 2023
@griesemer griesemer added this to the Go1.22 milestone Dec 6, 2023
@adonovan
Copy link
Member Author

adonovan commented Dec 6, 2023

Also: an alias of an alias doesn't nest correctly:

type C = int
type B = []C
type A = B
var x func([]A)

=>

func([]command-line-arguments.A /* = []command-line-arguments.C /* = int */ */)    !!

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/548135 mentions this issue: go/types, types2: don't print aliased type (in comments) for Alias types

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 20, 2023
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
Fixes golang#64584.

Change-Id: I756d6026d10f130c1dd5026891b7cc3c640d7f78
Reviewed-on: https://go-review.googlesource.com/c/go/+/548135
Reviewed-by: Alan Donovan <[email protected]>
Run-TryBot: Robert Griesemer <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
Auto-Submit: Robert Griesemer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants