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 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 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

@rogpeppe rogpeppe commented Aug 14, 2020

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

@ianlancetaylor ianlancetaylor commented Aug 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.