Skip to content

Commit 8abc6e2

Browse files
griesemergopherbot
authored andcommitted
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>
1 parent 4f4c235 commit 8abc6e2

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/cmd/compile/internal/types2/builtins.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
576576
// If nargs == 1, make sure x.mode is either a value or a constant.
577577
if x.mode != constant_ {
578578
x.mode = value
579+
// A value must not be untyped.
580+
check.assignment(x, &emptyInterface, "argument to "+bin.name)
581+
if x.mode == invalid {
582+
return
583+
}
579584
}
580585

581586
// Use the final type computed above for all arguments.

src/go/types/builtins.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
575575
// If nargs == 1, make sure x.mode is either a value or a constant.
576576
if x.mode != constant_ {
577577
x.mode = value
578+
// A value must not be untyped.
579+
check.assignment(x, &emptyInterface, "argument to "+bin.name)
580+
if x.mode == invalid {
581+
return
582+
}
578583
}
579584

580585
// Use the final type computed above for all arguments.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
func _(s uint) {
8+
_ = min(1 << s)
9+
}

0 commit comments

Comments
 (0)