{{ message }}
/ go Public

# cmd/compile: infinite recursion in types2#50782

Closed
opened this issue Jan 24, 2022 · 2 comments
Closed

# cmd/compile: infinite recursion in types2#50782

opened this issue Jan 24, 2022 · 2 comments
Labels
NeedsInvestigation release-blocker
Milestone

### danscales commented Jan 24, 2022

 This code below causes an infinite recursion in types2. This may already be fixed by some changes in flight (such as https://go-review.googlesource.com/c/go/+/379414/ for issue #48962 ), but I wanted to point out this simple example as another test case, if nothing else: ``````package p type Numeric interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 } // numericAbs matches numeric types with an Abs method. type numericAbs[T Numeric] interface { ~struct{ Value T } Abs() T } // AbsDifference computes the absolute value of the difference of // a and b, where the absolute value is determined by the Abs method. func absDifference[T numericAbs[T]](a, b T) T { d := a.Value - b.Value return d.Abs() } `````` This should not be valid code - in absDifference, we are constraining T to be also ~struct { Value T }, and also there is nothing that requires that T satisfies Numeric. But would be good if the type checker doesn't have an infinite recursion. The text was updated successfully, but these errors were encountered:
added this to the Go1.18 milestone Jan 24, 2022
added the NeedsInvestigation label Jan 24, 2022

### griesemer commented Jan 24, 2022

 This doesn't seem related to #48962. Simpler reproducer: ```package p type T[P int] struct{ f P } func _[P T[P]]() {}```

### gopherbot commented Jan 24, 2022

 Change https://golang.org/cl/380504 mentions this issue: `go/types, types2: pass the seen map through _TypeSet.IsComparable`

assigned findleyr and unassigned griesemer Jan 24, 2022
closed this as completed in ``` 84eefdc ``` Jan 24, 2022
pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
``` go/types, types2: pass the seen map through _TypeSet.IsComparable ```
``` 224c994 ```
```While checking comparability of type parameters, we recurse through
_TypeSet.IsComparable, but do not pass the cycle-tracking seen map,
resulting in infinite recursion in some cases.

Refactor to pass the seen map through this recursion.

Fixes golang#50782

Change-Id: I2c2bcfed3398c11eb9aa0c871da59e348bfba5f7
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>```
Labels
NeedsInvestigation release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants