![](/img/trans.png)
[英]Why does Sorbet think that a method I provided an explicit signature for in an RBI file doesn't exist?
[英]Sorbet doesn't report a missing method implementation (compared to an RBI signature), am I doing something wrong here?
我有一個文件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
安裝並初始化 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
我特意為adjust
方法添加了一個簽名,看看 Sorbet 是否會報告它。 但 Sorbet 不會報告任何錯誤。
我在這里配置的 Sorbet 級別是錯誤的,還是做錯了什么?
謝謝你。
我是 Sorbet 的新手,但我認為這是因為 RBI 簽名不充當傳統意義上的“接口”,因此可能描述了實現中不存在的方法。
https://sorbet.org/docs/abstract討論接口並用interface!
標記模塊interface!
,我認為這可能會提供您正在尋找的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.