Skip to content

Commit

Permalink
[release-branch.go1.21] go/types, types2: a min/max value argument mu…
Browse files Browse the repository at this point in the history
…st 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>
  • Loading branch information
griesemer authored and Robert Griesemer committed Jul 21, 2023
1 parent c9f01f0 commit 2fabb14
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cmd/compile/internal/types2/builtins.go
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/go/types/builtins.go
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions 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)
}

0 comments on commit 2fabb14

Please sign in to comment.