1
0
mirror of https://github.com/golang/go synced 2024-11-22 09:04:42 -07:00

cmd/gc: reject methods on non-locals, even if symbol exists

Fixes #5089.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7767044
This commit is contained in:
Daniel Morsing 2013-03-20 22:18:20 +01:00
parent d3c758d7d2
commit 7c3694c4de
2 changed files with 21 additions and 6 deletions

View File

@ -1380,6 +1380,12 @@ addmethod(Sym *sf, Type *t, int local, int nointerface)
}
}
if(local && !pa->local) {
// defining method on non-local type.
yyerror("cannot define new methods on non-local type %T", pa);
return;
}
n = nod(ODCLFIELD, newname(sf), N);
n->type = t;
@ -1395,12 +1401,6 @@ addmethod(Sym *sf, Type *t, int local, int nointerface)
return;
}
if(local && !pa->local) {
// defining method on non-local type.
yyerror("cannot define new methods on non-local type %T", pa);
return;
}
f = structfield(n);
f->nointerface = nointerface;

View File

@ -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.
// issue 5089: gc allows methods on non-locals if symbol already exists
package p
import "bufio"
func (b *bufio.Reader) Buffered() int { // ERROR "non-local"
return -1
}