1
0
mirror of https://github.com/golang/go synced 2024-11-22 20:50:05 -07:00
go/test/fixedbugs/issue41575.go
Max Neverov bdc6dbbc64 go/types: improve recursive type error message
This change improves error message for recursive types.
Currently, compilation of the [following program](https://go.dev/play/p/3ef84ObpzfG):

package main

type T1[T T2] struct{}
type T2[T T1] struct{}

returns an error:

./prog.go:3:6: invalid recursive type T1
	./prog.go:3:6: T1 refers to
	./prog.go:4:6: T2 refers to
	./prog.go:3:6: T1

With the patch applied the error message looks like:

./prog.go:3:6: invalid recursive type T1
	./prog.go:3:6: T1 refers to T2
	./prog.go:4:6: T2 refers to T1

Change-Id: Ic07cdffcffb1483c672b241fede4e694269b5b79
GitHub-Last-Rev: cd042fdc38
GitHub-Pull-Request: golang/go#69574
Reviewed-on: https://go-review.googlesource.com/c/go/+/614084
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-10-22 22:20:29 +00:00

37 lines
1.1 KiB
Go

// errorcheck
// Copyright 2020 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 T1 struct { // ERROR "invalid recursive type T1\n.*T1 refers to T2\n.*T2 refers to T1|invalid recursive type"
f2 T2
}
type T2 struct { // GCCGO_ERROR "invalid recursive type"
f1 T1
}
type a b // GCCGO_ERROR "invalid recursive type"
type b c // ERROR "invalid recursive type b\n.*b refers to c\n.*c refers to b|invalid recursive type|invalid recursive type"
type c b // GCCGO_ERROR "invalid recursive type"
type d e
type e f
type f f // ERROR "invalid recursive type: f refers to itself|invalid recursive type|invalid recursive type"
type g struct { // ERROR "invalid recursive type: g refers to itself|invalid recursive type"
h struct {
g
}
}
type w x
type x y // ERROR "invalid recursive type x\n.*x refers to y\n.*y refers to z\n.*z refers to x|invalid recursive type"
type y struct{ z } // GCCGO_ERROR "invalid recursive type"
type z [10]x
type w2 w // refer to the type loop again