From d2cb1d784b4127848ae5358d06db14ad671c7fee Mon Sep 17 00:00:00 2001 From: boyned//Kampfkarren Date: Sat, 13 Nov 2021 13:51:09 -0800 Subject: [PATCH] Add more notes about what is and isn't valid in short-circuiting --- rfcs/syntax-safe-navigation-operator.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rfcs/syntax-safe-navigation-operator.md b/rfcs/syntax-safe-navigation-operator.md index 5f520a82..634b61c0 100644 --- a/rfcs/syntax-safe-navigation-operator.md +++ b/rfcs/syntax-safe-navigation-operator.md @@ -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