-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from jerel/borrow-check
Add borrow checking and improve the error messaging
- Loading branch information
Showing
6 changed files
with
242 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
mod mock; | ||
use crate::mock::RUNTIME; | ||
|
||
mod test { | ||
use membrane::Membrane; | ||
use pretty_assertions::assert_eq; | ||
use std::path::Path; | ||
|
||
#[test] | ||
fn test_borrow_errors() { | ||
mod app { | ||
use membrane::async_dart; | ||
|
||
mod data { | ||
#[derive(serde::Deserialize, serde::Serialize)] | ||
pub struct Location(pub String); | ||
} | ||
|
||
#[async_dart( | ||
namespace = "a", | ||
// circular reference | ||
borrow = "b::Location", | ||
)] | ||
pub async fn reborrow_one() -> Result<data::Location, String> { | ||
todo!() | ||
} | ||
|
||
#[async_dart( | ||
namespace = "b", | ||
// circular reference | ||
borrow = "a::Location", | ||
)] | ||
pub async fn reborrow_two() -> Result<data::Location, String> { | ||
todo!() | ||
} | ||
} | ||
|
||
// gather metadata types and ensure that the above circular dependency is caught | ||
let mut membrane = Membrane::new(); | ||
|
||
membrane | ||
.package_destination_dir(Path::new("../dart_example")) | ||
.create_pub_package() | ||
.write_api(); | ||
|
||
assert_eq!( | ||
membrane.drain_errors(), | ||
vec!["The following `borrows` were found which attempt to reborrow a type which is not owned by the target namespace: `a::Location, b::Location`"] | ||
); | ||
} | ||
} |
Oops, something went wrong.