Refine what can be called in method style.

This commit is contained in:
Stephen Chung
2022-12-27 22:06:51 +08:00
parent 7c00b74916
commit bb1136e8ad
6 changed files with 81 additions and 77 deletions

View File

@@ -575,14 +575,6 @@ impl Engine {
_is_method_call: bool,
pos: Position,
) -> RhaiResultOf<(Dynamic, bool)> {
fn no_method_err(name: &str, pos: Position) -> RhaiResultOf<(Dynamic, bool)> {
Err(ERR::ErrorRuntime(
format!("'{name}' should not be called this way. Try {name}(...);").into(),
pos,
)
.into())
}
// Check for data race.
#[cfg(not(feature = "no_closure"))]
ensure_no_data_race(fn_name, _args, is_ref_mut)?;
@@ -622,16 +614,13 @@ impl Engine {
// Handle is_shared()
#[cfg(not(feature = "no_closure"))]
crate::engine::KEYWORD_IS_SHARED if _args.len() == 1 => {
return no_method_err(fn_name, pos)
crate::engine::KEYWORD_IS_SHARED => {
unreachable!("{} called as method", fn_name)
}
KEYWORD_FN_PTR | KEYWORD_EVAL | KEYWORD_IS_DEF_VAR if _args.len() == 1 => {
return no_method_err(fn_name, pos)
}
KEYWORD_FN_PTR_CALL | KEYWORD_FN_PTR_CURRY if !_args.is_empty() => {
return no_method_err(fn_name, pos)
KEYWORD_FN_PTR | KEYWORD_EVAL | KEYWORD_IS_DEF_VAR | KEYWORD_FN_PTR_CALL
| KEYWORD_FN_PTR_CURRY => {
unreachable!("{} called as method", fn_name)
}
_ => (),