Enforce signatures on user get/set/index functions
This commit is contained in:
28
codegen/ui_tests/rhai_fn_getter_conflict.rs
Normal file
28
codegen/ui_tests/rhai_fn_getter_conflict.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_getter_conflict.stderr
Normal file
11
codegen/ui_tests/rhai_fn_getter_conflict.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_getter_multiple.rs
Normal file
28
codegen/ui_tests/rhai_fn_getter_multiple.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_getter_multiple.stderr
Normal file
11
codegen/ui_tests/rhai_fn_getter_multiple.stderr
Normal file
@@ -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`
|
29
codegen/ui_tests/rhai_fn_getter_return.rs
Normal file
29
codegen/ui_tests/rhai_fn_getter_return.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_getter_return.stderr
Normal file
11
codegen/ui_tests/rhai_fn_getter_return.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_getter_signature.rs
Normal file
28
codegen/ui_tests/rhai_fn_getter_signature.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_getter_signature.stderr
Normal file
11
codegen/ui_tests/rhai_fn_getter_signature.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_index_getter_multiple.rs
Normal file
28
codegen/ui_tests/rhai_fn_index_getter_multiple.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_index_getter_multiple.stderr
Normal file
11
codegen/ui_tests/rhai_fn_index_getter_multiple.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_index_getter_return.rs
Normal file
28
codegen/ui_tests/rhai_fn_index_getter_return.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_index_getter_return.stderr
Normal file
11
codegen/ui_tests/rhai_fn_index_getter_return.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_index_getter_signature.rs
Normal file
28
codegen/ui_tests/rhai_fn_index_getter_signature.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_index_getter_signature.stderr
Normal file
11
codegen/ui_tests/rhai_fn_index_getter_signature.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_index_setter_multiple.rs
Normal file
28
codegen/ui_tests/rhai_fn_index_setter_multiple.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_index_setter_multiple.stderr
Normal file
11
codegen/ui_tests/rhai_fn_index_setter_multiple.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_setter_index_signature.rs
Normal file
28
codegen/ui_tests/rhai_fn_setter_index_signature.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_setter_index_signature.stderr
Normal file
11
codegen/ui_tests/rhai_fn_setter_index_signature.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_setter_multiple.rs
Normal file
28
codegen/ui_tests/rhai_fn_setter_multiple.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_setter_multiple.stderr
Normal file
11
codegen/ui_tests/rhai_fn_setter_multiple.stderr
Normal file
@@ -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`
|
29
codegen/ui_tests/rhai_fn_setter_return.rs
Normal file
29
codegen/ui_tests/rhai_fn_setter_return.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_setter_return.stderr
Normal file
11
codegen/ui_tests/rhai_fn_setter_return.stderr
Normal file
@@ -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`
|
28
codegen/ui_tests/rhai_fn_setter_signature.rs
Normal file
28
codegen/ui_tests/rhai_fn_setter_signature.rs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/rhai_fn_setter_signature.stderr
Normal file
11
codegen/ui_tests/rhai_fn_setter_signature.stderr
Normal file
@@ -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`
|
Reference in New Issue
Block a user