]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: convert untyped arguments to delete
authorMatthew Dempsky <mdempsky@google.com>
Thu, 21 Jan 2021 01:03:36 +0000 (17:03 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 21 Jan 2021 01:24:50 +0000 (01:24 +0000)
For the predeclared "delete" function, types2 was checking that the
second argument was assignable to the map's key type, but not actually
updating the Types map as appropriate. So this could leave untyped
constants in the AST.

The error "cannot convert" is somewhat less precise than the previous
"not assignable" error, but it's consistent with how types2 reports
other erroneous assignments of untyped constants.

Change-Id: Ic3ca3a3611ad0e4646c050e93088cdf992234e5f
Reviewed-on: https://go-review.googlesource.com/c/go/+/285059
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

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

index 43da6a15293055acfcc597c0c32b051aeda45446..bd1ea0fdc14c739969d8348dbad09cdfbcf346e8 100644 (file)
@@ -368,8 +368,8 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        return
                }
 
-               if !x.assignableTo(check, m.key, nil) {
-                       check.invalidArgf(x, "%s is not assignable to %s", x, m.key)
+               check.assignment(x, m.key, "argument to delete")
+               if x.mode == invalid {
                        return
                }
 
index 69cc48798e24d61a85ed9a1fef76d971a91a34bb..e473bd1df21c617749a25cf585b24c3e7a88c62f 100644 (file)
@@ -283,7 +283,7 @@ func delete1() {
        delete() // ERROR not enough arguments
        delete(1) // ERROR not enough arguments
        delete(1, 2, 3) // ERROR too many arguments
-       delete(m, 0 /* ERROR not assignable */)
+       delete(m, 0 /* ERROR cannot convert */)
        delete(m, s)
        _ = delete /* ERROR used as value */ (m, s)