Skip to content

Commit 38daac9

Browse files
committed
Allow creating FunctionType from argnodes
1 parent b3328e0 commit 38daac9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lualib/nelua/types.lua

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,11 +1709,24 @@ function FunctionType:_init(argattrs, rettypes, node, refonly)
17091709
Type._init(self, 'function', typedefs.ptrsize)
17101710

17111711
if argattrs then -- set the arguments
1712-
-- make sure each arg attr is really an Attr class
1713-
for i=1,#argattrs do
1714-
local argattr = argattrs[i]
1715-
if not argattr._attr then
1716-
setmetatable(argattr, Attr)
1712+
if argattrs[1] and argattrs[1]._astnode then
1713+
-- convert argnodes to argttrs
1714+
local argnodes = argattrs
1715+
argattrs = {}
1716+
for i=1,#argnodes do
1717+
local argnode = argnodes[i]
1718+
argattrs[i] = setmetatable({
1719+
name='arg'..i,
1720+
type=assert(argnode.attr.type, 'untyped astnode'),
1721+
}, Attr)
1722+
end
1723+
else
1724+
-- make sure each arg attr is really an Attr class
1725+
for i=1,#argattrs do
1726+
local argattr = argattrs[i]
1727+
if not argattr._attr then
1728+
setmetatable(argattr, Attr)
1729+
end
17171730
end
17181731
end
17191732
end

0 commit comments

Comments
 (0)