1
0
mirror of https://github.com/golang/go synced 2024-11-25 04:07:55 -07:00

gc: relax assignability of method receivers

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
This commit is contained in:
Anthony Martin 2011-05-24 19:48:19 -04:00 committed by Russ Cox
parent 3857747dce
commit 0b209b36b6
6 changed files with 8 additions and 14 deletions

View File

@ -822,7 +822,13 @@ reswitch:
case ODOTMETH: case ODOTMETH:
n->op = OCALLMETH; 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; break;
default: default:

View File

@ -15,7 +15,7 @@ func f() {
_ = x.T{}; _ = x.T{};
_ = x.T{Y:2}; _ = x.T{Y:2};
ok1.M(); // ERROR "assignment.*T" ok1.M();
bad1 := *ok; // ERROR "assignment.*T" bad1 := *ok; // ERROR "assignment.*T"
bad2 := ok1; // ERROR "assignment.*T" bad2 := ok1; // ERROR "assignment.*T"
*ok4 = ok1; // ERROR "assignment.*T" *ok4 = ok1; // ERROR "assignment.*T"

View File

@ -38,10 +38,3 @@ func main() {
var pi2 PI = pt var pi2 PI = pt
pi2.PM() 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
*/

View File

@ -161,8 +161,3 @@ panic: interface conversion: interface is main.T, not main.T
0x0 0x0
== bugs/ == 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