Generics Error in Goland 2021.3

Answered

Goland: 2021.3

GO: GOTIP go1.18-1afa432ab9

Goland 2021.3 report error on following code, while gotip playground works well https://gotipplay.golang.org/

package main

import (
"fmt"
)

// This playground uses a development build of Go:
// devel go1.18-1afa432ab9 Tue Dec 14 01:48:22 2021 +0000

type Data[T any] struct {
err error
result T
}

func New[T any](input T) Data[T] {
return Data[T] {
result: input,
}
}

func main() {
fmt.Println("of int", New(3))
fmt.Println("of int", New("ddfasasd"))
}

 

Goland report following error:

Cannot use 'Data[T]{ result: input,...

Unknown field 'result' in struct literal

0
2 comments

Looks like https://youtrack.jetbrains.com/issue/GO-9515 

When will this fix be available? Any workaround from user side?

0

Hello,

It is a known issue, please see GO-11973.

The fix will be available in the next bug-fix release: 2021.3.1. We plan to release it this week.

There is no workaround at the moment.

0

Please sign in to leave a comment.