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*); ...@@ -657,6 +657,7 @@ int isslice(Type*);
int isinter(Type*); int isinter(Type*);
int isnilinter(Type*); int isnilinter(Type*);
int isddd(Type*); int isddd(Type*);
Type* maptype(Type*, Type*);
Type* dclmethod(Type*); Type* dclmethod(Type*);
Type* methtype(Type*); Type* methtype(Type*);
int methconv(Type*); int methconv(Type*);
......
...@@ -1019,9 +1019,7 @@ convtype: ...@@ -1019,9 +1019,7 @@ convtype:
| LMAP '[' type ']' type | LMAP '[' type ']' type
{ {
// map literal // map literal
$$ = typ(TMAP); $$ = maptype($3, $5);
$$->down = $3;
$$->type = $5;
} }
| structtype | structtype
| '(' type ')' | '(' type ')'
...@@ -1126,9 +1124,7 @@ Aothertype: ...@@ -1126,9 +1124,7 @@ Aothertype:
} }
| LMAP '[' type ']' Atype | LMAP '[' type ']' Atype
{ {
$$ = typ(TMAP); $$ = maptype($3, $5);
$$->down = $3;
$$->type = $5;
} }
| '*' Atype | '*' Atype
{ {
...@@ -1160,9 +1156,7 @@ Bothertype: ...@@ -1160,9 +1156,7 @@ Bothertype:
} }
| LMAP '[' type ']' Btype | LMAP '[' type ']' Btype
{ {
$$ = typ(TMAP); $$ = maptype($3, $5);
$$->down = $3;
$$->type = $5;
} }
| '*' Btype | '*' Btype
{ {
...@@ -1806,9 +1800,7 @@ hidden_type1: ...@@ -1806,9 +1800,7 @@ hidden_type1:
} }
| LMAP '[' hidden_type ']' hidden_type | LMAP '[' hidden_type ']' hidden_type
{ {
$$ = typ(TMAP); $$ = maptype($3, $5);
$$->down = $3;
$$->type = $5;
} }
| LSTRUCT '{' ohidden_structdcl_list '}' | LSTRUCT '{' ohidden_structdcl_list '}'
{ {
......
...@@ -305,6 +305,25 @@ algtype(Type *t) ...@@ -305,6 +305,25 @@ algtype(Type *t)
return a; 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* Node*
list(Node *a, Node *b) 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