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: inappropriate "cannot use generic type without instantiation" error #40791

Closed
rogpeppe opened this issue Aug 14, 2020 · 3 comments
Closed

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented Aug 14, 2020

commit 722af87

The following program fails with the error "cannot use generic type Pair(type A, B) without instantiation", but the type does seem to be instantiated correctly.

package main
import "fmt"

func main() {
	fmt.Println(zeroS(int)())
}

type S(type T) struct {
	T T
}

func zeroS(type T)() S(T) {
	m := make([]S(T), 1)
	return m[0]
}

If we add a type alias, it works.

@ainar-g
Copy link
Contributor

ainar-g commented Aug 14, 2020

I don't know if it's related, but it seems to work when you use square brackets.

@rogpeppe
Copy link
Contributor Author

Ah, interesting! I was using round brackets because originally I had more than one type parameter so couldn't use square brackets because of issue #40788. https://go2goplay.golang.org/p/v35cQ-jcbEd

@ianlancetaylor
Copy link
Contributor

Yes, this is the syntactic ambiguity of []S(T) when using parentheses. You have to write it as [](S(T)). Or use square brackets.

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

4 participants