Skip to content

Commit

Permalink
only check against shadowing base types when declaring types
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Aug 11, 2024
1 parent 8edaa26 commit 2ec30ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 11 additions & 0 deletions spec/declaration/local_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,15 @@ describe("local", function()
kk = {}
]]))

it("using a base type name in a regular variable produces no warnings", util.check_warnings([[
local any = true
print(any)
local record integer
end
]], {
{ tag = "redeclaration", msg = "variable shadows previous declaration of 'integer'" },
{ tag = "unused", msg = "unused type integer" },
}))
end)
6 changes: 3 additions & 3 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7459,9 +7459,9 @@ do
end


function TypeChecker:check_if_redeclaration(new_name, node)
function TypeChecker:check_if_redeclaration(new_name, node, t)
local old = self:find_var(new_name, "check_only")
if old or simple_types[new_name] then
if old or (t.typename == "typedecl" and simple_types[new_name]) then
local var_name = node.tk
local var_kind = "variable"
if node.kind == "local_function" or node.kind == "record_function" then
Expand Down Expand Up @@ -7546,7 +7546,7 @@ do
name ~= "..." and
name:sub(1, 1) ~= "@" then

self:check_if_redeclaration(name, node)
self:check_if_redeclaration(name, node, t)
end

if var and not var.used then
Expand Down
6 changes: 3 additions & 3 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -7459,9 +7459,9 @@ do
end


function TypeChecker:check_if_redeclaration(new_name: string, node: Node)
function TypeChecker:check_if_redeclaration(new_name: string, node: Node, t: Type)
local old <const> = self:find_var(new_name, "check_only")
if old or simple_types[new_name as TypeName] then
if old or (t is TypeDeclType and simple_types[new_name as TypeName]) then
local var_name = node.tk
local var_kind = "variable"
if node.kind == "local_function" or node.kind == "record_function" then
Expand Down Expand Up @@ -7546,7 +7546,7 @@ do
and name ~= "..."
and name:sub(1, 1) ~= "@"
then
self:check_if_redeclaration(name, node)
self:check_if_redeclaration(name, node, t)
end

if var and not var.used then
Expand Down

0 comments on commit 2ec30ea

Please sign in to comment.