From: Robert Griesemer Date: Tue, 6 Jun 2023 21:30:31 +0000 (-0700) Subject: go/types, types2: use inexact unification when unifying against core types X-Git-Tag: go1.21rc1~34 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f35d2dae74d12b06df061d909cb9721f27208a15;p=gostls13.git go/types, types2: use inexact unification when unifying against core types 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 Reviewed-by: Robert Findley Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer Run-TryBot: Robert Griesemer --- diff --git a/src/cmd/compile/internal/types2/unify.go b/src/cmd/compile/internal/types2/unify.go index 10c4ec7632..48adc185c3 100644 --- a/src/cmd/compile/internal/types2/unify.go +++ b/src/cmd/compile/internal/types2/unify.go @@ -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 diff --git a/src/go/types/unify.go b/src/go/types/unify.go index d704a27f7c..3ecc80f161 100644 --- a/src/go/types/unify.go +++ b/src/go/types/unify.go @@ -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