| 268 | |
| 269 | |
| 270 | static void check_readonly (LexState *ls, expdesc *e) { |
| 271 | FuncState *fs = ls->fs; |
| 272 | TString *varname = NULL; /* to be set if variable is const */ |
| 273 | switch (e->k) { |
| 274 | case VCONST: { |
| 275 | varname = ls->dyd->actvar.arr[e->u.info].vd.name; |
| 276 | break; |
| 277 | } |
| 278 | case VLOCAL: { |
| 279 | Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx); |
| 280 | if (vardesc->vd.kind != VDKREG) /* not a regular variable? */ |
| 281 | varname = vardesc->vd.name; |
| 282 | break; |
| 283 | } |
| 284 | case VUPVAL: { |
| 285 | Upvaldesc *up = &fs->f->upvalues[e->u.info]; |
| 286 | if (up->kind != VDKREG) |
| 287 | varname = up->name; |
| 288 | break; |
| 289 | } |
| 290 | default: |
| 291 | return; /* other cases cannot be read-only */ |
| 292 | } |
| 293 | if (varname) { |
| 294 | const char *msg = luaO_pushfstring(ls->L, |
| 295 | "attempt to assign to const variable '%s'", getstr(varname)); |
| 296 | luaK_semerror(ls, msg); /* error */ |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | |
| 301 | /* |
no test coverage detected