v0.13.7
errors and warnings / parsing

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

× failswowlua
local settings: { frame: { scale: number }? } = {}settings.frame?.scale = 1
✓ compileswowlua
local settings: { frame: { scale: number }? } = {}if settings.frame then    settings.frame.scale = 1end

The 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

terminal
$ wowlua explain E0113
E0113 (error): Optional chain used as an assignment or compound-assignment target

source on GitHub ↗