Commit 98b34e5b authored by Russ Cox's avatar Russ Cox

reject invalid map key types at compile time

R=ken
OCL=25720
CL=25720
parent 0793c883
......@@ -657,6 +657,7 @@ int isslice(Type*);
int isinter(Type*);
int isnilinter(Type*);
int isddd(Type*);
Type* maptype(Type*, Type*);
Type* dclmethod(Type*);
Type* methtype(Type*);
int methconv(Type*);
......
......@@ -1019,9 +1019,7 @@ convtype:
| LMAP '[' type ']' type
{
// map literal
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
$$ = maptype($3, $5);
}
| structtype
| '(' type ')'
......@@ -1126,9 +1124,7 @@ Aothertype:
}
| LMAP '[' type ']' Atype
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
$$ = maptype($3, $5);
}
| '*' Atype
{
......@@ -1160,9 +1156,7 @@ Bothertype:
}
| LMAP '[' type ']' Btype
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
$$ = maptype($3, $5);
}
| '*' Btype
{
......@@ -1806,9 +1800,7 @@ hidden_type1:
}
| LMAP '[' hidden_type ']' hidden_type
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
$$ = maptype($3, $5);
}
| LSTRUCT '{' ohidden_structdcl_list '}'
{
......
......@@ -305,6 +305,25 @@ algtype(Type *t)
return a;
}
Type*
maptype(Type *key, Type *val)
{
Type *t;
if(key != nil && key->etype != TANY && algtype(key) == ANOEQ)
yyerror("invalid map key type %T", key);
t = typ(TMAP);
t->down = key;
t->type = val;
return t;
}
int
iskeytype(Type *t)
{
return algtype(t) != ANOEQ;
}
Node*
list(Node *a, Node *b)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment