From 0a6294ede62f573001be6c50c826213185f97810 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 2 Jan 2025 20:00:16 -0300 Subject: [PATCH] refactor: node_is_funcall --- tl.lua | 14 +++++++++----- tl.tl | 12 ++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tl.lua b/tl.lua index ad3ba928..e58f55b8 100644 --- a/tl.lua +++ b/tl.lua @@ -2343,6 +2343,10 @@ local function node_is_require_call(n) return nil end +local function node_is_funcall(node) + return node.kind == "op" and node.op.op == "@funcall" +end + @@ -2994,7 +2998,7 @@ do if r then return r end - if n.op and n.op.op == "@funcall" and + if node_is_funcall(n) and n.e1 and n.e1.tk == "pcall" and n.e2 and #n.e2 == 2 and n.e2[1].kind == "variable" and n.e2[1].tk == "require" and @@ -4143,7 +4147,7 @@ do return i end - if (exp.op and exp.op.op == "@funcall") or exp.failstore then + if node_is_funcall(exp) or exp.failstore then return i, exp end @@ -8159,7 +8163,7 @@ do - local struc = resolve_decl_into_nominal(self, nom, found) + local struc = resolve_decl_into_nominal(self, nom, found or nom.found) local td = a_type(ta, "typedecl", { def = struc }) @@ -9626,7 +9630,7 @@ a.types[i], b.types[i]), } if is_method then return "method" end - if node.kind == "op" and node.op.op == "@funcall" and e1 and e1.receiver then + if node_is_funcall(node) and e1 and e1.receiver then local receiver = e1.receiver if receiver.typename == "nominal" then local resolved = receiver.resolved @@ -11527,7 +11531,7 @@ self:expand_type(node, values, elements) }) local valtype = valtypes.tuple[i] local rvar, rval, err = self:check_assignment(varnode, vartype, valtype) if err == "missing" then - if #node.exps == 1 and node.exps[1].kind == "op" and node.exps[1].op.op == "@funcall" then + if #node.exps == 1 and node_is_funcall(node.exps[1]) then local msg = #valtuple.tuple == 1 and "only 1 value is returned by the function" or ("only " .. #valtuple.tuple .. " values are returned by the function") diff --git a/tl.tl b/tl.tl index d4e07eb8..f72568ea 100644 --- a/tl.tl +++ b/tl.tl @@ -2343,6 +2343,10 @@ local function node_is_require_call(n: Node): string return nil -- table.insert cares about arity end +local function node_is_funcall(node: Node): boolean + return node.kind == "op" and node.op.op == "@funcall" +end + local enum ParseLang "lua" "tl" @@ -2994,7 +2998,7 @@ local function node_is_require_call_or_pcall(n: Node): string if r then return r end - if n.op and n.op.op == "@funcall" + if node_is_funcall(n) and n.e1 and n.e1.tk == "pcall" and n.e2 and #n.e2 == 2 and n.e2[1].kind == "variable" and n.e2[1].tk == "require" @@ -4143,7 +4147,7 @@ do return i end - if (exp.op and exp.op.op == "@funcall") or exp.failstore then + if node_is_funcall(exp) or exp.failstore then return i, exp end @@ -9626,7 +9630,7 @@ do if is_method then return "method" end - if node.kind == "op" and node.op.op == "@funcall" and e1 and e1.receiver then + if node_is_funcall(node) and e1 and e1.receiver then local receiver = e1.receiver if receiver is NominalType then local resolved = receiver.resolved @@ -11527,7 +11531,7 @@ do local valtype = valtypes.tuple[i] local rvar, rval, err = self:check_assignment(varnode, vartype, valtype) if err == "missing" then - if #node.exps == 1 and node.exps[1].kind == "op" and node.exps[1].op.op == "@funcall" then + if #node.exps == 1 and node_is_funcall(node.exps[1]) then local msg = #valtuple.tuple == 1 and "only 1 value is returned by the function" or ("only " .. #valtuple.tuple .. " values are returned by the function")