erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Mocks in ObjC++ code cannot use .andReturn(nil) for an id argument #403

Closed dmaclach closed 4 years ago

dmaclach commented 4 years ago

So it turns out that C++ code @encodes nil differently than C code.

Compilation Settings @encode(typeof(nil))
ObjC ^v
ObjC++ with C++ 98 on 32 bit i
ObjC++ with C++ 98 on 64 bit q
ObjC++ with C++ 11 (all platforms) *

so at the point where the encoding is recorded (which is done in a macro) the value recorded could be any of the above. At the point where the encoding is compared (as a special case in OCMBoxedReturnValueProvider.m) we are only checking the ObjC version, so when we stub a mock with andReturn(nil) in Objective C++ we get an exception about the return type and the method signature return type not matching.

erikdoe commented 4 years ago

Closing this because the corresponding PR is merged. This will be released in OCMock 3.7.