]> Cypherpunks repositories - gostls13.git/commitdiff
gc: Fail on implicit assigment to non-exported fields in copy and append.
authorLuuk van Dijk <lvd@golang.org>
Wed, 9 Nov 2011 10:17:06 +0000 (11:17 +0100)
committerLuuk van Dijk <lvd@golang.org>
Wed, 9 Nov 2011 10:17:06 +0000 (11:17 +0100)
Fixes #1387.

R=rsc
CC=golang-dev
https://golang.org/cl/5348046

src/cmd/gc/typecheck.c
test/fixedbugs/bug378.go [new file with mode: 0644]

index f154db9eb4840dd65ae1d13b7bcdd01e575c1b63..f84f8440c4d43fdf7801640ff4b684aa031c109f 100644 (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:
diff --git a/test/fixedbugs/bug378.go b/test/fixedbugs/bug378.go
new file mode 100644 (file)
index 0000000..91975f2
--- /dev/null
@@ -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"
+}