]> Cypherpunks.ru repositories - gostls13.git/commit
go/types, types2: remove order dependency in inference involving channels
authorRobert Griesemer <gri@golang.org>
Mon, 21 Aug 2023 22:50:18 +0000 (15:50 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 29 Aug 2023 23:22:35 +0000 (23:22 +0000)
commit1f8f2ab9661c78876d8a8cb0ccc4625728842b26
tree29272789038044c8173a49aec8bb2c246312c5c1
parent22eba6a1f8421425c87fa82dcd526d39912f5af6
go/types, types2: remove order dependency in inference involving channels

In inexact unification, when a named type matches against an inferred
unnamed type, we change the previously inferred type to the named type.
This preserves the type name and assignability.

We have to do the same thing when encountering a directional channel:
a bidirectional channel can always be assigned to a directional channel
but not the other way around. Thus, if we see a directional channel, we
must choose the directional channel.

This CL extends the previously existing logic for named types to
directional channels and also makes the code conditional on inexact
unification. The latter is an optimization - if unification is exact,
type differences don't exist and updating an already inferred type has
no effect.

Fixes #62157.

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