Skip to content

cmd/compile: embedded field type cannot be a (pointer to a) type parameter #49030

@Fullstop000

Description

@Fullstop000

What version of Go are you using (go version)?

go version devel go1.18-cf51fb5d68 Sun Oct 17 04:27:13 2021 +0000 darwin/amd64

In https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md, the following code should be ok to be compiled:

type Lockable[T any] struct {
	T
	mu sync.Mutex
}

// Get returns the value stored in a Lockable.
func (l *Lockable[T]) Get() T {
	l.mu.Lock()
	defer l.mu.Unlock()
	return l.T
}

// Set sets the value in a Lockable.
func (l *Lockable[T]) Set(v T) {
	l.mu.Lock()
	defer l.mu.Unlock()
	l.T = v
}

What did you expect to see?

compile success

What did you see instead?

~/dev/go2playground ~/goroot/bin/go test
# go2playground [go2playground.test]
./main_test.go:50:2: embedded field type cannot be a (pointer to a) type parameter

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions