Skip to content

Commit

Permalink
Fix issue #243
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Nov 19, 2023
1 parent 19917ed commit e82695a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lualib/nelua/analyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ function visitors.Annotation(context, node, opts)
context.cmainimports = context.cmainimports or {}
table.insert(context.cmainimports, (codename:gsub('nelua_', '')))
end
context.cimports = context.cimports or {}
context.cimports[codename] = true
elseif name == 'nickname' then
assert(objattr._type and objattr.is_nameable)
local type, nickname = objattr, params
Expand Down
3 changes: 2 additions & 1 deletion lualib/nelua/ccontext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function CContext:declname(attr)
assert(attr._attr and attr.codename)
if not attr.nodecl and not attr.cimport then
declname = cdefs.quotename(declname)
if attr.shadows and not attr.staticstorage then
local cshadows = self.cimports and self.cimports[declname]
if (attr.shadows or cshadows) and not attr.staticstorage then
declname = self:genuniquename(declname)
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/cgenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,12 @@ it("variable shadowing", function()
local function exit(code: cint) <cimport> end
local function exit(code: cint) <cimport> end
exit(0)
do -- issue #243
local function time(timer: *ctime_t): ctime_t <cimport,cinclude'<time.h>',nodecl> end
local time = time(nilptr)
assert(time > 0)
end
]])
end)

Expand Down

0 comments on commit e82695a

Please sign in to comment.