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

cmd/go2go: incorrect redeclaration error in very specific circumstance with multiple files #39739

Closed
DeedleFake opened this issue Jun 21, 2020 · 1 comment

Comments

@DeedleFake
Copy link

DeedleFake commented Jun 21, 2020

This doesn't work in the playground because it requires a second file.

File one:

package main

func main() {
	Do().Func(Wrap(struct{})())
}

File two:

package main

type Struct(type T) struct {
	v T
}

func Do() Struct(struct{}) {
	return Struct(struct{}){}
}

func (s Struct(T)) Func(f Func(T)) Struct(T) {
	return Struct(T){
		v: f(s.v),
	}
}

type Func(type T) func(T) T

func Wrap(type T)() Func(T) {
	return func(v T) T {
		return v
	}
}

Output:

$ go tool go2go run *.go2# command-line-arguments
./test.go2:4: cannot use instantiate୦୦Wrap୦struct୮4୮5() (type instantiate୦୦Func୦struct୮4୮5) as type instantiate୦୦Func୦struct୮4୮5 in argument to Do().Func
./second.go2:23: instantiate୦୦Func୦struct୮4୮5 redeclared in this block
	previous declaration at ./second.go2:15
/home/deedles/devel/build/go/bin/go [run second.go test.go] failed: exit status 2

Moving the definition of Do() into the first file fixes it. Using a named empty struct type, such as type None struct {}, doesn't fix it.

@DeedleFake DeedleFake changed the title cmd/go2go: returning a generic anonymous function type from a function declared in a second file with an empty struct parameter incorrectly claims a redeclaration cmd/go2go: incorrect redeclaration claim in very specific circumstance with two files Jun 21, 2020
@DeedleFake DeedleFake changed the title cmd/go2go: incorrect redeclaration claim in very specific circumstance with two files cmd/go2go: incorrect redeclaration error in very specific circumstance with multiple files Jun 21, 2020
@ianlancetaylor
Copy link
Contributor

Also reported as #39749. Fixed on dev.go2go branch.

@golang golang locked and limited conversation to collaborators Jun 22, 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