Skip to content

Commit 4cba0bd

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: abort type unification if no progress is made
Fixes #59740. For #59750. Change-Id: I153d0a412bdfb15f81d6999e29691dc093fd0fcb Reviewed-on: https://go-review.googlesource.com/c/go/+/487197 Reviewed-by: Robert Findley <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 598cf5e commit 4cba0bd

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/cmd/compile/internal/types2/unify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const (
4646
// Whether to panic when unificationDepthLimit is reached.
4747
// If disabled, a recursion depth overflow results in a (quiet)
4848
// unification failure.
49-
panicAtUnificationDepthLimit = true
49+
panicAtUnificationDepthLimit = false // go.dev/issue/59740
5050

5151
// If enableCoreTypeUnification is set, unification will consider
5252
// the core types, if any, of non-local (unbound) type parameters.

src/go/types/unify.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
type F[T any] func(func(F[T]))
8+
9+
func f(F[int]) {}
10+
func g[T any](F[T]) {}
11+
12+
func _() {
13+
g(f /* ERROR "type func(F[int]) of f does not match F[T] (cannot infer T)" */) // type inference/unification must not panic
14+
}
15+
16+
// original test case from issue
17+
18+
type List[T any] func(T, func(T, List[T]) T) T
19+
20+
func nil[T any](n T, _ List[T]) T { return n }
21+
func cons[T any](h T, t List[T]) List[T] { return func(n T, f func(T, List[T]) T) T { return f(h, t) } }
22+
23+
func nums[T any](t T) List[T] {
24+
return cons(t, cons(t, nil /* ERROR "type func(n T, _ List[T]) T of nil[T] does not match inferred type List[T] for List[T]" */ [T]))
25+
}

0 commit comments

Comments
 (0)