Skip to content

Commit

Permalink
Change setupForwarderForSelector to still call "class_replaceMethod" …
Browse files Browse the repository at this point in the history
…if original implementation couldn't be found
  • Loading branch information
LowAmmo committed Dec 3, 2024
1 parent c1fc8d0 commit f773895
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Source/OCMock/OCPartialMockObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ - (void)setupForwarderForSelector:(SEL)sel
Method originalMethod = class_getInstanceMethod(mockedClass, sel);
/* Might be NULL if the selector is forwarded to another class */
IMP originalIMP = (originalMethod != NULL) ? method_getImplementation(originalMethod) : NULL;
if(originalIMP == NULL)
return;

const char *types = (originalMethod != NULL) ? method_getTypeEncoding(originalMethod) : NULL;
// TODO: check the fallback implementation is actually sufficient
if(types == NULL)
Expand All @@ -217,7 +214,8 @@ - (void)setupForwarderForSelector:(SEL)sel
Class subclass = object_getClass([self realObject]);
IMP forwarderIMP = [mockedClass instanceMethodForwarderForSelector:sel];
class_replaceMethod(subclass, sel, forwarderIMP, types);
class_addMethod(subclass, aliasSelector, originalIMP, types);
if(originalIMP != NULL)
class_addMethod(subclass, aliasSelector, originalIMP, types);
}


Expand Down

0 comments on commit f773895

Please sign in to comment.