]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix TypeDefn to deal with node with no Ntype set
authorDan Scales <danscales@google.com>
Thu, 4 Nov 2021 18:59:17 +0000 (11:59 -0700)
committerDan Scales <danscales@google.com>
Thu, 4 Nov 2021 20:24:01 +0000 (20:24 +0000)
Adjust TypeDefn(), which is used by reportTypeLoop(), to work for nodes
with no Ntype set (which are all nodes in -G=3 mode). Normally,
reportTypeLoop() would not be called, because the types2 typechecker
would have already caught it. This is a possible way to report an
unusual type loop involving type params, which is not being caught by
the types2 type checker.

Updates #48962

Change-Id: I55edee46026eece2e8647c5b5b4d8dfb39eeb5f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/361398
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/ir/name.go
test/typeparam/issue48962.go [new file with mode: 0644]

index dcfff7debaeedf923c2efa947b4e3fabe292e1dc..1d4110c73cf731ac343a5b8395a917663b902e8f 100644 (file)
@@ -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 (file)
index 0000000..de9a23c
--- /dev/null
@@ -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]
+}