Add more notes about what is and isn't valid in short-circuiting

This commit is contained in:
boyned//Kampfkarren 2021-11-13 13:51:09 -08:00
parent f6e87737e7
commit d2cb1d784b

View file

@ -89,6 +89,15 @@ When using safe navigation to call a function, the short circuiting will prevent
object?.doSomething(getValue())
```
The short-circuiting is limited within the expression.
```lua
dog?.owner.name -- This will return nil if `dog` is nil
(dog?.owner).name -- `(dog?.owner)` resolves to nil, of which `name` is then indexed. This will error at runtime if `dog` is nil.
dog?.legs + 3 -- `dog?.legs` is resolved on its own, meaning this will error at runtime if it is nil (`nil + 3`)
```
The operator must be used in the context of either a call or an index, and so:
```lua