0
1
mirror of https://github.com/golang/go synced 2024-11-11 12:49:30 +00:00
go/test/fixedbugs/issue56103.go
Matthew Dempsky 840b346c5d cmd/compile: reject anonymous interface cycles
This CL changes cmd/compile to reject anonymous interface cycles like:

	type I interface { m() interface { I } }

We don't anticipate any users to be affected by this change in
practice. Nonetheless, this CL also adds a `-d=interfacecycles`
compiler flag to suppress the error. And assuming no issue reports
from users, we'll move the check into go/types and types2 instead.

Updates #56103.

Change-Id: I1f1dce2d7aa19fb388312cc020e99cc354afddcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/445598
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
2022-11-21 20:15:23 +00:00

47 lines
1.5 KiB
Go

// errorcheck
// Copyright 2022 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
// Self recursion.
type i interface{ m() interface{ i } } // ERROR "invalid recursive type"
type _ interface{ i } // no redundant error
// Mutual recursion.
type j interface{ m() interface{ k } } // ERROR "invalid recursive type"
type k interface{ m() interface{ j } }
// Both self and mutual recursion.
type (
a interface { // ERROR "invalid recursive type"
m() interface {
a
b
}
}
b interface {
m() interface {
a
b
}
}
)
// Self recursion through other types.
func _() { type i interface{ m() *interface{ i } } } // ERROR "invalid recursive type"
func _() { type i interface{ m() []interface{ i } } } // ERROR "invalid recursive type"
func _() { type i interface{ m() [0]interface{ i } } } // ERROR "invalid recursive type"
func _() { type i interface{ m() chan interface{ i } } } // ERROR "invalid recursive type"
func _() { type i interface{ m() map[interface{ i }]int } } // ERROR "invalid recursive type"
func _() { type i interface{ m() map[int]interface{ i } } } // ERROR "invalid recursive type"
func _() { type i interface{ m() func(interface{ i }) } } // ERROR "invalid recursive type"
func _() { type i interface{ m() func() interface{ i } } } // ERROR "invalid recursive type"
func _() {
type i interface { // ERROR "invalid recursive type"
m() struct{ i interface{ i } }
}
}