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

[generics] doesn't handle name collision #39834

Closed
kovetskiy opened this issue Jun 24, 2020 · 2 comments
Closed

[generics] doesn't handle name collision #39834

kovetskiy opened this issue Jun 24, 2020 · 2 comments

Comments

@kovetskiy
Copy link

go version devel +2dc2987ac87 Tue Jun 23 23:41:16 2020 +0000 linux/amd64

bug/a.go:

package main

import "bug/lib"

type Bug(type T) interface {
	Get() T
}

func MakeCollision(type T)(bug Bug(T)) {
	
}

func main() {
	impl := lib.NewBug(int)(1)
	MakeCollision(int)(impl)
}

bug/lib/b.go:

package lib

type Bug(type T) struct {
	x T
}

func NewBug(type T)(x T) Bug(T) {
	return Bug(T){x: x}
}

func (bug Bug(T)) Get() T {
	return bug.x
}

current result:

 > go tool go2go run a.go2
   # command-line-arguments
   ./a.go2:5: invalid composite literal type instantiate୦୦Bug୦int
   ./a.go2:10: instantiate୦୦Bug୦int redeclared in this block
        previous declaration at ./a.go2:11
   /usr/lib/go/bin/go [run a.go] failed: exit status 2
@gopherbot
Copy link

Change https://golang.org/cl/239706 mentions this issue: [dev.go2go] go/go2go: include package in instantation of ident

@ianlancetaylor
Copy link
Contributor

Thanks. This is now fixed on the dev.go2go branch.

gopherbot pushed a commit that referenced this issue Jun 24, 2020
If an instantiated function from a different package uses a plain
identifier to instantiate a generic type or function, include the
package name in the generated identifier.

Fixes #39834

Change-Id: I4c786bac8972475e180cb41178520439343a36ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/239706
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Jun 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants