]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: diagnose '_ = nil' better
authorRuss Cox <rsc@golang.org>
Mon, 9 Sep 2013 16:49:39 +0000 (12:49 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 9 Sep 2013 16:49:39 +0000 (12:49 -0400)
Fixes #6004.

R=ken2
CC=golang-dev
https://golang.org/cl/13616044

src/cmd/gc/subr.c
test/fixedbugs/issue6004.go [new file with mode: 0644]

index 2f617ac9d0feab81d5dd852bb952150511923081..079ca305d5865e014ff4d9fb4a51ea28f003d26b 100644 (file)
@@ -1411,6 +1411,9 @@ assignconv(Node *n, Type *t, char *context)
        if(n == N || n->type == T || n->type->broke)
                return n;
 
+       if(t->etype == TBLANK && n->type->etype == TNIL)
+               yyerror("use of untyped nil");
+
        old = n;
        old->diag++;  // silence errors about n; we'll issue one below
        defaultlit(&n, t);
diff --git a/test/fixedbugs/issue6004.go b/test/fixedbugs/issue6004.go
new file mode 100644 (file)
index 0000000..45aaffd
--- /dev/null
@@ -0,0 +1,15 @@
+// errorcheck
+
+// Copyright 2013 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 main
+
+func main() {
+       _ = nil // ERROR "use of untyped nil"
+       _, _ = nil, 1 // ERROR "use of untyped nil"
+       _, _ = 1, nil // ERROR "use of untyped nil"
+       _ = append(nil, 1, 2, 3) // ERROR "untyped nil"
+}
+