From 1da729b7fdc4c9b7cf8791a610bb38daa797a1ed Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Tue, 6 Jul 2021 21:34:28 +0300 Subject: [PATCH] Added a few examples --- .../_posts/2021-06-30-luau-recap-june-2021.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/_posts/2021-06-30-luau-recap-june-2021.md b/docs/_posts/2021-06-30-luau-recap-june-2021.md index 0c5c4813..67aa8e96 100644 --- a/docs/_posts/2021-06-30-luau-recap-june-2021.md +++ b/docs/_posts/2021-06-30-luau-recap-june-2021.md @@ -23,6 +23,28 @@ This framework is extensible and we have plans for future improvements with `a = It is now also possible to get better type information inside `else` blocks of an `if` statement. +A few examples to see the constraint resolver in action: +```lua +function say_hello(name: string?) + -- extra parentheses were enough to trip the old typechecker + if (name) then + print("Hello " .. name .. "!") + else + print("Hello mysterious stranger!") + end +end +``` +```lua +function say_hello(name: string?, surname: string?) + -- but now we handle that and more complex expressions as well + if not (name and surname) then + print("Hello mysterious stranger!") + else + print("Hello " .. name .. " " .. surname .. "!") + end +end +``` + ## Typechecking improvements We have improved the way we handled module `require` calls. Previously, we had a simple pattern match on the `local m = require(...)` statement, but now we have replaced it with a general handling of the function call in any context.