diff options
author | Robert Griesemer <gri@golang.org> | 2023-07-20 15:45:24 -0700 |
---|---|---|
committer | Robert Griesemer <gri@google.com> | 2023-07-21 03:06:31 +0000 |
commit | 2fabb143d778b90a6ba8f9a2730464dd0e83a6a0 (patch) | |
tree | 9809d25b524bd5c7e243cc9e525a01999bb873e5 | |
parent | c9f01f0ec7ce43a21bb7bbc65ec1a28a27187ce7 (diff) | |
download | go-2fabb143d778b90a6ba8f9a2730464dd0e83a6a0.tar.gz go-2fabb143d778b90a6ba8f9a2730464dd0e83a6a0.zip |
[release-branch.go1.21] go/types, types2: a min/max value argument must not be untyped
Fizes #61492.
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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/511857
Reviewed-by: Cherry Mui <cherryyz@google.com>
-rw-r--r-- | src/cmd/compile/internal/types2/builtins.go | 5 | ||||
-rw-r--r-- | src/go/types/builtins.go | 5 | ||||
-rw-r--r-- | src/internal/types/testdata/fixedbugs/issue61486.go | 9 |
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 7795f2552d..11eacef806 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) +} |