Skip to content

Commit

Permalink
Fix automatic reference on dereferences
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Feb 15, 2020
1 parent 0a3ee5f commit c3fc0ef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions nelua/analyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,9 @@ function visitors.UnaryOp(context, node)
-- for loops needs to know if an Id symbol could mutate
argattr.mutate = true
end
if opname == 'deref' then
attr.lvalue = true
end
if type then
attr.type = type
end
Expand Down
2 changes: 1 addition & 1 deletion nelua/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ function PointerType:is_convertible_from_attr(attr, explicit)
if not attr.lvalue then
return false, stringer.pformat(
'cannot automatic reference rvalue of type "%s" to pointer type "%s"',
attr.type, self)
attr.type:prettyname(), self)
end
attr.autoref = true
return self
Expand Down
2 changes: 2 additions & 0 deletions spec/05-cgenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,8 @@ it("record metametods", function()
assert(a[0] == 1 and a[1] == 2)
assert(#a == 100)
assert(a:__len() == 100)
local pa = &a
assert(#$pa == 100)
local R = @record {
x: integer
Expand Down

0 comments on commit c3fc0ef

Please sign in to comment.