Skip to content

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

Closed
@adonovan

Description

@adonovan

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())
}

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions