[英]Sorbet doesn't report a missing method implementation (compared to an RBI signature), am I doing something wrong here?
I have a file my_class.rb
:我有一个文件my_class.rb
:
# typed: true
class MyClass
attr_accessor :a, :b
def initialize(a: 1, b: 2)
@a = a
@b = b
end
def do_stuff
puts "#{self.class}: #@a #@b"
a * b + a - b
end
end
After installing and initializing Sorbet , I decided to write an RBI signature for this file in sorbet/rbi/my_class.rbi
: 安装并初始化 Sorbet 后,我决定在sorbet/rbi/my_class.rbi
为此文件编写 RBI 签名:
# typed: strict
class MyClass
sig { params(a: Numeric, b: Numeric).void }
def initialize(a:, b:); end
sig { returns(Numeric) }
def a; end
sig { returns(Numeric) }
def b; end
sig { returns(Numeric) }
def do_stuff; end
sig { params(x: Numeric).void }
def adjust(x); end;
end
I deliberately added a signature for an adjust
method to see if Sorbet would report on it.我特意为adjust
方法添加了一个签名,看看 Sorbet 是否会报告它。 But Sorbet doesn't report any errors.但 Sorbet 不会报告任何错误。
Am I configuring Sorbet levels wrong here, or doing something else wrong?我在这里配置的 Sorbet 级别是错误的,还是做错了什么?
Thank you.谢谢你。
I'm new to Sorbet, but I think this is because the RBI signatures don't act as an 'interface' in the traditional sense, so may describe methods that don't exist in the implementation.我是 Sorbet 的新手,但我认为这是因为 RBI 签名不充当传统意义上的“接口”,因此可能描述了实现中不存在的方法。
https://sorbet.org/docs/abstract discusses interfaces and marking a module with interface!
https://sorbet.org/docs/abstract讨论接口并用interface!
标记模块interface!
, I think that may give what you're looking for. ,我认为这可能会提供您正在寻找的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.