Refine codegen error positions.
This commit is contained in:
parent
37fe14ba16
commit
33fa57d95b
@ -1,6 +1,8 @@
|
|||||||
Rhai Release Notes
|
Rhai Release Notes
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
This version introduces functions with `Dynamic` parameters acting as wildcards.
|
||||||
|
|
||||||
Version 0.19.13
|
Version 0.19.13
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
@ -200,12 +200,22 @@ impl ExportedParams for ExportedFnParams {
|
|||||||
("global", None) => match namespace {
|
("global", None) => match namespace {
|
||||||
FnNamespaceAccess::Unset => namespace = FnNamespaceAccess::Global,
|
FnNamespaceAccess::Unset => namespace = FnNamespaceAccess::Global,
|
||||||
FnNamespaceAccess::Global => (),
|
FnNamespaceAccess::Global => (),
|
||||||
_ => return Err(syn::Error::new(key.span(), "conflicting namespace")),
|
FnNamespaceAccess::Internal => {
|
||||||
|
return Err(syn::Error::new(
|
||||||
|
key.span(),
|
||||||
|
"namespace is already set to 'internal'",
|
||||||
|
))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
("internal", None) => match namespace {
|
("internal", None) => match namespace {
|
||||||
FnNamespaceAccess::Unset => namespace = FnNamespaceAccess::Internal,
|
FnNamespaceAccess::Unset => namespace = FnNamespaceAccess::Internal,
|
||||||
FnNamespaceAccess::Internal => (),
|
FnNamespaceAccess::Internal => (),
|
||||||
_ => return Err(syn::Error::new(key.span(), "conflicting namespace")),
|
FnNamespaceAccess::Global => {
|
||||||
|
return Err(syn::Error::new(
|
||||||
|
key.span(),
|
||||||
|
"namespace is already set to 'global'",
|
||||||
|
))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
("get", Some(s)) => {
|
("get", Some(s)) => {
|
||||||
@ -478,10 +488,10 @@ impl ExportedFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn exported_name<'n>(&'n self) -> Cow<'n, str> {
|
pub fn exported_name<'n>(&'n self) -> Cow<'n, str> {
|
||||||
self.params.name.last().map_or_else(
|
self.params
|
||||||
|| self.signature.ident.to_string().into(),
|
.name
|
||||||
|s| s.as_str().into(),
|
.last()
|
||||||
)
|
.map_or_else(|| self.signature.ident.to_string().into(), |s| s.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn arg_list(&self) -> impl Iterator<Item = &syn::FnArg> {
|
pub fn arg_list(&self) -> impl Iterator<Item = &syn::FnArg> {
|
||||||
@ -519,7 +529,7 @@ impl ExportedFn {
|
|||||||
if params.pure.is_some() && !self.mutable_receiver() {
|
if params.pure.is_some() && !self.mutable_receiver() {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
params.pure.unwrap(),
|
params.pure.unwrap(),
|
||||||
"functions marked with 'pure' must have a &mut first parameter",
|
"'pure' is not necessary on functions without a &mut first parameter",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,21 +551,21 @@ impl ExportedFn {
|
|||||||
// 3a. Property setters must take the subject and a new value as arguments.
|
// 3a. Property setters must take the subject and a new value as arguments.
|
||||||
FnSpecialAccess::Property(Property::Set(_)) if self.arg_count() != 2 => {
|
FnSpecialAccess::Property(Property::Set(_)) if self.arg_count() != 2 => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.span(),
|
self.signature.inputs.span(),
|
||||||
"property setter requires exactly 2 parameters",
|
"property setter requires exactly 2 parameters",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
// 3b. Property setters must return nothing.
|
// 3b. Property setters must return nothing.
|
||||||
FnSpecialAccess::Property(Property::Set(_)) if self.return_type().is_some() => {
|
FnSpecialAccess::Property(Property::Set(_)) if self.return_type().is_some() => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.span(),
|
self.signature.output.span(),
|
||||||
"property setter cannot return any value",
|
"property setter cannot return any value",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
// 4a. Index getters must take the subject and the accessed "index" as arguments.
|
// 4a. Index getters must take the subject and the accessed "index" as arguments.
|
||||||
FnSpecialAccess::Index(Index::Get) if self.arg_count() != 2 => {
|
FnSpecialAccess::Index(Index::Get) if self.arg_count() != 2 => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.span(),
|
self.signature.inputs.span(),
|
||||||
"index getter requires exactly 2 parameters",
|
"index getter requires exactly 2 parameters",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -569,15 +579,15 @@ impl ExportedFn {
|
|||||||
// 5a. Index setters must take the subject, "index", and new value as arguments.
|
// 5a. Index setters must take the subject, "index", and new value as arguments.
|
||||||
FnSpecialAccess::Index(Index::Set) if self.arg_count() != 3 => {
|
FnSpecialAccess::Index(Index::Set) if self.arg_count() != 3 => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.span(),
|
self.signature.inputs.span(),
|
||||||
"index setter requires exactly 3 parameters",
|
"index setter requires exactly 3 parameters",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
// 5b. Index setters must return nothing.
|
// 5b. Index setters must return nothing.
|
||||||
FnSpecialAccess::Index(Index::Set) if self.return_type().is_some() => {
|
FnSpecialAccess::Index(Index::Set) if self.return_type().is_some() => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.span(),
|
self.signature.output.span(),
|
||||||
"index setter cannot return a value",
|
"index setter cannot return any value",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -667,7 +677,7 @@ impl ExportedFn {
|
|||||||
pub fn generate_callable(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
pub fn generate_callable(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
||||||
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
||||||
let callable_fn_name: syn::Ident = syn::Ident::new(
|
let callable_fn_name: syn::Ident = syn::Ident::new(
|
||||||
format!("{}_callable", on_type_name.to_lowercase()).as_str(),
|
&format!("{}_callable", on_type_name.to_lowercase()),
|
||||||
self.name().span(),
|
self.name().span(),
|
||||||
);
|
);
|
||||||
quote! {
|
quote! {
|
||||||
@ -680,7 +690,7 @@ impl ExportedFn {
|
|||||||
pub fn generate_input_names(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
pub fn generate_input_names(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
||||||
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
||||||
let input_names_fn_name: syn::Ident = syn::Ident::new(
|
let input_names_fn_name: syn::Ident = syn::Ident::new(
|
||||||
format!("{}_input_names", on_type_name.to_lowercase()).as_str(),
|
&format!("{}_input_names", on_type_name.to_lowercase()),
|
||||||
self.name().span(),
|
self.name().span(),
|
||||||
);
|
);
|
||||||
quote! {
|
quote! {
|
||||||
@ -693,7 +703,7 @@ impl ExportedFn {
|
|||||||
pub fn generate_input_types(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
pub fn generate_input_types(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
||||||
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
||||||
let input_types_fn_name: syn::Ident = syn::Ident::new(
|
let input_types_fn_name: syn::Ident = syn::Ident::new(
|
||||||
format!("{}_input_types", on_type_name.to_lowercase()).as_str(),
|
&format!("{}_input_types", on_type_name.to_lowercase()),
|
||||||
self.name().span(),
|
self.name().span(),
|
||||||
);
|
);
|
||||||
quote! {
|
quote! {
|
||||||
@ -706,7 +716,7 @@ impl ExportedFn {
|
|||||||
pub fn generate_return_type(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
pub fn generate_return_type(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
||||||
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
||||||
let return_type_fn_name: syn::Ident = syn::Ident::new(
|
let return_type_fn_name: syn::Ident = syn::Ident::new(
|
||||||
format!("{}_return_type", on_type_name.to_lowercase()).as_str(),
|
&format!("{}_return_type", on_type_name.to_lowercase()),
|
||||||
self.name().span(),
|
self.name().span(),
|
||||||
);
|
);
|
||||||
quote! {
|
quote! {
|
||||||
|
@ -217,7 +217,7 @@ impl Module {
|
|||||||
|
|
||||||
pub fn exported_name(&self) -> Cow<str> {
|
pub fn exported_name(&self) -> Cow<str> {
|
||||||
if !self.params.name.is_empty() {
|
if !self.params.name.is_empty() {
|
||||||
self.params.name.as_str().into()
|
(&self.params.name).into()
|
||||||
} else {
|
} else {
|
||||||
self.module_name().to_string().into()
|
self.module_name().to_string().into()
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ error: property getter requires exactly 1 parameter
|
|||||||
--> $DIR/rhai_fn_getter_signature.rs:13:9
|
--> $DIR/rhai_fn_getter_signature.rs:13:9
|
||||||
|
|
|
|
||||||
13 | pub fn test_fn(input: Point, value: bool) -> bool {
|
13 | pub fn test_fn(input: Point, value: bool) -> bool {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
||||||
--> $DIR/rhai_fn_getter_signature.rs:23:8
|
--> $DIR/rhai_fn_getter_signature.rs:23:8
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: conflicting namespace
|
error: namespace is already set to 'global'
|
||||||
--> $DIR/rhai_fn_global_multiple.rs:12:23
|
--> $DIR/rhai_fn_global_multiple.rs:12:23
|
||||||
|
|
|
|
||||||
12 | #[rhai_fn(global, internal)]
|
12 | #[rhai_fn(global, internal)]
|
||||||
|
@ -2,7 +2,7 @@ error: index getter requires exactly 2 parameters
|
|||||||
--> $DIR/rhai_fn_index_getter_signature.rs:13:9
|
--> $DIR/rhai_fn_index_getter_signature.rs:13:9
|
||||||
|
|
|
|
||||||
13 | pub fn test_fn(input: Point) -> bool {
|
13 | pub fn test_fn(input: Point) -> bool {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
||||||
--> $DIR/rhai_fn_index_getter_signature.rs:23:8
|
--> $DIR/rhai_fn_index_getter_signature.rs:23:8
|
||||||
|
@ -2,7 +2,7 @@ error: index setter requires exactly 3 parameters
|
|||||||
--> $DIR/rhai_fn_setter_index_signature.rs:13:9
|
--> $DIR/rhai_fn_setter_index_signature.rs:13:9
|
||||||
|
|
|
|
||||||
13 | pub fn test_fn(input: Point) -> bool {
|
13 | pub fn test_fn(input: Point) -> bool {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
||||||
--> $DIR/rhai_fn_setter_index_signature.rs:23:8
|
--> $DIR/rhai_fn_setter_index_signature.rs:23:8
|
||||||
|
@ -2,7 +2,7 @@ error: property setter cannot return any value
|
|||||||
--> $DIR/rhai_fn_setter_return.rs:13:9
|
--> $DIR/rhai_fn_setter_return.rs:13:9
|
||||||
|
|
|
|
||||||
13 | pub fn test_fn(input: &mut Point, value: f32) -> bool {
|
13 | pub fn test_fn(input: &mut Point, value: f32) -> bool {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
||||||
--> $DIR/rhai_fn_setter_return.rs:24:8
|
--> $DIR/rhai_fn_setter_return.rs:24:8
|
||||||
|
@ -2,7 +2,7 @@ error: property setter requires exactly 2 parameters
|
|||||||
--> $DIR/rhai_fn_setter_signature.rs:13:9
|
--> $DIR/rhai_fn_setter_signature.rs:13:9
|
||||||
|
|
|
|
||||||
13 | pub fn test_fn(input: Point) -> bool {
|
13 | pub fn test_fn(input: Point) -> bool {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
error[E0433]: failed to resolve: use of undeclared crate or module `test_module`
|
||||||
--> $DIR/rhai_fn_setter_signature.rs:23:8
|
--> $DIR/rhai_fn_setter_signature.rs:23:8
|
||||||
|
Loading…
Reference in New Issue
Block a user