microts: generated Rust raises non_shorthand_field_patterns for a union variant with fields
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust, typescript
Hướng nghiên cứu
Bắt đầu tại pattern trong microts/compiler/rust-printer.ts:68, chỗ hiện luôn ghi name: pattern; kiểm tra các caller của nó trong microts/compiler/aot-model-codegen.ts — match encode gần dòng 902 và đọc thành viên union gần dòng 496 — cả hai đều bind từng field vào một biến cùng tên. Phát ra shorthand khi tên được bind bằng tên field, bao gồm cả trường hợp rest .., sau đó chạy lại trong harness bun tools/pocket.ts compile --aot --out gen cùng với cargo check (lý tưởng nhất là với -D warnings) để xác nhận gen/app_model.rs không có warning.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 1.6k
- Fork
- 88
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pocket-stack/pocketjs
-
microts: a model local that every branch assigns raises unused_assignments in the generated RustĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
pocket-stack/pocketjs#756 ·
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
pocket-stack/pocketjs#745 ·
-
cli: the type check of pocket compile resolves "./app" to the view when the model is app.d.tsĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
pocket-stack/pocketjs#743 ·
-
bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
pocket-stack/pocketjs#757 ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
pocket-stack/pocketjs#744 ·
Tất cả issue của pocket-stack/pocketjs
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
security: set top-level least-privilege permissions in five workflowsCó thể đã có người làm @JonathanTSilva đã nhận hôm nay. Đang mởpriority: p2 size: xs type: security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
JonathanTSilva/jts-website#150 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] SETUP.md is out of dateĐang mởbug Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
scottbenton/Iron-Link#437 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
speakeasy-api/speakeasy#2159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vercel-labs/ui#1066 ·
Maintainer thường phản hồi trong vòng 1 ngày