Comments (4)
As I explained on Slack, this is not unique to instance variables, this is sort of just how variable assignments work. As long as the assignment to a "pinned" variable (a variable with an explicitly declared type) is compatible with the type it was pinned to, Sorbet will use the more narrow type of the variable if it is ever assigned to a second time.
Input
# typed: true
extend T::Sig
sig { void }
def lookup_for_me
x = T.let(0, Integer)
x = T.unsafe('')
T.reveal_type(x)
end
Observed output
editor.rb:8: Revealed type: T.untyped https://srb.help/7014
8 | T.reveal_type(x)
^^^^^^^^^^^^^^^^
Got T.untyped originating from:
editor.rb:7:
7 | x = T.unsafe('')
^^^^^^^^^^^^
Errors: 1
The issue here is simply that T.untyped
is a subtype of all types, which is unsound but just the way that Sorbet works.
There are two separate issues you raise, which ought to be tracked separately:
-
Reporting a "usage of untyped" warning if the usage happens nested somewhere in the type, like
T::Array[T.untyped] <: T::Array[Integer]
, instead of at the top level, likeT.untyped <: T::Array[Integer]
. -
Adding a way to opt into this information in the
srb tc
output, because it is currently only available in editors.
from sorbet.
I don't understand this resolution. The assignment explicitly specifies type parameters for the T::Hash
, but those are thrown away. As a user, this makes no sense.
from sorbet.
If nothing else, this should be a clear sign that your documentation needs to be much clearer about how T.let
works.
from sorbet.
There is some difference between instance variables and non-instance-variables here. In this example, the T.let
is being respected when it should not be. As opposed to the original issue, which is where T.let
is incorrectly (appearing to a novice to be) ignored.
from sorbet.
Related Issues (20)
- Rename Symbol does not update Ruby symbol literal visibility modifiers
- Linked generic type pairs
- Remove git worktree script HOT 1
- Missing dependency on `bigdecimal`
- ENFORCE failure in Desguar when synthesizing locs from unsupported nodes
- Support find all references for `Opus::Command`
- Return type is not recognized as a subtype of the super method when using requires_ancestor HOT 2
- Allow using shape type in `T.proc` to act like keyword args
- autocomplete on method enum arguments should directly suggest enum values HOT 1
- T.proc arity checking assumes it's a lambda, not a proc HOT 1
- Error for duplicate enum values
- Default positional arguments before required positional arguments throws "not enough arguments" error in callers HOT 1
- Rename an undefined variable HOT 2
- `T.self_type` does not work for union types (e.g. `T::Boolean#tap` returns `TrueClass`)
- Bad `T.must` / `T.unsafe`autocorrect for method result inside `call` method inside an `Opus::Command` class
- Autocorrect to add argument missing from parent method
- Include more information in `Return value` TypeErrors HOT 1
- Unexpected return type mismatch for overridden method
- Try turning mimalloc back on for macOS release builds
- Sorbet generics error only occurs for specific ordering of includes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sorbet.