Commit 151b2f15 authored by Luuk van Dijk's avatar Luuk van Dijk

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
parent 13e92e4d
...@@ -1032,6 +1032,9 @@ reswitch: ...@@ -1032,6 +1032,9 @@ reswitch:
yyerror("first argument to append must be slice; have %lT", t); yyerror("first argument to append must be slice; have %lT", t);
goto error; goto error;
} }
if(!exportassignok(t->type, "append"))
goto error;
if(n->isddd) { if(n->isddd) {
if(args->next == nil) { if(args->next == nil) {
yyerror("cannot use ... on first argument to append"); yyerror("cannot use ... on first argument to append");
...@@ -1098,6 +1101,8 @@ reswitch: ...@@ -1098,6 +1101,8 @@ reswitch:
yyerror("arguments to copy have different element types: %lT and %lT", n->left->type, n->right->type); yyerror("arguments to copy have different element types: %lT and %lT", n->left->type, n->right->type);
goto error; goto error;
} }
if(!exportassignok(n->left->type->type, "copy"))
goto error;
goto ret; goto ret;
case OCONV: case OCONV:
......
// 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"
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment