aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2023-07-20 15:45:24 -0700
committerGopher Robot <gobot@golang.org>2023-07-21 00:34:06 +0000
commit8abc6e25979ee75e6e01086b94d456255fbe6a4e (patch)
tree7de5d1c9cad30b5dd582257ca621af9141ef17e8 /src
parent4f4c23512e2d5cddfa7024a7e9c217ba357b9978 (diff)
downloadgo-8abc6e25979ee75e6e01086b94d456255fbe6a4e.tar.xz
go/types, types2: a min/max value argument must not be untyped
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>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/types2/builtins.go5
-rw-r--r--src/go/types/builtins.go5
-rw-r--r--src/internal/types/testdata/fixedbugs/issue61486.go9
3 files changed, 19 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go
index f3763862ec..7a209e7a97 100644
--- a/src/cmd/compile/internal/types2/builtins.go
+++ b/src/cmd/compile/internal/types2/builtins.go
@@ -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.
diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go
index 4aee3979d0..35b8755a91 100644
--- a/src/go/types/builtins.go
+++ b/src/go/types/builtins.go
@@ -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
index 0000000000..b12a800f0d
--- /dev/null
+++ b/src/internal/types/testdata/fixedbugs/issue61486.go
@@ -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)
+}