You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# typed: trueextendT::SigclassCoBoxextendT::SigextendT::GenericElem=type_member(:out)sig{params(value: Elem).void}definitialize(value)@value=valueendendsig{type_parameters(:V).params(value: T.type_parameter(:V)).returns(CoBox[T.type_parameter(:V)])}defco_box(value)CoBox.new(value)# errors, but should notend# covariant usageT.let(co_box(Bar.new),CoBox[Bar])T.let(co_box(Baz.new),CoBox[Bar])# invariant example follows, just for comparisonclassBoxextendT::SigextendT::GenericElem=type_membersig{params(value: Elem).void}definitialize(value)@value=valueendendsig{type_parameters(:V).params(value: T.type_parameter(:V)).returns(Box[T.type_parameter(:V)])}defbox(value)Box.new(value)endclassBar;endclassBaz < Bar;endT.let(box(Bar.new),Box[Bar])
Observed output
editor.rb:19: Expected CoBox[T.type_parameter(:V) (of Object#co_box)] but found CoBox[<top>] for method result type https://srb.help/7005
19 | CoBox.new(value) # errors, but should not
^^^^^^^^^^^^^^^^
Expected CoBox[T.type_parameter(:V) (of Object#co_box)] for result type of method co_box:
editor.rb:18:
18 |def co_box(value)
^^^^^^^^^^^^^^^^^
Got CoBox[<top>] originating from:
editor.rb:19:
19 | CoBox.new(value) # errors, but should not
^^^^^^^^^^^^^^^^
Errors: 1
Expected behavior
Perhaps I've misunderstood something, but I think methods like co_box shouldn't error.
My current workaround is to have them return CoBox[T.untyped]
The text was updated successfully, but these errors were encountered:
This annotation is secretly required. When it is not provided, Sorbet assumes:
T.untyped if the generic is invariant
<top> if the generic is covariant
T.noreturn if the generic is contravariant
The fix for this will be one of #3768 or #4450 (either: require a type argument for all generics, or infer a type argument from the arguments, and require the ones that can't be inferred).
(I've tried both in the past and neither is a simple fix so unfortunately they'll remain open for the time being.)
Input
→ View on sorbet.run
Observed output
Expected behavior
Perhaps I've misunderstood something, but I think methods like
co_box
shouldn't error.My current workaround is to have them return
CoBox[T.untyped]
The text was updated successfully, but these errors were encountered: