]> Cypherpunks repositories - gostls13.git/commitdiff
gc: relax assignability of method receivers
authorAnthony Martin <ality@pbrane.org>
Tue, 24 May 2011 23:48:19 +0000 (19:48 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 24 May 2011 23:48:19 +0000 (19:48 -0400)
The spec was adjusted in commit df410d6a4842 to allow the
implicit assignment of strutures with unexported fields in
method receivers.  This change updates the compiler.

Also moved bug322 into fixedbugs and updated golden.out
to reflect the removal of the last known bug.

Fixes #1402.

R=golang-dev, gri, rsc
CC=golang-dev
https://golang.org/cl/4526069

src/cmd/gc/typecheck.c
test/fixedbugs/bug226.dir/y.go
test/fixedbugs/bug322.dir/lib.go [moved from test/bugs/bug322.dir/lib.go with 100% similarity]
test/fixedbugs/bug322.dir/main.go [moved from test/bugs/bug322.dir/main.go with 69% similarity]
test/fixedbugs/bug322.go [moved from test/bugs/bug322.go with 100% similarity]
test/golden.out

index 9aaf3e6efe02747ec90d044cc52e2e7413633b3e..0cf11684dae8ec23e3bde32d2da46a2fa64d6b60 100644 (file)
@@ -822,7 +822,13 @@ reswitch:
 
                case ODOTMETH:
                        n->op = OCALLMETH;
-                       typecheckaste(OCALL, n->left, 0, getthisx(t), list1(l->left), "method receiver");
+                       // typecheckaste was used here but there wasn't enough
+                       // information further down the call chain to know if we
+                       // were testing a method receiver for unexported fields.
+                       // It isn't necessary, so just do a sanity check.
+                       tp = getthisx(t)->type->type;
+                       if(l->left == N || !eqtype(l->left->type, tp))
+                               fatal("method receiver");
                        break;
 
                default:
index 01e8b7b4373da11bbaa59661b33ef2b0754fd01b..c66d592b7c01166418656a060180705c9620c02a 100644 (file)
@@ -15,7 +15,7 @@ func f() {
        _ = x.T{};
        _ = x.T{Y:2};
        
-       ok1.M();        // ERROR "assignment.*T"
+       ok1.M();
        bad1 := *ok;    // ERROR "assignment.*T"
        bad2 := ok1;    // ERROR "assignment.*T"
        *ok4 = ok1;     // ERROR "assignment.*T"
similarity index 69%
rename from test/bugs/bug322.dir/main.go
rename to test/fixedbugs/bug322.dir/main.go
index 0ab5b32e4536429089ef075fee995a2fc9978388..f403c7d32e2ac187a054100c679d97aa1c73a851 100644 (file)
@@ -38,10 +38,3 @@ func main() {
        var pi2 PI = pt
        pi2.PM()
 }
-
-/*
-These should not be errors anymore:
-
-bug322.dir/main.go:19: implicit assignment of unexported field 'x' of lib.T in method receiver
-bug322.dir/main.go:32: implicit assignment of unexported field 'x' of lib.T in method receiver
-*/
similarity index 100%
rename from test/bugs/bug322.go
rename to test/fixedbugs/bug322.go
index 725e8de448e66e985f6d5c8009ea0ee49576bc4d..4400e41dd147545e9fdac29e0aaaf37164e63023 100644 (file)
@@ -161,8 +161,3 @@ panic: interface conversion: interface is main.T, not main.T
 0x0
 
 == bugs/
-
-=========== bugs/bug322.go
-bugs/bug322.dir/main.go:19: implicit assignment of unexported field 'x' of lib.T in method receiver
-bugs/bug322.dir/main.go:32: implicit assignment of unexported field 'x' of lib.T in method receiver
-BUG: fails incorrectly