** Raises an error if variable described by 'e' is read only; moreover, ** if 'e' is t[exp] where t is the vararg parameter, change it to index ** a real table. (Virtual vararg tables cannot be changed.) */
| 284 | ** a real table. (Virtual vararg tables cannot be changed.) |
| 285 | */ |
| 286 | static void check_readonly (LexState *ls, expdesc *e) { |
| 287 | FuncState *fs = ls->fs; |
| 288 | TString *varname = NULL; /* to be set if variable is const */ |
| 289 | switch (e->k) { |
| 290 | case VCONST: { |
| 291 | varname = ls->dyd->actvar.arr[e->u.info].vd.name; |
| 292 | break; |
| 293 | } |
| 294 | case VLOCAL: case VVARGVAR: { |
| 295 | Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx); |
| 296 | if (vardesc->vd.kind != VDKREG) /* not a regular variable? */ |
| 297 | varname = vardesc->vd.name; |
| 298 | break; |
| 299 | } |
| 300 | case VUPVAL: { |
| 301 | Upvaldesc *up = &fs->f->upvalues[e->u.info]; |
| 302 | if (up->kind != VDKREG) |
| 303 | varname = up->name; |
| 304 | break; |
| 305 | } |
| 306 | case VVARGIND: { |
| 307 | needvatab(fs->f); /* function will need a vararg table */ |
| 308 | e->k = VINDEXED; |
| 309 | } /* FALLTHROUGH */ |
| 310 | case VINDEXUP: case VINDEXSTR: case VINDEXED: { /* global variable */ |
| 311 | if (e->u.ind.ro) /* read-only? */ |
| 312 | varname = tsvalue(&fs->f->k[e->u.ind.keystr]); |
| 313 | break; |
| 314 | } |
| 315 | default: |
| 316 | lua_assert(e->k == VINDEXI); /* this one doesn't need any check */ |
| 317 | return; /* integer index cannot be read-only */ |
| 318 | } |
| 319 | if (varname) |
| 320 | luaK_semerror(ls, "attempt to assign to const variable '%s'", |
| 321 | getstr(varname)); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | /* |
no test coverage detected