Skip to content

Commit

Permalink
Tweak msg_send! so return type cannot be omitted
Browse files Browse the repository at this point in the history
Previously, the structure of the macro meant that the return type was
inferred to () when no type was specified. This relied on an edge case
in the compiler and will produce undefined behavior in the future.

This fixes #62.
  • Loading branch information
SSheldon committed Oct 16, 2019
1 parent 4f8f67a commit df957f2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,38 @@ let _: () = msg_send![obj, setArg1:1 arg2:2];
macro_rules! msg_send {
(super($obj:expr, $superclass:expr), $name:ident) => ({
let sel = sel!($name);
let result;
match $crate::__send_super_message(&*$obj, $superclass, sel, ()) {
Err(s) => panic!("{}", s),
Ok(r) => r,
Ok(r) => result = r,
}
result
});
(super($obj:expr, $superclass:expr), $($name:ident : $arg:expr)+) => ({
let sel = sel!($($name:)+);
let result;
match $crate::__send_super_message(&*$obj, $superclass, sel, ($($arg,)*)) {
Err(s) => panic!("{}", s),
Ok(r) => r,
Ok(r) => result = r,
}
result
});
($obj:expr, $name:ident) => ({
let sel = sel!($name);
let result;
match $crate::__send_message(&*$obj, sel, ()) {
Err(s) => panic!("{}", s),
Ok(r) => r,
Ok(r) => result = r,
}
result
});
($obj:expr, $($name:ident : $arg:expr)+) => ({
let sel = sel!($($name:)+);
let result;
match $crate::__send_message(&*$obj, sel, ($($arg,)*)) {
Err(s) => panic!("{}", s),
Ok(r) => r,
Ok(r) => result = r,
}
result
});
}

0 comments on commit df957f2

Please sign in to comment.