Skip to content

Commit

Permalink
Do not check abstract def parameter names on abstract types and modul…
Browse files Browse the repository at this point in the history
…es (#12434)
  • Loading branch information
HertzDevil authored and beta-ziliani committed Sep 7, 2022
1 parent 3de0d78 commit 9f04719
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions spec/compiler/semantic/warnings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -728,5 +728,37 @@ describe "Semantic: warnings" do
CR
end
end

it "doesn't warn if current type is abstract (#12266)" do
warnings_result(<<-CR).should be_empty
class Foo
def foo(x); end
end
abstract class Bar < Foo
abstract def foo(y)
end
abstract class Baz < Bar
end
CR
end

it "doesn't warn if current type is a module (#12266)" do
warnings_result(<<-CR).should be_empty
module Foo
def foo(x); end # Warning: positional parameter 'x' corresponds to parameter 'y' of the overridden method Bar#foo(y), which has a different name and may affect named argument passing
end
module Bar
include Foo
abstract def foo(y)
end
module Baz
include Bar
end
CR
end
end
end
6 changes: 3 additions & 3 deletions src/compiler/crystal/semantic/abstract_def_checker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class Crystal::AbstractDefChecker
implemented = true
end

unless found_param_match
check_positional_param_names(target_type, ancestor_type, a_def, base, method)
unless found_param_match || target_type.abstract? || target_type.module?
check_positional_param_names(a_def, base, method)
found_param_match = true if same_parameters?(a_def, method)
end
end
Expand Down Expand Up @@ -368,7 +368,7 @@ class Crystal::AbstractDefChecker
end
end

def check_positional_param_names(target_type : Type, impl_type : Type, impl_method : Def, base_type : Type, base_method : Def)
def check_positional_param_names(impl_method : Def, base_type : Type, base_method : Def)
impl_param_count = impl_method.splat_index || impl_method.args.size
base_param_count = base_method.splat_index || base_method.args.size
{impl_param_count, base_param_count}.min.times do |i|
Expand Down

0 comments on commit 9f04719

Please sign in to comment.