Skip to content

Commit

Permalink
Allow creating FunctionType from argnodes
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Oct 8, 2024
1 parent b3328e0 commit 38daac9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lualib/nelua/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38daac9

Please sign in to comment.