]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: use correct predicate when asserting comma-ok types
authorRobert Griesemer <gri@golang.org>
Thu, 18 Apr 2024 15:51:27 +0000 (08:51 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 18 Apr 2024 17:42:47 +0000 (17:42 +0000)
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 <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/testdata/manual.go
src/go/types/check.go
src/go/types/testdata/manual.go
src/internal/types/testdata/fixedbugs/issue66878.go [new file with mode: 0644]

index 6066acdb35f28fe0ef03fb806cb1337849fc3d43..ee7e2e86836a89cf18eb7aa40579c877f19ad751 100644 (file)
@@ -600,7 +600,7 @@ func (check *Checker) recordCommaOkTypes(x syntax.Expr, a []*operand) {
                return
        }
        t0, t1 := a[0].typ, a[1].typ
-       assert(isTyped(t0) && isTyped(t1) && (isBoolean(t1) || t1 == universeError))
+       assert(isTyped(t0) && isTyped(t1) && (allBoolean(t1) || t1 == universeError))
        if m := check.Types; m != nil {
                for {
                        tv := m[x]
index 57dcc227a5980279cc165f7154b3f81cfde1cfd5..d8f312f61d58c50e54cb8e70f9f80dc0a98c05a1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2023 The Go Authors. All rights reserved.
+// Copyright 2024 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
index 87106c4d0195551fd2145f8aeb53e8ecb8f9fb60..94f2bbfd786f005c34a6ab1f294b005cf7234a3d 100644 (file)
@@ -579,7 +579,7 @@ func (check *Checker) recordCommaOkTypes(x ast.Expr, a []*operand) {
                return
        }
        t0, t1 := a[0].typ, a[1].typ
-       assert(isTyped(t0) && isTyped(t1) && (isBoolean(t1) || t1 == universeError))
+       assert(isTyped(t0) && isTyped(t1) && (allBoolean(t1) || t1 == universeError))
        if m := check.Types; m != nil {
                for {
                        tv := m[x]
index 57dcc227a5980279cc165f7154b3f81cfde1cfd5..d8f312f61d58c50e54cb8e70f9f80dc0a98c05a1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2023 The Go Authors. All rights reserved.
+// Copyright 2024 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
diff --git a/src/internal/types/testdata/fixedbugs/issue66878.go b/src/internal/types/testdata/fixedbugs/issue66878.go
new file mode 100644 (file)
index 0000000..bd6315f
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func _[T bool](ch chan T) {
+       var _, _ T = <-ch
+}
+
+// offending code snippets from issue
+
+func _[T ~bool](ch <-chan T) {
+       var x, ok T = <-ch
+       println(x, ok)
+}
+
+func _[T ~bool](m map[int]T) {
+       var x, ok T = m[0]
+       println(x, ok)
+}