Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lang] Improve invalid selector error #561

Merged
merged 10 commits into from
Nov 4, 2020
Merged
3 changes: 2 additions & 1 deletion crates/lang/ir/src/ir/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ impl TryFrom<syn::NestedMeta> for AttributeArg {
)
})?;
let str = lit_str.value();
let cap = regex.captures(&str).unwrap();
let cap = regex.captures(&str)
.expect("invalid selector - a selector must consist of four bytes in hex (e.g. `selector = \"0xCAFEBABE\"`)");
cmichi marked this conversation as resolved.
Show resolved Hide resolved
let selector_bytes = [
u8::from_str_radix(&cap[1], 16).expect(
"encountered non-hex digit at position 0",
cmichi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
1 change: 1 addition & 0 deletions crates/lang/macro/tests/compile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn compile_tests() {
t.compile_fail("tests/ui/fail/M-02-message-missing-self-arg.rs");
t.compile_fail("tests/ui/fail/M-03-message-returns-self.rs");
t.compile_fail("tests/ui/fail/M-04-message-returns-non-codec.rs");
t.compile_fail("tests/ui/fail/M-05-message-invalid-selector.rs");
t.compile_fail("tests/ui/fail/M-10-method-unknown-ink-marker.rs");

t.compile_fail("tests/ui/fail/S-01-missing-storage-struct.rs");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use ink_lang as ink;

#[ink::contract]
mod message_invalid_selector {
#[ink(storage)]
pub struct MessageInvalidSelector {}

impl MessageInvalidSelector {
#[ink(constructor)]
pub fn constructor() -> Self {
Self {}
}

#[ink(message, selector = "0x00")]
pub fn invalid_selector(&self) { }
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: custom attribute panicked
--> $DIR/M-05-message-invalid-selector.rs:3:1
|
3 | #[ink::contract]
cmichi marked this conversation as resolved.
Show resolved Hide resolved
| ^^^^^^^^^^^^^^^^
|
= help: message: invalid selector - a selector must consist of four bytes in hex (e.g. `selector = "0xCAFEBABE"`)