diff --git a/codegen/src/function.rs b/codegen/src/function.rs index 4e5bf139..41b3aac1 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -113,6 +113,14 @@ impl Parse for ExportedFnParams { } } + // Check validity of name, if present. + if name.as_ref().filter(|n| n.contains('.')).is_some() { + return Err(syn::Error::new( + span, + "Rhai function names may not contain dot" + )) + } + Ok(ExportedFnParams { name, return_raw, diff --git a/codegen/ui_tests/rhai_fn_rename_dot.rs b/codegen/ui_tests/rhai_fn_rename_dot.rs new file mode 100644 index 00000000..9e2180d9 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_rename_dot.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.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_rename_dot.stderr b/codegen/ui_tests/rhai_fn_rename_dot.stderr new file mode 100644 index 00000000..f650a081 --- /dev/null +++ b/codegen/ui_tests/rhai_fn_rename_dot.stderr @@ -0,0 +1,11 @@ +error: Rhai function names may not contain dot + --> $DIR/rhai_fn_rename_dot.rs:12:15 + | +12 | #[rhai_fn(name = "foo.bar")] + | ^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_module` + --> $DIR/rhai_fn_rename_dot.rs:23:8 + | +23 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared type or module `test_module`