Skip to content

Commit ad87d44

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: use correct predicate when asserting comma-ok types
While at it and unrelated, up-date testdata/manual.go sample file so we can just copy its contents into a test file after debugging, without fixing the date. Fixes #66878. Change-Id: Ie49a341b78d99bdc0f1a0ba1ca42fa2d3a807bd6 Reviewed-on: https://go-review.googlesource.com/c/go/+/580075 Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent a0205e6 commit ad87d44

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/cmd/compile/internal/types2/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func (check *Checker) recordCommaOkTypes(x syntax.Expr, a []*operand) {
600600
return
601601
}
602602
t0, t1 := a[0].typ, a[1].typ
603-
assert(isTyped(t0) && isTyped(t1) && (isBoolean(t1) || t1 == universeError))
603+
assert(isTyped(t0) && isTyped(t1) && (allBoolean(t1) || t1 == universeError))
604604
if m := check.Types; m != nil {
605605
for {
606606
tv := m[x]

src/cmd/compile/internal/types2/testdata/manual.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The Go Authors. All rights reserved.
1+
// Copyright 2024 The Go Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

src/go/types/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ func (check *Checker) recordCommaOkTypes(x ast.Expr, a []*operand) {
579579
return
580580
}
581581
t0, t1 := a[0].typ, a[1].typ
582-
assert(isTyped(t0) && isTyped(t1) && (isBoolean(t1) || t1 == universeError))
582+
assert(isTyped(t0) && isTyped(t1) && (allBoolean(t1) || t1 == universeError))
583583
if m := check.Types; m != nil {
584584
for {
585585
tv := m[x]

src/go/types/testdata/manual.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The Go Authors. All rights reserved.
1+
// Copyright 2024 The Go Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
func _[T bool](ch chan T) {
8+
var _, _ T = <-ch
9+
}
10+
11+
// offending code snippets from issue
12+
13+
func _[T ~bool](ch <-chan T) {
14+
var x, ok T = <-ch
15+
println(x, ok)
16+
}
17+
18+
func _[T ~bool](m map[int]T) {
19+
var x, ok T = m[0]
20+
println(x, ok)
21+
}

0 commit comments

Comments
 (0)