Skip to content

Commit 6d51dd1

Browse files
committed
go/types: remove work-around for issue #26124
This work-around is not needed anymore now that method signatures are type-checked separately from their receiver base types: no artificial cycles are introduced anymore and so there is no need to artificially cut them. Updates #26124. Change-Id: I9d50171f12dd8977116a5d3f63ac39a06b1cd492 Reviewed-on: https://go-review.googlesource.com/c/139899 Reviewed-by: Alan Donovan <[email protected]>
1 parent 8ae8576 commit 6d51dd1

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

src/go/types/decl.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,6 @@ func (check *Checker) objDecl(obj Object, def *Named) {
245245
// Indirections are used to break type cycles.
246246
var indir = NewTypeName(token.NoPos, nil, "*", nil)
247247

248-
// cutCycle is a sentinel type name that is pushed onto the object path
249-
// to indicate that a cycle doesn't actually exist. This is currently
250-
// needed to break cycles formed via method declarations because they
251-
// are type-checked together with their receiver base types. Once methods
252-
// are type-checked separately (see also TODO in Checker.typeDecl), we
253-
// can get rid of this.
254-
var cutCycle = NewTypeName(token.NoPos, nil, "!", nil)
255-
256248
// typeCycle checks if the cycle starting with obj is valid and
257249
// reports an error if it is not.
258250
// TODO(gri) rename s/typeCycle/cycle/ once we don't need the other
@@ -293,16 +285,10 @@ func (check *Checker) typeCycle(obj Object) (isCycle bool) {
293285
case *Const, *Var:
294286
nval++
295287
case *TypeName:
296-
switch {
297-
case obj == indir:
288+
if obj == indir {
298289
ncycle-- // don't count (indirections are not objects)
299290
hasIndir = true
300-
case obj == cutCycle:
301-
// The cycle is not real and only caused by the fact
302-
// that we type-check methods when we type-check their
303-
// receiver base types.
304-
return false
305-
default:
291+
} else {
306292
// Determine if the type name is an alias or not. For
307293
// package-level objects, use the object map which
308294
// provides syntactic information (which doesn't rely
@@ -554,14 +540,6 @@ func (check *Checker) addMethodDecls(obj *TypeName) {
554540
}
555541
}
556542

557-
// Suppress detection of type cycles occurring through method
558-
// declarations - they wouldn't exist if methods were type-
559-
// checked separately from their receiver base types. See also
560-
// comment at the end of Checker.typeDecl.
561-
// TODO(gri) Remove this once methods are type-checked separately.
562-
check.push(cutCycle)
563-
defer check.pop()
564-
565543
// add valid methods
566544
for _, m := range methods {
567545
// spec: "For a base type, the non-blank names of methods bound

0 commit comments

Comments
 (0)