From 38daac9ffe02baf515be631b74391fb6b745cc5f Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Tue, 8 Oct 2024 19:26:06 -0300 Subject: [PATCH] Allow creating FunctionType from argnodes --- lualib/nelua/types.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lualib/nelua/types.lua b/lualib/nelua/types.lua index ff2caef2..c40422ab 100644 --- a/lualib/nelua/types.lua +++ b/lualib/nelua/types.lua @@ -1709,11 +1709,24 @@ function FunctionType:_init(argattrs, rettypes, node, refonly) Type._init(self, 'function', typedefs.ptrsize) if argattrs then -- set the arguments - -- make sure each arg attr is really an Attr class - for i=1,#argattrs do - local argattr = argattrs[i] - if not argattr._attr then - setmetatable(argattr, Attr) + if argattrs[1] and argattrs[1]._astnode then + -- convert argnodes to argttrs + local argnodes = argattrs + argattrs = {} + for i=1,#argnodes do + local argnode = argnodes[i] + argattrs[i] = setmetatable({ + name='arg'..i, + type=assert(argnode.attr.type, 'untyped astnode'), + }, Attr) + end + else + -- make sure each arg attr is really an Attr class + for i=1,#argattrs do + local argattr = argattrs[i] + if not argattr._attr then + setmetatable(argattr, Attr) + end end end end