This patch removes some redundant functions that implement checking availability against context, and implements a new, more correct one: ShouldDiagnoseAvailabilityInContext. This is done to more easily allow delaying AD_NotYetIntroduced diagnostics, which is a patch I'll submit right after this!
As it happens, this fixes a bug:
int unavailable_global __attribute__((unavailable)); __attribute__((unavailable)) @interface Foo - meth; @end @implementation Foo - meth { (void) unavailable_global; // no error (void) ^{ (void) unavailable_global; // incorrect-error: 'unavailable_global' is not available }; } @end
Here, there is a reference to an unavailable declaration, unavailable, in the context of a block. We shouldn't emit an error here because 'meth' is implicitly unavailable, meaning that we should be able to reference other unavailable declarations inside it
The problem is that, though both isDeclUnavailable() and getCurContextAvailability() check the reference to unavailable_global, isDeclUnavailable doesn't infer availability attributes from @interface to @implementation (But does consider nested contexts), and getCurContextAvailability() doesn't consider non-immediate contexts (But does infer from @interface -> @implementation). Since they both don't catch this case, this error is emitted when it really shouldn't be!
Thanks for taking a look!