]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.unified] cmd/compile/internal/noder: preserve RTTI for select statements
authorMatthew Dempsky <mdempsky@google.com>
Mon, 18 Jul 2022 19:41:56 +0000 (12:41 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 19 Jul 2022 23:30:39 +0000 (23:30 +0000)
commit878439cfe592165bdeaeed037bf1d3351e638853
treed33491449b8207a4fddd8d7371b4599dedc3e6d4
parente376746e54aae4fb519f50bbe42656a2d34df285
[dev.unified] cmd/compile/internal/noder: preserve RTTI for select statements

In a select statement, `case i = <-c: ...` may require an implicit
conversion of the received value to i's type, but walk does not expect
a conversion here. Instead, typecheck actually discards the
conversion (resulting in ill-typed IR), and then relies on it being
reinserted later when walk desugars the assignment.

However, that might lose the explicit RTTI operands we've set for
conversions to interface type, so explicitly introduce a temporary
variable and rewrite as `case tmp := <-c: i = tmp; ...`, which is
semantically equivalent and allows the `i = tmp` assignment to
maintain the explicit RTTI without confusing the rest of the compiler
frontend.

Change-Id: Ie6c4dc9b19437e83970cd3ce83420813b8a47dc4
Reviewed-on: https://go-review.googlesource.com/c/go/+/418098
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/noder/reader.go