errors and warnings / parsing / E0113
E0113 error
Optional chain used as an assignment or compound-assignment target
- area
- parsing (x01xx)
- fails the build
- yes
An optional chain (?., ?.[, ?:) is the target of an assignment or a
compound assignment, as in t.inner?.n = 1. If the chain stopped at nil
there would be nothing to assign to. Test the value first and assign
through a plain access.
Example
local settings: { frame: { scale: number }? } = {}settings.frame?.scale = 1local settings: { frame: { scale: number }? } = {}if settings.frame then settings.frame.scale = 1endThe compiler reports it like this:
error[E0113]: an optional chain cannot be assigned to ┌─ src/main.wowlua:2:1 │ 2 │ settings.frame?.scale = 1 │ ^^^^^^^^^^^^^^^^^^^^^ here
Offline
$ wowlua explain E0113 E0113 (error): Optional chain used as an assignment or compound-assignment target