From 2fabb143d778b90a6ba8f9a2730464dd0e83a6a0 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 20 Jul 2023 15:45:24 -0700 Subject: [PATCH] [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 --- src/cmd/compile/internal/types2/builtins.go | 5 +++++ src/go/types/builtins.go | 5 +++++ src/internal/types/testdata/fixedbugs/issue61486.go | 9 +++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/internal/types/testdata/fixedbugs/issue61486.go diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go index f3763862ec8db..7a209e7a9720b 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 7795f2552dde3..11eacef80638f 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 0000000000000..b12a800f0d9e8 --- /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) +}