From: Robert Griesemer Date: Thu, 20 Jul 2023 22:45:24 +0000 (-0700) Subject: [release-branch.go1.21] go/types, types2: a min/max value argument must not be untyped X-Git-Tag: go1.21rc4~13 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2fabb143d778b90a6ba8f9a2730464dd0e83a6a0;p=gostls13.git [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 Auto-Submit: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-on: https://go-review.googlesource.com/c/go/+/511857 Reviewed-by: Cherry Mui --- 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) +}