]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: use inexact unification when unifying against core types
authorRobert Griesemer <gri@golang.org>
Tue, 6 Jun 2023 21:30:31 +0000 (14:30 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 12 Jun 2023 16:27:51 +0000 (16:27 +0000)
Follow-up on CL 498955 which introduced a unification mode, to be used
to control the precision of unification of element types (CL 498895):
When unifying against core types of unbound type parameters, we must
use inexact unification at the top (irrespective of the unification mode),
otherwise it may fail when unifying against a defined type (core types
are always underlying types).

No specific test case (I have not been able to create one yet).

Change-Id: Ie15e98f4b9e9fb60d6857d34b03d350ebbf0375e
Reviewed-on: https://go-review.googlesource.com/c/go/+/501302
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>

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

index 10c4ec7632d8d162dabb9549f50b4ca3dcf1d9d8..48adc185c379232b979bc6e4775346c64af6a6d3 100644 (file)
@@ -700,7 +700,11 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
                                if traceInference {
                                        u.tracef("core %s ≡ %s", x, y)
                                }
-                               return u.nify(cx, y, mode, p)
+                               // If y is a defined type, it may not match against cx which
+                               // is an underlying type (incl. int, string, etc.). Use assign
+                               // mode here so that the unifier automatically takes under(y)
+                               // if necessary.
+                               return u.nify(cx, y, assign, p)
                        }
                }
                // x != y and there's nothing to do
index d704a27f7c739425e5899835091d1606a20f7890..3ecc80f1616281b7e11dca24fe58b67237e43a97 100644 (file)
@@ -702,7 +702,11 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
                                if traceInference {
                                        u.tracef("core %s ≡ %s", x, y)
                                }
-                               return u.nify(cx, y, mode, p)
+                               // If y is a defined type, it may not match against cx which
+                               // is an underlying type (incl. int, string, etc.). Use assign
+                               // mode here so that the unifier automatically takes under(y)
+                               // if necessary.
+                               return u.nify(cx, y, assign, p)
                        }
                }
                // x != y and there's nothing to do