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: TypeName.IsAlias reports true for type parameters #49213

Closed
mdempsky opened this issue Oct 28, 2021 · 6 comments
Closed

go/types: TypeName.IsAlias reports true for type parameters #49213

mdempsky opened this issue Oct 28, 2021 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@mdempsky
Copy link
Member

Test program below prints: type T = x.T₁ true *types.TypeParam

I'd expect it to print false instead of true, because T is not an alias.

package main

import (
	"fmt"
	"go/ast"
	"go/parser"
	"go/token"
	"go/types"
	"log"
	"strings"
)

const src = `
package x
func F[T any]() { /*@@@*/ }
`

func main() {
	fset := token.NewFileSet()

	file, err := parser.ParseFile(fset, "x.go", src, 0)
	if err != nil {
		log.Fatal(err)
	}

	conf := types.Config{}
	info := types.Info{}
	pkg, err := conf.Check("x", fset, []*ast.File{file}, &info)
	if err != nil {
		log.Fatal(err)
	}

	pos := file.Pos() + token.Pos(strings.Index(src, "@@@"))
	scope := pkg.Scope().Innermost(pos)
	_, obj := scope.LookupParent("T", pos)
	name := obj.(*types.TypeName)

	fmt.Printf("%v %v %T", name, name.IsAlias(), name.Type())
}

/cc @griesemer @findleyr

@mdempsky mdempsky added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 28, 2021
@mdempsky mdempsky added this to the Go1.18 milestone Oct 28, 2021
@findleyr
Copy link
Contributor

This is just an oversight, actually (I'd been meaning to look into the poor object string...)

We just need to add a case to TypeName.IsAlias:
https://cs.opensource.google/go/go/+/master:src/go/types/object.go;l=254;drc=99d5d8ab6b6819f84bb62aeb3b1eaefaab01989f

@findleyr findleyr added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 28, 2021
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 28, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/359656 mentions this issue: go/types: fix TypeName.IsAlias reports for type parameters

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/360294 mentions this issue: cmd/compile/internal/types2: fix TypeName.IsAlias for type parameter names

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/360334 mentions this issue: go/types/objectpath: fix testcase for CL 359656

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/360335 mentions this issue: go/types/objectpath: fix testcase for the modification of TypeName.IsAlias

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/360336 mentions this issue: go/types/objectpath: fix testcase for the modification of TypeName.IsAlias

gopherbot pushed a commit to golang/tools that referenced this issue Nov 1, 2021
… TypeName.IsAlias

For CL 359656
For golang/go#49213

Change-Id: I3ae7abe8acc0d8816e2029aa55e8bbaee1e05c94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/360334
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
gopherbot pushed a commit that referenced this issue Nov 1, 2021
…names

This is a port of CL 359656 from go/types to types2.

For #49213.

Change-Id: Ib98f9a344c1397af92e061cafd519ea374fd60bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/360294
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopherbot pushed a commit to golang/tools that referenced this issue Nov 1, 2021
For CL 359656
For golang/go#49213

Change-Id: Ib2c5d8fa60702baf07530226322a0a113af6b9e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/360335
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants