From 4e9a508a11c16db9aeff44b27e88713ab413bff7 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 4 Mar 2024 11:13:18 +0800 Subject: add default return declaration for function literal. --- spec/inputs/funcs.yue | 35 +++++++++++++++++++++++++ spec/outputs/funcs.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) (limited to 'spec') diff --git a/spec/inputs/funcs.yue b/spec/inputs/funcs.yue index 0e45ff1..e647edc 100644 --- a/spec/inputs/funcs.yue +++ b/spec/inputs/funcs.yue @@ -158,4 +158,39 @@ args = (f,g,m return 1 if n == 0 n * @(n-1) +do + items.every (item) -> + if item.field + value = item.field.get "abc" + if value + switch value\get! + when 123 + return false + when 456 + handle item + true + + items.every (item): true -> + if item.field + value = item.field.get "abc" + if value + switch value\get! + when 123 + return false + when 456 + -- prevent implicit return for next line + handle item + + HttpServer\post "/login", (req): success: false -> + switch req when {:name, :pwd} + if name ~= "" + if user := DB\queryUser name, pwd + if user.status == "available" + return success: true + + check = (num) -> return num + -- func without implicit return + func = (): -> check 123 + print func! -- get nil + nil diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua index 03281e4..c07989e 100644 --- a/spec/outputs/funcs.lua +++ b/spec/outputs/funcs.lua @@ -219,4 +219,74 @@ self = function(n) end return n * self(n - 1) end +do + items.every(function(item) + if item.field then + local value = item.field.get("abc") + if value then + do + local _exp_0 = value:get() + if 123 == _exp_0 then + return false + elseif 456 == _exp_0 then + handle(item) + end + end + end + end + return true + end) + items.every(function(item) + if item.field then + local value = item.field.get("abc") + if value then + do + local _exp_0 = value:get() + if 123 == _exp_0 then + return false + elseif 456 == _exp_0 then + handle(item) + end + end + end + end + return true + end) + HttpServer:post("/login", function(req) + do + local _type_0 = type(req) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + local name = req.name + local pwd = req.pwd + if name ~= nil and pwd ~= nil then + if name ~= "" then + do + local user = DB:queryUser(name, pwd) + if user then + if user.status == "available" then + return { + success = true + } + end + end + end + end + end + end + end + return { + success = false + } + end) + local check + check = function(num) + return num + end + local func + func = function() + check(123) + end + print(func()) +end return nil -- cgit v1.2.3-55-g6feb