]> Cypherpunks.ru repositories - gostls13.git/commitdiff
types2, go/types: record final type for min/max arguments
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sun, 25 Jun 2023 15:59:33 +0000 (22:59 +0700)
committerGopher Robot <gobot@golang.org>
Mon, 26 Jun 2023 17:08:05 +0000 (17:08 +0000)
Fixes #60991

Change-Id: I6130ccecbdc209996dbb376491be9df3b8988327
Reviewed-on: https://go-review.googlesource.com/c/go/+/506055
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/types2/builtins.go
src/go/types/builtins.go
test/fixedbugs/issue60991.go [new file with mode: 0644]

index a3e1981af6e6e6ea58bfd3105a27858bfba3b45d..f3763862ec8dbc77dbc35c47cde68b3b178d3db5 100644 (file)
@@ -578,6 +578,11 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        x.mode = value
                }
 
+               // Use the final type computed above for all arguments.
+               for _, a := range args {
+                       check.updateExprType(a.expr, x.typ, true)
+               }
+
                if check.recordTypes() && x.mode != constant_ {
                        types := make([]Type, nargs)
                        for i := range types {
index 837a9b5e14d632e2a2c9aa48dd5fb7e6d464c289..7795f2552dde3d847b51c1ea4347283539d5467e 100644 (file)
@@ -577,6 +577,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        x.mode = value
                }
 
+               // Use the final type computed above for all arguments.
+               for _, a := range args {
+                       check.updateExprType(a.expr, x.typ, true)
+               }
+
                if check.recordTypes() && x.mode != constant_ {
                        types := make([]Type, nargs)
                        for i := range types {
diff --git a/test/fixedbugs/issue60991.go b/test/fixedbugs/issue60991.go
new file mode 100644 (file)
index 0000000..e1d51e4
--- /dev/null
@@ -0,0 +1,13 @@
+// build
+
+// 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
+
+import "math"
+
+func f() {
+       _ = min(0.1, 0.2, math.Sqrt(1))
+}