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

Fix to make incorrect return type into error #169

Merged
merged 2 commits into from
Feb 15, 2023

Conversation

MikuroXina
Copy link
Contributor

@MikuroXina MikuroXina commented Feb 13, 2023

This commit introduces a compile time error for incorrect return types.

For example, the following will now fail to compile:

#[swift_bridge::bridge]
mod ffi {
    extern "Rust" {
        fn get_reference() -> SomeType;
    }
}

fn get_reference() -> &'static SomeType {
    &SomeType
}

Before this commit the above example would compile and calling get_reference would cause undefined behavior.

Copy link
Owner

@chinedufn chinedufn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your first contribution!

Left one minor request then after that we can merge this.

@chinedufn chinedufn merged commit e7aef34 into chinedufn:master Feb 15, 2023
@chinedufn
Copy link
Owner

@MikuroXina I merged your PR as is, thanks for the contribution!

I added a commit message to illustrate the change. We try to explain every commit using a thorough example.

I've also updated your PR body with an example.

@chinedufn
Copy link
Owner

Sorry for pointing you in the wrong direction.

I made a change to improve the compile time error message here 1b33e95

Here's the new message:

error[E0308]: mismatched types
--> tests/ui/incorrect-return-type.rs:6:1
|
6 | #[swift_bridge::bridge]
| ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `SomeType`, found `&SomeType`
...
9 | type SomeType;
| ______________-
10 | |
11 | | #[swift_bridge(rust_name = "some_function")]
12 | | fn fn1() -> SomeType;
| |_____________________________- expected due to this
|
= note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> tests/ui/incorrect-return-type.rs:6:1
|
6 | #[swift_bridge::bridge]
| ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `SomeType`, found enum `Option`
...
9 | type SomeType;
| ______________-
10 | |
11 | | #[swift_bridge(rust_name = "some_function")]
12 | | fn fn1() -> SomeType;
13 | | #[swift_bridge(rust_name = "another_function")]
14 | | fn fn2() -> SomeType;
| |_____________________________- expected due to this
|
= note: expected struct `SomeType`
found enum `Option<SomeType>`
= note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)

@MikuroXina MikuroXina deleted the fix/#12 branch February 15, 2023 16:35
@chinedufn
Copy link
Owner

Closed #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants