No warning about missing return statement in Objective-C code in SPM

Hi. We noticed quite a strange behavior in SPM where it does not warn about missing return statements in Objective-C. Is this behavior expected?

  1. Create an Xcode project in Objective-C
  2. Create an SPM package in Objective-C
  3. Add a method in the SPM package that returns a BOOL
  4. Leave the body of the method empty (no return statement)
  5. Import the package in the project and invoke the method in the project

Expected: Build fails due missing return statement

Observed: Build succeeds and every time the method is run, it returns random values

Feedback: FB11558487

Is there a way to tell SPM to inherit build/compile flags from the Xcode project? When I try to do the same on the Xcode project side, I get the expected behavior. Build fails and I must fix the issue before proceeding. But not in case with SPM.

I think a missing return statement is at most a warning, not an error, in C-family languages. (A quick test with gcc gives an error with -Wall, but nothing with -W.)

@endecotp. Yes, I think you are right. There should be a warning at least. But in my observation, there is no indication at all. So to be more precise, this is what's happening. If I declare such a method in a class added to an Xcode project,

- (BOOL)doTheThing {
     // do not return anything
}

then I see a warning from Xcode saying that there is no return statement. And this issue is caught by our CI system which has a very strict policy on warnings. If anyone in the team adds even a single warning, then such a change cannot be merged.

But if I add the same method to a Swift package which is linked against the same Xcode project, then there is no clang warning in Xcode about it anymore. So now we have a situation that we have no idea how many other cases like that we have in our codebase because we are totally blind to it as Xcode/clang does not indicate any issue at all...

No warning about missing return statement in Objective-C code in SPM
 
 
Q