microts: generated Rust raises non_shorthand_field_patterns for a union variant with fields
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust, typescript
调研方向
从 pattern 开始,位于 microts/compiler/rust-printer.ts:68,它目前总是写出 name: pattern;检查它在 microts/compiler/aot-model-codegen.ts 中的调用方——第 902 行附近的 encode match 和第 496 行附近的 union 成员读取——两者都会把每个字段绑定到同名变量。当绑定名等于字段名时输出 shorthand,包括 .. rest 情况,然后在 harness 中重新运行复现的 bun tools/pocket.ts compile --aot --out gen 以及 cargo check(最好带 -D warnings),以确认 gen/app_model.rs 无警告。
由索引模型根据 Issue 内容生成。
描述
Version
PocketJS main (2c9fcf30). macOS 27.2 arm64, Bun 1.4.2, Rust 1.98.1.
Repro
pocket.host.json, pocket.host.config.ts (aot: true, model: "compiled") and main.tsx as in #720; the cargo harness as in #725.
// app.ts
import { createSignal } from "solid-js";
import type { i32 } from "@pocketjs/framework/solid/std";
export type Flag = { kind: "off" } | { kind: "on"; value: i32 };
export const [flag, setFlag] = createSignal<Flag>({ kind: "off" });
export const [count, setCount] = createSignal<i32>(0);
export function toggle(): void {
const current = flag();
if (current.kind === "on") {
setCount(current.value);
setFlag({ kind: "off" });
} else {
setFlag({ kind: "on", value: count() + 1 });
}
}
// app.tsx
import { Text, View } from "@pocketjs/framework/solid/components";
import { count, toggle } from "./app";
export default function App() {
return (
<View class="w-full h-full p-4 bg-slate-100" focusable onPress={() => toggle()}>
<Text class="text-lg text-slate-900">{count()}</Text>
</View>
);
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
(cd harness && cargo check)
Actual
warning: the `value:` in this pattern is redundant
--> src/../../gen/app_model.rs:21:24
|
21 | ... Flag::On { value: value } => Value::Object(alloc::vec!((String::from("kind"), Value::String(String::from("on"))), (String::fro...
| ^^^^^^^^^^^^ help: use shorthand field pattern: `value`
|
= note: `#[warn(non_shorthand_field_patterns)]` on by default
warning: the `value:` in this pattern is redundant
--> src/../../gen/app_model.rs:110:32
|
110 | Flag::On { value: value, .. } => value,
| ^^^^^^^^^^^^ help: use shorthand field pattern: `value`
A crate built with -D warnings fails on a model that has a union variant with fields.
Expected
Generated code compiles without warnings: Flag::On { value } and Flag::On { value, .. }. #736 removed the warnings of the unused lint group; this lint is outside that group.
Cause
pattern in microts/compiler/rust-printer.ts:68 writes name: pattern for every field of a variant pattern that carries a pattern. The codec encoder (microts/compiler/aot-model-codegen.ts, the encode match near line 902) and the member read of a union (near line 496) bind each field to a variable of the same name.
Workaround
#![allow(non_shorthand_field_patterns)] in the crate that includes include.rs.
- 主要语言
- TypeScript
- 星标
- 1.6k
- 派生
- 88
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pocket-stack/pocketjs 的其他 Issue
-
microts: a model local that every branch assigns raises unused_assignments in the generated Rust未关闭bug
难度 2/5 1-3 小时 新手友好度 80/100
pocket-stack/pocketjs#756 ·
-
bug
难度 1/5 1 小时以内 新手友好度 88/100
pocket-stack/pocketjs#745 ·
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
pocket-stack/pocketjs#743 ·
-
bug
难度 5/5 一周以上 新手友好度 12/100
pocket-stack/pocketjs#757 ·
-
bug
难度 4/5 3-5 天 新手友好度 35/100
pocket-stack/pocketjs#744 ·
查看 pocket-stack/pocketjs 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
security: set top-level least-privilege permissions in five workflows可能已有人在做 @JonathanTSilva 今天认领。 未关闭priority: p2 size: xs type: security
难度 2/5 1-3 小时 新手友好度 64/100
JonathanTSilva/jts-website#150 ·
维护者通常 1 天内回复
-
bug Needs Triage
难度 2/5 1-3 小时 新手友好度 82/100
scottbenton/Iron-Link#437 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
speakeasy-api/speakeasy#2159 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
vercel-labs/ui#1066 ·
维护者通常 1 天内回复