Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive in warning about param names in implementations #12208

Closed
beta-ziliani opened this issue Jul 5, 2022 · 3 comments
Closed

False positive in warning about param names in implementations #12208

beta-ziliani opened this issue Jul 5, 2022 · 3 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@beta-ziliani
Copy link
Member

Take the following code:

abstract class Foo
  abstract def foo(x : Int32)
end

module FooM
  def foo(x : Int32); end
end

class Bar < Foo
  include FooM
  def foo(y : Int32 | String); end
end

In this code, FooM correctly matches Foo's abstract def, however with #11915 + #12167 it warns:

warning in line 11
Warning: positional parameter 'y' corresponds to parameter 'x' of the overridden method Foo#foo(x : Int32), ...
@beta-ziliani beta-ziliani added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Jul 5, 2022
@beta-ziliani
Copy link
Member Author

Similar:

module Foo
  abstract def foo(x : Int32)
end

class FooM
  def foo(x : Int32); end
end

class Bar < FooM
  include Foo

  def foo(y : Int32 | String); end
end

@HertzDevil
Copy link
Contributor

#foo will be looked up in Bar before FooM even though FooM#foo is stricter than Bar#foo:

abstract class Foo
  abstract def foo(x : Int32)
end

module FooM
  def foo(x : Int32); 1; end
end

class Bar < Foo
  include FooM
  def foo(y : Int32 | String); 2; end
end

Bar.new.foo(0)  # => 2
Bar.new.foo("") # => 2

So I think this error is appropriate, because Foo#foo is ultimately implemented in Bar, not FooM.

@beta-ziliani
Copy link
Member Author

Ah I see, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

No branches or pull requests

2 participants