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
editor.rb:10: Use of undeclared variable @y https://srb.help/6002
10 | @y = 0
^^
Errors: 1
Expected behavior
We should infer the annotation for @x because it is a literal type. We should use the same type defaulting rules that we use for constants (as depicted) to also handle instance variables.
This should probably only work for instance variable assignments that happen inside initialize or the top level of a class.
Ideally we would consolidate the logic that handles constants to handle instance variables.
To this end, we can probably move the logic to be done in a rewriter pass.
The rewriter pass would insert a T.let inside assignments to either constants or instance variables when the RHS is a literal.
(As opposed to now, where it is done in the internals of namer/resolver.)
The text was updated successfully, but these errors were encountered:
With the advent of #6599 (which infers that X = A.new means X = T.let(A.new, A), would there be any desire to apply the same logic to ivars?
E.g.
#typed: strictclassCextendT::Sigsig{void}definitialize@foo=Foo.new# inferred as `T.let(Foo.new, Foo)`end# Stretch goal: A further refinement of https://github.com/sorbet/sorbet/issues/995defmemoed_bar@bar ||= Bar.new# inferred as `T.let(Bar.new, T.nilable(Bar))`endend
Input
→ View on sorbet.run
Observed output
Expected behavior
We should infer the annotation for
@x
because it is a literal type. We should use the same type defaulting rules that we use for constants (as depicted) to also handle instance variables.initialize
or the top level of a class.To this end, we can probably move the logic to be done in a rewriter pass.
The rewriter pass would insert a
T.let
inside assignments to either constants or instance variables when the RHS is a literal.(As opposed to now, where it is done in the internals of namer/resolver.)
The text was updated successfully, but these errors were encountered: