Improve diagonstics on return_raw return mismatches

This commit is contained in:
J Henry Waugh
2020-08-23 17:22:29 -05:00
parent 7c273e0aac
commit 3fd3da6bfc
6 changed files with 104 additions and 9 deletions

View File

@@ -0,0 +1,25 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_fn(return_raw)]
pub fn test_fn(input: &mut Point) {
input.x += 1.0;
}
fn main() {
let n = Point {
x: 0.0,
y: 10.0,
};
test_fn(&mut n);
if n.x >= 10.0 {
println!("yes");
} else {
println!("no");
}
}

View File

@@ -0,0 +1,11 @@
error: return_raw functions must return Result<T>
--> $DIR/export_fn_raw_noreturn.rs:10:5
|
10 | pub fn test_fn(input: &mut Point) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0425]: cannot find function `test_fn` in this scope
--> $DIR/export_fn_raw_noreturn.rs:19:5
|
19 | test_fn(&mut n);
| ^^^^^^^ not found in this scope

View File

@@ -0,0 +1,24 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_fn(return_raw)]
pub fn test_fn(input: Point) -> bool {
input.x > input.y
}
fn main() {
let n = Point {
x: 0.0,
y: 10.0,
};
if test_fn(n) {
println!("yes");
} else {
println!("no");
}
}

View File

@@ -0,0 +1,21 @@
error[E0308]: mismatched types
--> $DIR/export_fn_raw_return.rs:10:8
|
9 | #[export_fn(return_raw)]
| ------------------------ expected `std::result::Result<rhai::Dynamic, std::boxed::Box<rhai::EvalAltResult>>` because of return type
10 | pub fn test_fn(input: Point) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found `bool`
|
= note: expected enum `std::result::Result<rhai::Dynamic, std::boxed::Box<rhai::EvalAltResult>>`
found type `bool`
error[E0308]: mismatched types
--> $DIR/export_fn_raw_return.rs:10:33
|
9 | #[export_fn(return_raw)]
| ------------------------ expected `std::result::Result<rhai::Dynamic, std::boxed::Box<rhai::EvalAltResult>>` because of return type
10 | pub fn test_fn(input: Point) -> bool {
| ^^^^ expected enum `std::result::Result`, found `bool`
|
= note: expected enum `std::result::Result<rhai::Dynamic, std::boxed::Box<rhai::EvalAltResult>>`
found type `bool`