Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mirrored struct field r#type generates invalid static checks #2416

Open
SilverMira opened this issue Nov 21, 2024 · 1 comment
Open

mirrored struct field r#type generates invalid static checks #2416

SilverMira opened this issue Nov 21, 2024 · 1 comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working

Comments

@SilverMira
Copy link
Contributor

SilverMira commented Nov 21, 2024

Describe the bug

Given a third party simple struct like this

// third_party

pub struct MyStruct {
  pub r#type: u32
}

and a mirror to it within frb crate

pub use third_party::MyStruct;

#[flutter_rust_bridge::frb(mirror(MyStruct))]
pub struct _MyStruct {
  pub r#type: u32
}

The generated code to type check the mirror doesn't include the r#

// frb_generated.rs
// Section: static_checks

#[allow(clippy::unnecessary_literal_unwrap)]
const _: fn() = || {
{ let MyStruct = None::<crate::api::simple::TestMirror>.unwrap(); let _: u32 = MyStruct.type;
                                                                                        ^^^^
 } 
};

Since type is a keyword, rust won't compile unless it's prefixed with r# and will complain syntax error.

Steps to reproduce

N/A

Logs

N/A

Expected behavior

The generated static check should respect r# if any in the mirror definition

Generated binding code

No response

OS

Windows

Version of flutter_rust_bridge_codegen

2.6.0

Flutter info

No response

Version of clang++

No response

Additional context

No response

@SilverMira SilverMira added the bug Something isn't working label Nov 21, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Nov 21, 2024

Looks like a bug, feel free to PR to fix it! Alternative I will work on it later, but since this has easy workaround (do not use r#keyword style) may not be within days.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants