Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Question about the intended semantics for inline `#:` type assertions on local variables

Aperta
#3,030 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
ruby
Ambito
documentation

Direzione di ricerca

Inizia esaminando la documentazione della sintassi inline in docs/ e i comportamenti segnalati di Steep e Sorbet per le asserzioni sulle variabili locali. Confronta gli esempi nell’issue e determina se il progetto debba specificare un’unica semantica o documentare le differenze tra i checker. Il lavoro è concluso quando è disponibile una decisione documentata o una modifica alla documentazione chiaramente circoscritta per gli autori e gli utenti degli strumenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Now that inline RBS comments are in ruby/rbs I'd like to clarify what the #: type assertion on a local variable is supposed to mean and to make sure that we aren't baking in a semantic difference between steep and sorbet.

For instance in the following code:

x = "hi" #: String
x = 5
  • Steep (verified on 2.0.0) treats #: as a type assertion on the expression (introduced in Steep 1.3 as "declaring the type of an expression inline, without introducing a new local variable with a @type var annotation"). The local remains flow-typed, so the later x = 5 re-infers x to Integer — no error at the reassignment.
  • Sorbet (verified on 0.6.13327 (RBS comments support) lowers x = v #: T to x = T.let(v, T). T.let declares the local's type for the whole method scope, so x = 5 is an error ("Incompatible assignment to variable declared via let").

This is extra confusing because in the case of

class Foo
  attr_accessor :bar #: String?
end

foo = Foo.new
Foo.bar = 5

results in an error in both Steep and Sorbet.

Questions

  1. Is the semantics of a #: assertion on a local variable intended to be an expression-level assertion (Steep's behavior), a scope-level declaration/pin (Sorbet's T.let behavior), or is it deliberately left to each checker?
  2. If it's left to checkers by design, can we consider documenting that (e.g. in docs/) so tool authors and users know portability is not guaranteed here?
  3. If a single intended meaning is desired, is there a preference — and would it be worth a note in the inline-syntax docs so Steep/Sorbet/other implementations (RubyMine, and third-party checkers) can converge?
Lingua principale
Ruby
Stelle
2.2k
Fork
256
Merge medio
7g 1h
PR unite (30g)
35

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/rbs

Tutte le issue di ruby/rbs

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.