diff --git a/codegen/src/function.rs b/codegen/src/function.rs index 3b0edee8..75812dbd 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -377,9 +377,11 @@ impl ExportedFn { } pub fn set_params(&mut self, mut params: ExportedFnParams) -> syn::Result<()> { - // Do not allow non-returning raw functions. + // Several issues are checked here to avoid issues with diagnostics caused by raising them + // later. + // + // 1. Do not allow non-returning raw functions. // - // This is caught now to avoid issues with diagnostics later. if params.return_raw && mem::discriminant(&self.signature.output) == mem::discriminant(&syn::ReturnType::Default) @@ -390,6 +392,58 @@ impl ExportedFn { )); } + match params.special { + // 2a. Property getters must take only the subject as an argument. + FnSpecialAccess::Property(Property::Get(_)) if self.arg_count() != 1 => + return Err(syn::Error::new( + self.signature.span(), + "property getter requires exactly 1 argument", + )), + // 2b. Property getters must return a value. + FnSpecialAccess::Property(Property::Get(_)) if self.return_type().is_none() => + return Err(syn::Error::new( + self.signature.span(), + "property getter must return a value" + )), + // 3a. Property setters must take the subject and a new value as arguments. + FnSpecialAccess::Property(Property::Set(_)) if self.arg_count() != 2 => + return Err(syn::Error::new( + self.signature.span(), + "property setter requires exactly 2 arguments", + )), + // 3b. Property setters must return nothing. + FnSpecialAccess::Property(Property::Set(_)) if self.return_type().is_some() => + return Err(syn::Error::new( + self.signature.span(), + "property setter must return no value" + )), + // 4a. Index getters must take the subject and the accessed "index" as arguments. + FnSpecialAccess::Index(Index::Get) if self.arg_count() != 2 => + return Err(syn::Error::new( + self.signature.span(), + "index getter requires exactly 2 arguments", + )), + // 4b. Index getters must return a value. + FnSpecialAccess::Index(Index::Get) if self.return_type().is_none() => + return Err(syn::Error::new( + self.signature.span(), + "index getter must return a value" + )), + // 5a. Index setters must take the subject, "index", and new value as arguments. + FnSpecialAccess::Index(Index::Set) if self.arg_count() != 3 => + return Err(syn::Error::new( + self.signature.span(), + "index setter requires exactly 3 arguments", + )), + // 5b. Index setters must return nothing. + FnSpecialAccess::Index(Index::Set) if self.return_type().is_some() => + return Err(syn::Error::new( + self.signature.span(), + "index setter must return no value" + )), + _ => {} + } + self.params = params; Ok(()) } diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index e830600e..2bf48752 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -1197,23 +1197,25 @@ mod generate_tests { let input_tokens: TokenStream = quote! { pub mod one_fn { #[rhai_fn(set = "squared")] - pub fn int_foo(x: &mut u64) { - *x = (*x) * (*x) + pub fn int_foo(x: &mut u64, y: u64) { + *x = y * y } } }; let expected_tokens = quote! { pub mod one_fn { - pub fn int_foo(x: &mut u64) { - *x = (*x) * (*x) + pub fn int_foo(x: &mut u64, y: u64) { + *x = y * y } #[allow(unused_imports)] use super::*; #[allow(unused_mut)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); - m.set_fn("set$squared", FnAccess::Public, &[core::any::TypeId::of::()], + m.set_fn("set$squared", FnAccess::Public, + &[core::any::TypeId::of::(), + core::any::TypeId::of::()], CallableFunction::from_plugin(int_foo_token())); m } @@ -1223,10 +1225,11 @@ mod generate_tests { fn call(&self, args: &mut [&mut Dynamic], pos: Position ) -> Result> { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); + debug_assert_eq!(args.len(), 2usize, + "wrong arg count: {} != {}", args.len(), 2usize); + let arg1 = mem::take(args[1usize]).clone().cast::(); let arg0: &mut _ = &mut args[0usize].write_lock::().unwrap(); - Ok(Dynamic::from(int_foo(arg0))) + Ok(Dynamic::from(int_foo(arg0, arg1))) } fn is_method_call(&self) -> bool { true } @@ -1235,7 +1238,7 @@ mod generate_tests { Box::new(int_foo_token()) } fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() + new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } } pub fn int_foo_token_callable() -> CallableFunction { @@ -1256,25 +1259,29 @@ mod generate_tests { let input_tokens: TokenStream = quote! { pub mod one_fn { #[rhai_fn(name = "set_sq", set = "squared")] - pub fn int_foo(x: &mut u64) { - *x = (*x) * (*x) + pub fn int_foo(x: &mut u64, y: u64) { + *x = y * y } } }; let expected_tokens = quote! { pub mod one_fn { - pub fn int_foo(x: &mut u64) { - *x = (*x) * (*x) + pub fn int_foo(x: &mut u64, y: u64) { + *x = y * y } #[allow(unused_imports)] use super::*; #[allow(unused_mut)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); - m.set_fn("set_sq", FnAccess::Public, &[core::any::TypeId::of::()], + m.set_fn("set_sq", FnAccess::Public, + &[core::any::TypeId::of::(), + core::any::TypeId::of::()], CallableFunction::from_plugin(int_foo_token())); - m.set_fn("set$squared", FnAccess::Public, &[core::any::TypeId::of::()], + m.set_fn("set$squared", FnAccess::Public, + &[core::any::TypeId::of::(), + core::any::TypeId::of::()], CallableFunction::from_plugin(int_foo_token())); m } @@ -1284,10 +1291,11 @@ mod generate_tests { fn call(&self, args: &mut [&mut Dynamic], pos: Position ) -> Result> { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); + debug_assert_eq!(args.len(), 2usize, + "wrong arg count: {} != {}", args.len(), 2usize); + let arg1 = mem::take(args[1usize]).clone().cast::(); let arg0: &mut _ = &mut args[0usize].write_lock::().unwrap(); - Ok(Dynamic::from(int_foo(arg0))) + Ok(Dynamic::from(int_foo(arg0, arg1))) } fn is_method_call(&self) -> bool { true } @@ -1296,7 +1304,7 @@ mod generate_tests { Box::new(int_foo_token()) } fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() + new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } } pub fn int_foo_token_callable() -> CallableFunction { diff --git a/codegen/ui_tests/rhai_fn_getter_conflict.rs b/codegen/ui_tests/rhai_fn_getter_conflict.rs new file mode 100644 index 00000000..66cdb9d0 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_conflict.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(name = "foo", get = "foo", set = "bar")] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_getter_conflict.stderr b/codegen/ui_tests/rhai_fn_getter_conflict.stderr new file mode 100644 index 00000000..de276c78 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_conflict.stderr @@ -0,0 +1,11 @@ +error: conflicting setter + --> $DIR/rhai_fn_getter_conflict.rs:12:42 + | +12 | #[rhai_fn(name = "foo", get = "foo", set = "bar")] + | ^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_getter_conflict.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_getter_multiple.rs b/codegen/ui_tests/rhai_fn_getter_multiple.rs new file mode 100644 index 00000000..d60a11ba --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_multiple.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(name = "foo", get = "foo", get = "bar")] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_getter_multiple.stderr b/codegen/ui_tests/rhai_fn_getter_multiple.stderr new file mode 100644 index 00000000..d5167326 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_multiple.stderr @@ -0,0 +1,11 @@ +error: conflicting getter + --> $DIR/rhai_fn_getter_multiple.rs:12:42 + | +12 | #[rhai_fn(name = "foo", get = "foo", get = "bar")] + | ^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_getter_multiple.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_getter_return.rs b/codegen/ui_tests/rhai_fn_getter_return.rs new file mode 100644 index 00000000..da7c8454 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_return.rs @@ -0,0 +1,29 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(get = "foo")] + pub fn test_fn(input: &mut Point) { + input.x *= 2.0; + } +} + +fn main() { + let mut n = Point { + x: 0.0, + y: 10.0, + }; + test_module::test_fn(&mut n); + if n.x > 10.0 { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_getter_return.stderr b/codegen/ui_tests/rhai_fn_getter_return.stderr new file mode 100644 index 00000000..6f7a7e40 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_return.stderr @@ -0,0 +1,11 @@ +error: property getter must return a value + --> $DIR/rhai_fn_getter_return.rs:13:9 + | +13 | pub fn test_fn(input: &mut Point) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_getter_return.rs:23:5 + | +23 | test_module::test_fn(&mut n); + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_getter_signature.rs b/codegen/ui_tests/rhai_fn_getter_signature.rs new file mode 100644 index 00000000..c4f1952d --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_signature.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(get = "foo")] + pub fn test_fn(input: Point, value: bool) -> bool { + value && input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n, true) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_getter_signature.stderr b/codegen/ui_tests/rhai_fn_getter_signature.stderr new file mode 100644 index 00000000..863757e1 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_getter_signature.stderr @@ -0,0 +1,11 @@ +error: property getter requires exactly 1 argument + --> $DIR/rhai_fn_getter_signature.rs:13:9 + | +13 | pub fn test_fn(input: Point, value: bool) -> bool { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_getter_signature.rs:23:8 + | +23 | if test_module::test_fn(n, true) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_index_getter_multiple.rs b/codegen/ui_tests/rhai_fn_index_getter_multiple.rs new file mode 100644 index 00000000..450c8aa5 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_getter_multiple.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(name = "foo", index_get, index_get)] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_index_getter_multiple.stderr b/codegen/ui_tests/rhai_fn_index_getter_multiple.stderr new file mode 100644 index 00000000..94e8df2e --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_getter_multiple.stderr @@ -0,0 +1,11 @@ +error: conflicting index_get + --> $DIR/rhai_fn_index_getter_multiple.rs:12:40 + | +12 | #[rhai_fn(name = "foo", index_get, index_get)] + | ^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_index_getter_multiple.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_index_getter_return.rs b/codegen/ui_tests/rhai_fn_index_getter_return.rs new file mode 100644 index 00000000..32b8c3ee --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_getter_return.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(index_get)] + pub fn test_fn(input: &mut Point, i: f32) { + input.x *= 2.0; + } +} + +fn main() { + let mut n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(&mut n, 5.0) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_index_getter_return.stderr b/codegen/ui_tests/rhai_fn_index_getter_return.stderr new file mode 100644 index 00000000..cb4c020f --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_getter_return.stderr @@ -0,0 +1,11 @@ +error: index getter must return a value + --> $DIR/rhai_fn_index_getter_return.rs:13:9 + | +13 | pub fn test_fn(input: &mut Point, i: f32) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_index_getter_return.rs:23:8 + | +23 | if test_module::test_fn(&mut n, 5.0) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_index_getter_signature.rs b/codegen/ui_tests/rhai_fn_index_getter_signature.rs new file mode 100644 index 00000000..e6fe68f5 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_getter_signature.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(index_get)] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_index_getter_signature.stderr b/codegen/ui_tests/rhai_fn_index_getter_signature.stderr new file mode 100644 index 00000000..efdcff4a --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_getter_signature.stderr @@ -0,0 +1,11 @@ +error: index getter requires exactly 2 arguments + --> $DIR/rhai_fn_index_getter_signature.rs:13:9 + | +13 | pub fn test_fn(input: Point) -> bool { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_index_getter_signature.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_index_setter_multiple.rs b/codegen/ui_tests/rhai_fn_index_setter_multiple.rs new file mode 100644 index 00000000..77d8cf3e --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_setter_multiple.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(name = "foo", index_set, index_set)] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_index_setter_multiple.stderr b/codegen/ui_tests/rhai_fn_index_setter_multiple.stderr new file mode 100644 index 00000000..5a6de59d --- /dev/null +++ b/codegen/ui_tests/rhai_fn_index_setter_multiple.stderr @@ -0,0 +1,11 @@ +error: conflicting index_set + --> $DIR/rhai_fn_index_setter_multiple.rs:12:40 + | +12 | #[rhai_fn(name = "foo", index_set, index_set)] + | ^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_index_setter_multiple.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_setter_index_signature.rs b/codegen/ui_tests/rhai_fn_setter_index_signature.rs new file mode 100644 index 00000000..21a71846 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_index_signature.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(index_set)] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_setter_index_signature.stderr b/codegen/ui_tests/rhai_fn_setter_index_signature.stderr new file mode 100644 index 00000000..c4123d51 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_index_signature.stderr @@ -0,0 +1,11 @@ +error: index setter requires exactly 3 arguments + --> $DIR/rhai_fn_setter_index_signature.rs:13:9 + | +13 | pub fn test_fn(input: Point) -> bool { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_setter_index_signature.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_setter_multiple.rs b/codegen/ui_tests/rhai_fn_setter_multiple.rs new file mode 100644 index 00000000..170a373c --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_multiple.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(name = "foo", set = "foo", set = "bar")] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_setter_multiple.stderr b/codegen/ui_tests/rhai_fn_setter_multiple.stderr new file mode 100644 index 00000000..aa4553ec --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_multiple.stderr @@ -0,0 +1,11 @@ +error: conflicting setter + --> $DIR/rhai_fn_setter_multiple.rs:12:42 + | +12 | #[rhai_fn(name = "foo", set = "foo", set = "bar")] + | ^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_setter_multiple.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_setter_return.rs b/codegen/ui_tests/rhai_fn_setter_return.rs new file mode 100644 index 00000000..5a2542a8 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_return.rs @@ -0,0 +1,29 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(set = "foo")] + pub fn test_fn(input: &mut Point, value: f32) -> bool { + let z = if value % 2 { input.x } else { input.y }; + *input.x = z; + } +} + +fn main() { + let mut n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(&mut n, 5.0) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_setter_return.stderr b/codegen/ui_tests/rhai_fn_setter_return.stderr new file mode 100644 index 00000000..383b6711 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_return.stderr @@ -0,0 +1,11 @@ +error: property setter must return no value + --> $DIR/rhai_fn_setter_return.rs:13:9 + | +13 | pub fn test_fn(input: &mut Point, value: f32) -> bool { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_setter_return.rs:24:8 + | +24 | if test_module::test_fn(&mut n, 5.0) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module` diff --git a/codegen/ui_tests/rhai_fn_setter_signature.rs b/codegen/ui_tests/rhai_fn_setter_signature.rs new file mode 100644 index 00000000..06e401a6 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_signature.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_module { + pub use super::Point; + #[rhai_fn(set = "foo")] + pub fn test_fn(input: Point) -> bool { + input.x > input.y + } +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_module::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/rhai_fn_setter_signature.stderr b/codegen/ui_tests/rhai_fn_setter_signature.stderr new file mode 100644 index 00000000..719663f2 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_setter_signature.stderr @@ -0,0 +1,11 @@ +error: property setter requires exactly 2 arguments + --> $DIR/rhai_fn_setter_signature.rs:13:9 + | +13 | pub fn test_fn(input: Point) -> bool { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_setter_signature.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module`