diff --git a/src/cmd/compile/internal/ir/name.go b/src/cmd/compile/internal/ir/name.go index dcfff7deba..1d4110c73c 100644 --- a/src/cmd/compile/internal/ir/name.go +++ b/src/cmd/compile/internal/ir/name.go @@ -146,7 +146,10 @@ func (n *Name) editChildren(edit func(Node) Node) {} // That is, given "type T Defn", it returns Defn. // It is used by package types. func (n *Name) TypeDefn() *types.Type { - return n.Ntype.Type() + if n.Ntype != nil { + return n.Ntype.Type() + } + return n.Type() } // RecordFrameOffset records the frame offset for the name. diff --git a/test/typeparam/issue48962.go b/test/typeparam/issue48962.go new file mode 100644 index 0000000000..de9a23cdd2 --- /dev/null +++ b/test/typeparam/issue48962.go @@ -0,0 +1,15 @@ +// errorcheck -G=3 + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type T0[P any] struct { // ERROR "invalid recursive type" + f P +} + +type T1 struct { + _ T0[T1] +}