From: Russ Cox Date: Mon, 9 Sep 2013 16:49:39 +0000 (-0400) Subject: cmd/gc: diagnose '_ = nil' better X-Git-Tag: go1.2rc2~306 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=903c2fda18825f1f8b276c92325f84f52bc71071;p=gostls13.git cmd/gc: diagnose '_ = nil' better Fixes #6004. R=ken2 CC=golang-dev https://golang.org/cl/13616044 --- diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index 2f617ac9d0..079ca305d5 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -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 index 0000000000..45aaffd2c9 --- /dev/null +++ b/test/fixedbugs/issue6004.go @@ -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" +} +