Giter VIP home page Giter VIP logo

Comments (4)

jez avatar jez commented on June 3, 2024

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

→ View on sorbet.run

# 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:

  1. 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, like T.untyped <: T::Array[Integer].

    #7706

  2. Adding a way to opt into this information in the srb tc output, because it is currently only available in editors.

    #7707

from sorbet.

amanda-mitchell avatar amanda-mitchell commented on June 3, 2024

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.

amanda-mitchell avatar amanda-mitchell commented on June 3, 2024

If nothing else, this should be a clear sign that your documentation needs to be much clearer about how T.let works.

from sorbet.

skatenerd avatar skatenerd commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.