Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#3,030 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
ドキュメント
明瞭さ
説明が足りない
活発さ
静か
技術スタック
ruby
領域
documentation

調査の方向性

まず docs/ のインライン構文に関するドキュメントと、ローカル変数のアサーションに関して報告されている Steep および Sorbet の挙動を確認します。Issue の例を比較し、プロジェクトとして1つのセマンティクスを指定すべきか、チェッカー間の違いをドキュメント化すべきかを判断します。完了とは、文書化された決定、またはツールの作成者とユーザーを対象とした、範囲が明確なドキュメント変更があることを意味します。

索引モデルが issue の本文から書いたものです。

説明

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?
主要言語
Ruby
スター
2.2k
フォーク
258
平均マージ
1日 8時間
マージ済み PR(30日)
44

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/rbs のほかの issue

ruby/rbs の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。