Rust codegen: RustMethodResolver fails to unwrap .nullable on optional interface/module methods

Open Beginner friendly
#247 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, typescript
Domain
backend

Research direction

Start with compiler/compiler/Compiler/Sources/Generation/Rust/RustMethodResolver.swift and read RustMethodResolver.resolve, where the issue identifies the switch on property.type. Check for existing tests covering optional interface or module methods, then run the relevant Rust code generation tests. Done means optional methods retain their declared parameters and return type in the generated Rust trait and FFI dispatch.

Written by the indexing model from the issue text.

Description

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

RustMethodResolver fails to unwrap .nullable on optional interface/module methods

File: compiler/compiler/Compiler/Sources/Generation/Rust/RustMethodResolver.swift

When an @ExportProxy or @ExportModule declares an optional method in TypeScript (such as onClose?(): void), the generated Rust trait and FFI dispatch treat it as a zero-argument getter returning Option<...Callback> instead of a method with the declared signature. RustMethodResolver.resolve switches directly on property.type rather than property.type.unwrappingOptional.

Because optional TypeScript methods are wrapped in .nullable(.function(...)), matching property.type without unwrapping falls into the default: branch, setting parameters to [] and returnType to .nullable(.function(...)).

Switch on property.type.unwrappingOptional instead of property.type in RustMethodResolver.resolve.

Dominant language
C++
Stars
16.4k
Forks
539
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Snapchat/Valdi

All issues in Snapchat/Valdi

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.