extend-protocol doesn't work on deftype-fn backed types
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
sci.impl.types/type-impl から始め、issue で説明されている SciTypeInstance と ICustomType のパスをたどります。提供されている extend-protocol の再現手順を実行し、その後、deftype-fn に基づくカスタムインスタンスがそれぞれの特定の型に一致することを確認します。同時に、インラインのプロトコル実装が引き続き機能することも確認します。
索引モデルが issue の本文から書いたものです。
説明
extend-protocol doesn't work on deftype-fn backed types
Problem
When a deftype is backed by a custom type via :deftype-fn (e.g. SciMap in babashka), extend-protocol on that type doesn't work.
The root cause is that type-impl returns :sci.impl.protocols/reified for ICustomType instances (rather than the specific type symbol like user.MyCache), so the defmethod registered by extend-protocol for the specific type never matches.
Reproduction
(defprotocol Extra (extra [this]))
(extend-protocol Extra
MyCustomType
(extra [this] :it-works))
(extra (->MyCustomType ...))
;; => No implementation of method: :extra of protocol: #'user/Extra found for: :sci.impl.protocols/reified
Analysis
In sci.impl.types/type-impl:
SciTypeInstanceis checked first → returns specific type symbol (e.g.user.Foo) — extend-protocol worksICustomTypeis checked second → returns:sci.impl.protocols/reified— extend-protocol doesn't match
For the standard SciType path, inline protocol impls are registered as defmethods keyed on the specific type symbol. extend-protocol also registers defmethods for that symbol, so both work.
For custom types (via :deftype-fn), inline protocol impls go through the :reified defmethod which delegates to ICustomType.getMethods(). But extend-protocol registers a defmethod for the specific type symbol, which never fires because type-impl returns :reified.
Possible fix
Make custom type instances also implement SciTypeInstance (or otherwise return a specific type symbol from type-impl), then register a per-type defmethod that delegates to getMethods(). This would let both inline impls and extend-protocol coexist.
This would also open the door to unifying the standard SciType path and the custom type path, since both would use methods-map + per-type defmethod delegation.
- 主要言語
- Clojure
- スター
- 1.4k
- フォーク
- 109
- 平均マージ
- 1分
- マージ済み PR(30日)
- 26
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
babashka/sci のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
babashka/sci#1097 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
JVM: implement a host (Clojure) protocol from sci — copy-var on a protocol var (ADR 0013, half 1)対応中かも @yogthos が 80 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
Explore forkable SCI runtime worlds再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
babashka/sci#1040 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
babashka/sci#1002 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
nextjournal/clerk#830 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
IOP tokens release blocker team qa team qa autotests WG adoption
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
penpot/penpot#13540 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
izhangzhihao/intellij-rainbow-brackets#2903 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100