]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: no need to revert tparam renaming in inference results
authorRobert Findley <rfindley@google.com>
Mon, 14 Feb 2022 01:27:55 +0000 (20:27 -0500)
committerRobert Findley <rfindley@google.com>
Mon, 14 Feb 2022 12:26:56 +0000 (12:26 +0000)
This is a follow up to CL 385494. In early patch sets of that CL,
renamed type parameters were substituted in arguments, which meant that
they could leak into the inference results. However, we subsequently
realized that we could instead substitute in the signature parameters.
In this case it is not possible for the substituted type parameters to
appear in the resulting type arguments, so there is no need to
un-substitute.

Change-Id: I4da45b0b8d7ad809d0ddfa7061ae5f6f07895540
Reviewed-on: https://go-review.googlesource.com/c/go/+/385574
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/types2/infer.go
src/go/types/infer.go

index 6259e287aeda074d4769c5fb6d4557839d649c78..2d6f26c0c92f885adb139b4d3617fc0bb3fbc7c0 100644 (file)
@@ -116,16 +116,6 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
 
                        tparams = tparams2
                        params = check.subst(pos, params, renameMap, nil).(*Tuple)
-
-                       // If we replaced any type parameters, their replacements may occur in
-                       // the resulting inferred type arguments. Make sure we use the original
-                       // type parameters in the result.
-                       defer func() {
-                               unrenameMap := makeRenameMap(tparams2, tparams)
-                               for i, res := range result {
-                                       result[i] = check.subst(pos, res, unrenameMap, nil)
-                               }
-                       }()
                }
        }
 
index 18ec81edd438b0af5ce580d69a10a3a975b57aad..8f22144c839128f1995ac36da9741c4a36296202 100644 (file)
@@ -115,16 +115,6 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
 
                        tparams = tparams2
                        params = check.subst(posn.Pos(), params, renameMap, nil).(*Tuple)
-
-                       // If we replaced any type parameters, their replacements may occur in
-                       // the resulting inferred type arguments. Make sure we use the original
-                       // type parameters in the result.
-                       defer func() {
-                               unrenameMap := makeRenameMap(tparams2, tparams)
-                               for i, res := range result {
-                                       result[i] = check.subst(posn.Pos(), res, unrenameMap, nil)
-                               }
-                       }()
                }
        }