我正在尝试让这个 Sorbet 代码正常工作(在Sorbet 操场上):
# typed: true
extend T::Sig
extend T::Generic
class Foo
extend T::Sig
extend T::Generic
TypeParam = type_member
end
class FooA < Foo
TypeParam = type_member(fixed: Integer)
end
sig {type_parameters(:MyParam)
.params(foo: Foo[T.type_parameter(:MyParam)]).void}
def blah(foo)
end
my_foo = FooA.new
blah(T.cast(my_foo, Foo[Integer]))
但是,我收到类型错误:
editor.rb:23: Expected Foo[T.type_parameter(:MyParam)] but found Foo[Integer] for argument foo https://srb.help/7002
23 |blah(T.cast(my_foo, Foo[Integer]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expected Foo[T.type_parameter(:MyParam)] for argument foo of method Object#blah:
editor.rb:18:
18 | .params(foo: Foo[T.type_parameter(:MyParam)]).void}
^^^
Got Foo[Integer] originating from:
editor.rb:23:
23 |blah(T.cast(my_foo, Foo[Integer]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 1
我不确定如何将blah
方法单态化,以便它可以采用 type 的参数Foo[Integer]
。Sorbet 目前是否支持此用例?