extend-protocol doesn't work on deftype-fn backed types
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 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 分钟
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
babashka/sci 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 65/100
维护者通常 1 天内回复
-
JVM: implement a host (Clojure) protocol from sci — copy-var on a protocol var (ADR 0013, half 1)可能已有人在做 @yogthos 于 80 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 45/100
维护者通常 1 天内回复
-
Explore forkable SCI runtime worlds可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 5/5 一周以上 新手友好度 20/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 52/100
维护者通常 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
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
izhangzhihao/intellij-rainbow-brackets#2903 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 67/100