crystal
crystal copied to clipboard
Positional parameter mismatch: warning inconsistency
This is an inconsistency with the warning that I noticed when compiling a real crystal program.
abstract class Foo
abstract def ===(value)
end
abstract class Bar < Foo
end
In src/object.cr:49:11
49 | def ===(other)
^----
Warning: positional parameter 'other' corresponds to parameter 'value' of the overridden method Foo#===(value), which has a different name and may affect named argument passing
A total of 1 warnings were found.
In the example, the warning goes away if either
valueis changed toother, as in theObjectclass (matches my expectation)Baris marked as concrete and#===(value)is added (doesn't match my expectation)
The warning message also seems to be inverted, suggesting that Object's definition is incorrect rather than Foo's.
This is present in master.
Reduced:
class 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
abstract class Bar < Foo
abstract def foo(y)
end
abstract class Baz < Bar
end
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
If one duplicates the definition of Baz then the same error shows up once per duplication.
There probably shouldn't be any warnings at all in these cases if the type being considered (Baz) is an abstract class or a module. Note that Foo#foo should never implement Bar#foo because Foo is an ancestor of Bar.