]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: abort type unification if no progress is made
authorRobert Griesemer <gri@golang.org>
Fri, 21 Apr 2023 02:27:23 +0000 (19:27 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 21 Apr 2023 12:32:24 +0000 (12:32 +0000)
Fixes #59740.
For #59750.

Change-Id: I153d0a412bdfb15f81d6999e29691dc093fd0fcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/487197
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/types2/unify.go
src/go/types/unify.go
src/internal/types/testdata/fixedbugs/issue59740.go [new file with mode: 0644]

index a5ccc6eb41cdcc2b62ff53e48cf49acba1d2a6af..3c4027d1899c20b48f43a7392de17f468d343006 100644 (file)
@@ -46,7 +46,7 @@ const (
        // Whether to panic when unificationDepthLimit is reached.
        // If disabled, a recursion depth overflow results in a (quiet)
        // unification failure.
-       panicAtUnificationDepthLimit = true
+       panicAtUnificationDepthLimit = false // go.dev/issue/59740
 
        // If enableCoreTypeUnification is set, unification will consider
        // the core types, if any, of non-local (unbound) type parameters.
index 107e569380579a6b1a78c923bcc42ea748385e51..9d89a687de27d461549da6ff01674b0adc0ddb60 100644 (file)
@@ -48,7 +48,7 @@ const (
        // Whether to panic when unificationDepthLimit is reached.
        // If disabled, a recursion depth overflow results in a (quiet)
        // unification failure.
-       panicAtUnificationDepthLimit = true
+       panicAtUnificationDepthLimit = false // go.dev/issue/59740
 
        // If enableCoreTypeUnification is set, unification will consider
        // the core types, if any, of non-local (unbound) type parameters.
diff --git a/src/internal/types/testdata/fixedbugs/issue59740.go b/src/internal/types/testdata/fixedbugs/issue59740.go
new file mode 100644 (file)
index 0000000..31cd03b
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2023 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 F[T any] func(func(F[T]))
+
+func f(F[int])      {}
+func g[T any](F[T]) {}
+
+func _() {
+       g(f /* ERROR "type func(F[int]) of f does not match F[T] (cannot infer T)" */) // type inference/unification must not panic
+}
+
+// original test case from issue
+
+type List[T any] func(T, func(T, List[T]) T) T
+
+func nil[T any](n T, _ List[T]) T        { return n }
+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) } }
+
+func nums[T any](t T) List[T] {
+       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]))
+}