microts: generated Rust raises non_shorthand_field_patterns for a union variant with fields
まだ誰も着手していません。
評価
- 難易度
- 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 を出力し、.. レストケースも含めてください。その後、ハーネス内で再現用の 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 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 日以内に返信