diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c index cfb1f0adef2..a725ea971cd 100644 --- a/src/cmd/gc/const.c +++ b/src/cmd/gc/const.c @@ -1144,7 +1144,10 @@ defaultlit(Node **np, Type *t) } if(n->val.ctype == CTNIL) { lineno = lno; - yyerror("use of untyped nil"); + if(!n->diag) { + yyerror("use of untyped nil"); + n->diag = 1; + } n->type = T; break; } diff --git a/test/fixedbugs/issue6402.go b/test/fixedbugs/issue6402.go new file mode 100644 index 00000000000..da5980c9ab6 --- /dev/null +++ b/test/fixedbugs/issue6402.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2014 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. + +// Issue 6402: spurious 'use of untyped nil' error + +package p + +func f() uintptr { + return nil // ERROR "cannot use nil as type uintptr in return argument" +}