Skip to content

Commit 465e8dc

Browse files
committed
Reject a text signature that puts / after * or **
The writer counts positional-only parameters up front and emits `/` when they run out, which assumes they come first in the Rust argument list. Nothing enforced that, and posix.chmod violated it. The signature is composed in a const context, so the assert fails the build and names the fix. Assisted-by: Claude Code:claude-opus-5
1 parent 1bf3c17 commit 465e8dc

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎crates/vm/src/function/signature.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ struct St {
242242
emitted: bool,
243243
po_left: usize,
244244
var_pos_seen: bool,
245+
var_kw_seen: bool,
245246
star_emitted: bool,
246247
}
247248

@@ -255,6 +256,7 @@ const fn write_signature_prefix(buf: &mut [u8], name: &str, args: &[SigArg]) ->
255256
emitted: false,
256257
po_left: count_po_args(args),
257258
var_pos_seen: false,
259+
var_kw_seen: false,
258260
star_emitted: false,
259261
},
260262
args,
@@ -575,6 +577,12 @@ const fn write_one(buf: &mut [u8], mut st: St, param: Param, fallback: &str) ->
575577
st = emit_named(buf, st, "", name, param.default);
576578
st.po_left -= 1;
577579
if st.po_left == 0 {
580+
// Python rejects `/` after `*` or `**`. The Rust arguments put a
581+
// keyword or variadic one before a positional one; reorder them.
582+
assert!(
583+
!st.star_emitted && !st.var_pos_seen && !st.var_kw_seen,
584+
"positional-only parameter after `*` or `**`: reorder the Rust arguments"
585+
);
578586
st = emit_text(buf, st, "/");
579587
}
580588
st
@@ -591,7 +599,10 @@ const fn write_one(buf: &mut [u8], mut st: St, param: Param, fallback: &str) ->
591599
st.var_pos_seen = true;
592600
emit_named(buf, st, "*", name, param.default)
593601
}
594-
ParamKind::VarKeyword => emit_named(buf, st, "**", name, param.default),
602+
ParamKind::VarKeyword => {
603+
st.var_kw_seen = true;
604+
emit_named(buf, st, "**", name, param.default)
605+
}
595606
}
596607
}
597608

@@ -631,6 +642,7 @@ mod tests {
631642
emitted: false,
632643
po_left: 0,
633644
var_pos_seen: false,
645+
var_kw_seen: false,
634646
star_emitted: true,
635647
},
636648
Param {

0 commit comments

Comments
 (0)