Skip to content

Commit df957f2

Browse files
committed
Tweak msg_send! so return type cannot be omitted
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.
1 parent 4f8f67a commit df957f2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/macros.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,38 @@ let _: () = msg_send![obj, setArg1:1 arg2:2];
111111
macro_rules! msg_send {
112112
(super($obj:expr, $superclass:expr), $name:ident) => ({
113113
let sel = sel!($name);
114+
let result;
114115
match $crate::__send_super_message(&*$obj, $superclass, sel, ()) {
115116
Err(s) => panic!("{}", s),
116-
Ok(r) => r,
117+
Ok(r) => result = r,
117118
}
119+
result
118120
});
119121
(super($obj:expr, $superclass:expr), $($name:ident : $arg:expr)+) => ({
120122
let sel = sel!($($name:)+);
123+
let result;
121124
match $crate::__send_super_message(&*$obj, $superclass, sel, ($($arg,)*)) {
122125
Err(s) => panic!("{}", s),
123-
Ok(r) => r,
126+
Ok(r) => result = r,
124127
}
128+
result
125129
});
126130
($obj:expr, $name:ident) => ({
127131
let sel = sel!($name);
132+
let result;
128133
match $crate::__send_message(&*$obj, sel, ()) {
129134
Err(s) => panic!("{}", s),
130-
Ok(r) => r,
135+
Ok(r) => result = r,
131136
}
137+
result
132138
});
133139
($obj:expr, $($name:ident : $arg:expr)+) => ({
134140
let sel = sel!($($name:)+);
141+
let result;
135142
match $crate::__send_message(&*$obj, sel, ($($arg,)*)) {
136143
Err(s) => panic!("{}", s),
137-
Ok(r) => r,
144+
Ok(r) => result = r,
138145
}
146+
result
139147
});
140148
}

0 commit comments

Comments
 (0)