diff options
author | Russ Cox <rsc@golang.org> | 2010-06-09 11:00:55 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-06-09 11:00:55 -0700 |
commit | f067c34934cac10bb85820bc236efcf416176daa (patch) | |
tree | d99738fe4769bf42cf63cc85900866a1c2eb5e4a /src/cmd/gc/typecheck.c | |
parent | cc5336b66c854904f622f322aba5f522c6e04f3c (diff) | |
download | golang-f067c34934cac10bb85820bc236efcf416176daa.tar.gz |
gc: more cleanup
* disallow surrogate pair runes.
* diagnose impossible type assertions
* eliminate another static buffer.
* do not overflow lexbuf.
* add -u flag to disable package unsafe.
R=ken2
CC=golang-dev
http://codereview.appspot.com/1619042
Diffstat (limited to 'src/cmd/gc/typecheck.c')
-rw-r--r-- | src/cmd/gc/typecheck.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index d285ad0a7..592166c88 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -52,7 +52,7 @@ typecheck(Node **np, int top) Node *n, *l, *r; NodeList *args; int lno, ok, ntop; - Type *t; + Type *t, *missing, *have; Sym *sym; Val v; char *why; @@ -521,6 +521,18 @@ reswitch: if(n->type == T) goto error; } + if(n->type != T && n->type->etype != TINTER) + if(!implements(n->type, t, &missing, &have)) { + if(have) + yyerror("impossible type assertion: %+N cannot have dynamic type %T" + " (wrong type for %S method)\n\thave %S%hhT\n\twant %S%hhT", + l, n->type, missing->sym, have->sym, have->type, + missing->sym, missing->type); + else + yyerror("impossible type assertion: %+N cannot have dynamic type %T" + " (missing %S method)", l, n->type, missing->sym); + goto error; + } goto ret; case OINDEX: @@ -1179,6 +1191,8 @@ ret: checkwidth(t); } } + if(safemode && isptrto(t, TANY)) + yyerror("cannot use unsafe.Pointer"); evconst(n); if(n->op == OTYPE && !(top & Etype)) { |