From bf1236e58b929ebc3652c12fc65d7a12a6bb31c6 Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Mon, 21 Jun 2021 16:04:04 +0300 Subject: [PATCH] Added `assert` call alternative --- rfcs/syntax-nil-forgiving-operator.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rfcs/syntax-nil-forgiving-operator.md b/rfcs/syntax-nil-forgiving-operator.md index e5a5fe41..0cfdc72f 100644 --- a/rfcs/syntax-nil-forgiving-operator.md +++ b/rfcs/syntax-nil-forgiving-operator.md @@ -81,3 +81,10 @@ It might be useful to warn about unnecessary uses of this operator when the valu ### Bad practice The operator might be placed by users to ignore/silence correct warnings and lower the strength of type checking that Luau provides. + +## Alternatives + +Aside from type assertion operator `::` it should be possible to place `assert` function calls before the operation. +Type refinement/constraints should handle that statement and avoid warning in the following expressions. + +But `assert` call will introduce runtime overhead without adding extra safety to the case when the type is nil at run time, in both cases an error will be thrown.