Rust codegen: MarshallerRef::get rejects omitted optional arguments from JS instead of returning undefined

オープン
#241 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
66/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, javascript, rust, typescript
領域
api, backend

調査の方向性

Start in valdi_core/src/valdi_core/rust/marshaller.rs at MarshallerRef::get, then compare its out-of-range behavior with valdi_rust_marshaller_get in valdi_core/src/valdi_core/cpp/Marshalling/RustValdi.cpp. Check how generated bindings deserialize optional and required parameters. Done when omitted trailing optional arguments become None and required arguments still report a type mismatch.

索引モデルが issue の本文から書いたものです。

説明

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

MarshallerRef::get rejects omitted optional arguments from JS instead of returning undefined

File: valdi_core/src/valdi_core/rust/marshaller.rs

When TypeScript or JavaScript calls a Rust module method, proxy method, or callback and omits a trailing optional argument (for example calling echoOptionalPoint() instead of echoOptionalPoint(undefined)), the call fails with a missing Valdi argument at index error instead of treating the omitted argument as None. This starts in MarshallerRef::get, which rejects any index at or above self.len.

Users calling any generated Rust API with an optional parameter receive an error whenever trailing optional arguments are omitted rather than explicitly passed as undefined.

On the C++ side, ValueMarshallerFunctionTrampoline::forwardCall only forwards the arguments JavaScript actually passed (auto resolvedParametersSize = std::min(_parametersSize, parametersSize);), so argument_count in ValdiCall is smaller than the declared parameter count even though generated Rust bindings unconditionally request every parameter with arguments.get(index)?. While valdi_rust_marshaller_get in valdi_core/src/valdi_core/cpp/Marshalling/RustValdi.cpp already returns &Valdi::Value::undefinedRef() for out-of-range indices (matching ValueFunctionCallContext::getParameter), MarshallerRef::get returns an error before reaching it.

Return a ValueRef to Valdi's undefined singleton when index >= self.len (for instance via a valdi_rust_value_undefined FFI helper) so Option<T> deserializes as None and non-optional parameters report a type mismatch.

主要言語
C++
スター
16.4k
フォーク
539
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Snapchat/Valdi のほかの issue

Snapchat/Valdi の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。