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

gc: Fail on implicit assigment to non-exported fields in copy and append.

Fixes #1387.

R=rsc
CC=golang-dev
https://golang.org/cl/5348046
This commit is contained in:
Luuk van Dijk 2011-11-09 11:17:06 +01:00
parent 13e92e4d75
commit 151b2f1509
2 changed files with 32 additions and 0 deletions

View File

@ -1032,6 +1032,9 @@ reswitch:
yyerror("first argument to append must be slice; have %lT", t);
goto error;
}
if(!exportassignok(t->type, "append"))
goto error;
if(n->isddd) {
if(args->next == nil) {
yyerror("cannot use ... on first argument to append");
@ -1098,6 +1101,8 @@ reswitch:
yyerror("arguments to copy have different element types: %lT and %lT", n->left->type, n->right->type);
goto error;
}
if(!exportassignok(n->left->type->type, "copy"))
goto error;
goto ret;
case OCONV:

27
test/fixedbugs/bug378.go Normal file
View File

@ -0,0 +1,27 @@
// errchk $G $D/$F.go
// Copyright 2011 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 1387
package foo
import "bytes"
func i() {
a := make([]bytes.Buffer, 1)
b := a[0] // ERROR "unexported field"
}
func f() {
a := make([]bytes.Buffer, 1)
a = append(a, a...) // ERROR "unexported field"
}
func g() {
a := make([]bytes.Buffer, 1)
b := make([]bytes.Buffer, 1)
copy(b, a) // ERROR "unexported field"
}