We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
https://go2goplay.golang.org/p/ZBpMABeQ0r8
package main import ( "fmt" ) type Item(type T) struct { Val T } func NewItems(type T)(size int) []Item(T) { // Not compile: cannot use generic type Item(type T) without instantiation return make([]Item(T), size) } func main() { items := NewItems(int)(2) fmt.Printf("items = %#v\n", items) }
Making a slice of generics struct compiles
type checking failed
The text was updated successfully, but these errors were encountered:
If I pre-define a generics type of the slice, it compiles. https://go2goplay.golang.org/p/Wun2YoiGVcg
package main import ( "fmt" ) type Item(type T) struct { Val T } type Items(type T) []Item(T) func NewItems(type T)(size int) []Item(T) { return make(Items(T), size) } func main() { items := NewItems(int)(2) fmt.Printf("items = %#v\n", items) }
Sorry, something went wrong.
If you add parentheses, it compiles too. https://go2goplay.golang.org/p/OSGzqlKrMsM
return make([](Item(T)), size)
This is another instance of the ambiguity described at https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#instantiating-types-in-type-literals .
No branches or pull requests
What did you do?
https://go2goplay.golang.org/p/ZBpMABeQ0r8
What did you expect to see?
Making a slice of generics struct compiles
What did you see instead?
type checking failed
The text was updated successfully, but these errors were encountered: