Skip to content

把 'Optional 解码目标迁到 Option - #8

Merged
tiye merged 1 commit into
mainfrom
migrate/optional-to-option
Oct 29, 2026
Merged

tiye merged 1 commit into
mainfrom
migrate/optional-to-option

Conversation

@tiye

@tiye tiye commented Oct 29, 2026

Copy link
Copy Markdown
Member

Requested by Jon · project thread

改动

calcit 0.32 计划删除旧的 Optional<T>(calcit-lang/calcit#2233,calcit 0.33.0 里程碑)。本仓库有 23 处 'Optional 解码目标,写法都一样:先用 .unwrap-or (get m :k) nil 把 Option 退回 nil,再 decode-map-as … (:: 'Optional T),很多地方还要接一次 nil->option 变回 Option。

  • 可能为 nil 的 store 字段改为 .and-then (get m :k) present-option 读取,并直接按 (:: 'Option T) 解码一次,结果已经是 Option。
  • 渲染层把 selected-channel、selected-history、selected-storage、workspace-entry 和 storage-error 保持为 Option 并用 match 处理。新增 selected-channel? 和 storage-kind?,替代原来的 nil 判断。
  • ack 消息直接传 Option :none 或 Option :some message。
  • present-option 放在 app.comp.container 作为本地 helper,并加进 app.main 和 app.updater 的 :refer。这样做是因为 strict 检查不允许把 nil->option(0.30.1 里参数仍是 Optional 类型)当作 .and-then 的回调。

改完后 calcit.cirru 中不再有 'Optional 和 nil->option。

本地验证

按 workflow 里的步骤本地跑过:caps --strict --ci、caps verify --toolchain、calcit edit format 后无 diff、--check-only 和 --check-only --all-defs、fix --workflow strict --verify(status passed,diagnostics 为空)、analyze weak-types --only deprecated-call(calls 为 0)。


Generated by Claude Code

calcit 0.32 schedules the legacy `Optional<T>` for removal
(calcit#2233). The 23 `'Optional` decode targets here followed one
shape: `.unwrap-or (get m :k) nil` erased an Option back to nil, then
`decode-map-as … (:: 'Optional T)` and often `nil->option` turned it
back into an Option.

Store slots that may hold nil are now read with
`.and-then (get m :k) present-option` and decoded once as
`(:: 'Option T)`, so the result is already an Option. The renderer
view keeps `selected-channel`, `selected-history`, `selected-storage`,
`workspace-entry` and `storage-error` as Options and matches on them;
`selected-channel?` and `storage-kind?` replace the nil checks. Ack
messages pass `Option :none` / `Option :some message` directly.

`present-option` is a local helper because strict checking rejects
passing `nil->option` (still `Optional`-typed in 0.30.1) as a callback.
No `'Optional` or `nil->option` remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019bPdumddHcfQCCCVRuVyXS
@tiye tiye self-assigned this Oct 29, 2026
@tiye
tiye merged commit 41a857c into main Oct 29, 2026
1 check passed
@tiye
tiye deleted the migrate/optional-to-option branch October 29, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants