]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: a min/max value argument must not be untyped
authorRobert Griesemer <gri@golang.org>
Thu, 20 Jul 2023 22:45:24 +0000 (15:45 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 21 Jul 2023 00:34:06 +0000 (00:34 +0000)
Fixes #61486.

Change-Id: I5770e238e44b724816894d914b3ea5dc78bc3ced
Reviewed-on: https://go-review.googlesource.com/c/go/+/511835
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/types2/builtins.go
src/go/types/builtins.go
src/internal/types/testdata/fixedbugs/issue61486.go [new file with mode: 0644]

index f3763862ec8dbc77dbc35c47cde68b3b178d3db5..7a209e7a9720b6b344d1bd1b58d75605ffa793e4 100644 (file)
@@ -576,6 +576,11 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // If nargs == 1, make sure x.mode is either a value or a constant.
                if x.mode != constant_ {
                        x.mode = value
+                       // A value must not be untyped.
+                       check.assignment(x, &emptyInterface, "argument to "+bin.name)
+                       if x.mode == invalid {
+                               return
+                       }
                }
 
                // Use the final type computed above for all arguments.
index 4aee3979d003a2b3962aef908d0372574b7c2e0c..35b8755a91556cc903ea66ab481368bd8671fb48 100644 (file)
@@ -575,6 +575,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // If nargs == 1, make sure x.mode is either a value or a constant.
                if x.mode != constant_ {
                        x.mode = value
+                       // A value must not be untyped.
+                       check.assignment(x, &emptyInterface, "argument to "+bin.name)
+                       if x.mode == invalid {
+                               return
+                       }
                }
 
                // Use the final type computed above for all arguments.
diff --git a/src/internal/types/testdata/fixedbugs/issue61486.go b/src/internal/types/testdata/fixedbugs/issue61486.go
new file mode 100644 (file)
index 0000000..b12a800
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2023 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 _(s uint) {
+       _ = min(1 << s)
+}