Handle type declarations in scopes

closes #66
This commit is contained in:
Vitalii Elenhaupt 2018-06-23 08:47:18 +03:00
parent fafc5f4bdc
commit 04c7300964
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
3 changed files with 32 additions and 0 deletions

View file

@ -124,6 +124,20 @@ module Ameba::Rule::Lint
subject.catch(source).should be_valid
end
it "doesn't report if it shadows record type declaration" do
source = Source.new %(
class FooBar
record Foo, index : String
def bar
3.times do |index|
end
end
end
)
subject.catch(source).should be_valid
end
it "reports rule, location and message" do
source = Source.new %(
foo = 1

View file

@ -408,6 +408,17 @@ module Ameba::Rule::Lint
)
subject.catch(s).should be_valid
end
it "doesn't report if assignment initialized and captured by block" do
s = Source.new %(
a : String? = nil
1.times do
a = "Fotis"
end
)
subject.catch(s).should be_valid
end
end
context "branching" do

View file

@ -110,6 +110,13 @@ module Ameba::AST
on_scope_end(node) if @current_scope.eql?(node)
end
# :nodoc:
def visit(node : Crystal::TypeDeclaration)
if !@current_scope.type_definition? && (var = node.var).is_a?(Crystal::Var)
@current_scope.add_variable var
end
end
# :nodoc:
def visit(node : Crystal::Arg)
@current_scope.add_argument node