Add type constraints to classgenerics in methods
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
実装ファイルやテストは指定されていません。まず、issue の例に照らして、RBS における既存のメソッドのジェネリック制約の扱いを確認してください。完了の条件は、合意された構文と、メソッドシグネチャ内のクラスジェネリックに対する制約のサポートがあり、Array と Enumerable のケースがカバーされていることです。
索引モデルが issue の本文から書いたものです。
説明
RBS currently only lets you add type constraints to generic variables when they're declared. (For class/modules, it looks like class Foo[P < _ToS] and for methods it looks like def print: [T < _ToS] (T) -> T).
I propose expanding the method form of this to support arbitrary constraints of class generics:
class CardboardBox[Contents]
def add: (Contents) -> void
def submerge!: {Contents < _Waterproof} () -> void
end
There's a lot of motivating examples of this in the stdlib. Here's a select few:
class Array[E]
# `Array#join` requires the `E` to respond to `to_s`
def join: {E < _ToS} (?string separator) -> String
# `Array#sum` without a default argument requires `E`
# to coerce with integers
def sum: [R < _Add] {E < _Coerce[Integer, R]} () -> R
| [I < _Add[E, O], O < _Add] (I default) -> O
end
module Enumerable[E] : _Each[E]
# `Enumerable#include?` goes `element == object`,
# which requires that `E` implements `==`, not `T`.
def include?: [T] {E < _Equals[T]} (T object) -> bool
end
Few things to note:
- I'm not wed to the syntax—in fact, I'd probably prefer it if it were a part of the
[]expression (egdef include?: [T, E < _Equals[T]]). But that might be difficult to implement, and the braces are currently unused before arguments - This proposal only talks class generics, as that's a somewhat pressing need. However, it might be nice (and if it's easy to do), extend this syntax to support any form of constraints
- 主要言語
- Ruby
- スター
- 2.2k
- フォーク
- 263
- 平均マージ
- 1日 20時間
- マージ済み PR(30日)
- 64
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/rbs のほかの issue
-
InlineParser: `@rbs @ivar` annotation is reported as unused unless it is the first thing in the class body対応中かも @ksss が 50 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug f:request-creation professional
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
mysociety/alaveteli#9733 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs verification
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 13 日以内に返信
-
🐛 bug 👩💻 équipe CE 🧑🏭 entreprises
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
betagouv/conseillers-entreprises#4808 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100