{
Sym *s;
int local;
+ int maplineno, lno;
s = n->sym;
if(s == S || s->def == N || s->def->op != OTYPE || s->def->type != n)
// type n t;
// copy t, but then zero out state associated with t
// that is no longer associated with n.
+ maplineno = n->maplineno;
local = n->local;
*n = *t;
n->sym = s;
n->method = nil;
n->vargen = 0;
n->nod = N;
+
// catch declaration of incomplete type
switch(n->etype) {
case TFORWSTRUCT:
default:
checkwidth(n);
}
+
+ // double-check use of type as map key
+ if(maplineno) {
+ lno = lineno;
+ lineno = maplineno;
+ maptype(n, types[TBOOL]);
+ lineno = lno;
+ }
}
// TARRAY
int32 bound; // negative is dynamic array
+
+ int32 maplineno; // first use of TFORW as map key
};
#define T ((Type*)0)
{
Type *t;
- if(key != nil && key->etype != TANY && algtype(key) == ANOEQ)
- yyerror("invalid map key type %T", key);
+ if(key != nil && key->etype != TANY && algtype(key) == ANOEQ) {
+ if(key->etype == TFORW) {
+ // map[key] used during definition of key.
+ // postpone check until key is fully defined.
+ // if there are multiple uses of map[key]
+ // before key is fully defined, the error
+ // will only be printed for the first one.
+ // good enough.
+ if(key->maplineno == 0)
+ key->maplineno = lineno;
+ } else
+ yyerror("invalid map key type %T", key);
+ }
t = typ(TMAP);
t->down = key;
t->type = val;
package main
type I interface {
- m(map[I] bool)
+ m(map[I] bool); // ok
+}
+
+type S struct {
+ m map[S] bool; // ERROR "map key type"
}
=========== bugs/bug164.go
BUG: should not compile
-=========== bugs/bug165.go
-bugs/bug165.go:6: invalid map key type I
-BUG: should compile
-
=========== fixedbugs/bug016.go
fixedbugs/bug016.go:7: constant -3 overflows uint