jspahrsummers / libextobjc

A Cocoa library to extend the Objective-C programming language.
MIT License
4.53k stars 461 forks source link

Non-void fonction not detected by Xcode compiler; Missing return warning #121

Open BelaSzombathelyi opened 8 years ago

BelaSzombathelyi commented 8 years ago

The LLVM not drop warning for this:

- (int)test
{
    if (YES) {

    } else {
        @weakify(self);
        ^{
            @strongify(self);
            NSLog(@"%@",self.class);
        }();
    }
}

If I remove weakly and strongly it drop compile error.

- (int)test
{
    if (YES) {

    } else {
        ^{
            NSLog(@"%@",self.class);
        }();
    }
} // Control reaches end of non-void function
jspahrsummers commented 8 years ago

I'm not sure why @weakify and @strongify would have anything to do with this.

If you use explicit __weak and __strong variables, do you see the same issue?

BelaSzombathelyi commented 8 years ago

No, I can not compile it.

- (int)test
{
    if (YES) {

    } else {
        __weak __typeof(self)weakSelf = self;
        ^{
            __strong __typeof(weakSelf) strongSelf = weakSelf;
            NSLog(@"%@",strongSelf.class);
        }();
    }
} // Control reaches end of non-void function
BelaSzombathelyi commented 8 years ago

I use LLVM 7.1 with Xcode 7.3.1 (7D1014), (if it helps)

jspahrsummers commented 8 years ago

It might be the @finally embedded within the macros. I'm not sure there's a readily apparent solution here, sorry. 😕

BelaSzombathelyi commented 8 years ago

I found the answer. If a method contains try-catch block, compiler not warning for "Non-void function" Example:

- (int)test
{
    @try {

    } @catch (NSException *exception) {

    }
}//No error

This bug no jump between methods, only one method deep.

- (int)a
{
    [self b];
} // Control reaches end of non-void function

- (void)b
{
    @try {

    } @catch (NSException *exception) {

    }
}