mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
cmd/gc: make redeclaration between import and func less confusing
Fixes #4510. R=ken2 CC=golang-dev https://golang.org/cl/7001054
This commit is contained in:
parent
8850d14fe9
commit
ae2131ab3b
|
@ -151,16 +151,30 @@ void
|
||||||
redeclare(Sym *s, char *where)
|
redeclare(Sym *s, char *where)
|
||||||
{
|
{
|
||||||
Strlit *pkgstr;
|
Strlit *pkgstr;
|
||||||
|
int line1, line2;
|
||||||
|
|
||||||
if(s->lastlineno == 0) {
|
if(s->lastlineno == 0) {
|
||||||
pkgstr = s->origpkg ? s->origpkg->path : s->pkg->path;
|
pkgstr = s->origpkg ? s->origpkg->path : s->pkg->path;
|
||||||
yyerror("%S redeclared %s\n"
|
yyerror("%S redeclared %s\n"
|
||||||
"\tprevious declaration during import \"%Z\"",
|
"\tprevious declaration during import \"%Z\"",
|
||||||
s, where, pkgstr);
|
s, where, pkgstr);
|
||||||
} else
|
} else {
|
||||||
yyerror("%S redeclared %s\n"
|
line1 = parserline();
|
||||||
|
line2 = s->lastlineno;
|
||||||
|
|
||||||
|
// When an import and a declaration collide in separate files,
|
||||||
|
// present the import as the "redeclared", because the declaration
|
||||||
|
// is visible where the import is, but not vice versa.
|
||||||
|
// See issue 4510.
|
||||||
|
if(s->def == N) {
|
||||||
|
line2 = line1;
|
||||||
|
line1 = s->lastlineno;
|
||||||
|
}
|
||||||
|
|
||||||
|
yyerrorl(line1, "%S redeclared %s (%#N)\n"
|
||||||
"\tprevious declaration at %L",
|
"\tprevious declaration at %L",
|
||||||
s, where, s->lastlineno);
|
s, where, s->def, line2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vargen;
|
static int vargen;
|
||||||
|
|
9
test/fixedbugs/issue4510.dir/f1.go
Normal file
9
test/fixedbugs/issue4510.dir/f1.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// Copyright 2012 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 "fmt" // ERROR "fmt redeclared"
|
||||||
|
|
||||||
|
var _ = fmt.Printf
|
7
test/fixedbugs/issue4510.dir/f2.go
Normal file
7
test/fixedbugs/issue4510.dir/f2.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// Copyright 2012 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
|
||||||
|
|
||||||
|
func fmt() {}
|
7
test/fixedbugs/issue4510.go
Normal file
7
test/fixedbugs/issue4510.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// errorcheckdir
|
||||||
|
|
||||||
|
// Copyright 2012 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 ignored
|
Loading…
Reference in a new issue