Unverified Commit 4e2c7c30 authored by Karel L. Kubat's avatar Karel L. Kubat Committed by GitHub
Browse files

[lang] catch illegal struct destructuring pattern in ink! message arguments. (#846)

* [lang] catch illegal struct destructuring pattern in ink! message arguments.

* fmt
parent 011bae31
Pipeline #146181 failed with stages
in 12 minutes and 41 seconds
......@@ -417,6 +417,19 @@ pub(super) fn ensure_callable_invariants(
kind,
))
}
if let Some(arg) = method_item.sig.inputs.iter().find(|input| {
match input {
syn::FnArg::Typed(pat) => !matches!(*pat.pat, syn::Pat::Ident(_)),
_ => false,
}
}) {
return Err(format_err_spanned!(
arg,
"ink! {} arguments must have an identifier",
kind
))
}
Ok(())
}
......
......@@ -38,6 +38,7 @@ fn compile_tests() {
t.compile_fail("tests/ui/fail/C-13-abi-constructor.rs");
t.compile_fail("tests/ui/fail/C-14-payable-constructor.rs");
t.compile_fail("tests/ui/fail/C-15-payable-trait-constructor.rs");
t.compile_fail("tests/ui/fail/C-16-function-arg-struct-destructuring.rs");
t.compile_fail("tests/ui/fail/H-01-invalid-dyn-alloc.rs");
t.compile_fail("tests/ui/fail/H-02-invalid-as-dependency.rs");
......
use ink_lang as ink;
#[ink::contract]
mod noop {
struct Args {
foo: (),
}
#[ink(storage)]
pub struct Noop {}
impl Noop {
#[ink(constructor)]
pub fn new() -> Self {
Self {}
}
#[ink(message)]
pub fn noop(&self, Foo { foo }: Foo) {}
}
}
fn main() {}
error: ink! message arguments must have an identifier
--> $DIR/C-16-function-arg-struct-destructuring.rs:20:28
|
20 | pub fn noop(&self, Foo { foo }: Foo) {}
| ^^^^^^^^^^^^^^^^
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment