[Sema]Suppress availability diagnostics inside synthesized functions.

This commit suppresses errors for references to unavailable symbols inside
implicit functions.

This is a quick hack to fix a hit-listed radar <rdar://problem/20007266> where
the compiler was emitting spurious errors for enums explicitly marked
unavailable in Objective-C and whose nil literal conformance is synthesized by
the importer. These errors could occur when user code made no apparent reference
to the enum in question and instead only referred to an imported class that
itself referred to the enum in a method signature.

We will need to do something systematic about availability and deprecation
diagnostics in synthesized code.  In particular, we should make sure that:
(1) we never emit code that references explicitly unavailable symbols;
(2) that the user never gets an error about symbol that they did not explicitly type; and
(3) that errors can dealt with via the appropriate availability check or annotation. I'm
tracking this with radar rdar://problem/20024980.

rdar://problem/20007266

Swift SVN r26251
This commit is contained in:
Devin Coughlin
2015-03-18 05:51:01 +00:00
parent 1511d7a15a
commit 02f542c2d0
5 changed files with 34 additions and 6 deletions

View File

@@ -478,6 +478,16 @@ static bool diagAvailability(TypeChecker &TC, const ValueDecl *D,
if (!D)
return false;
// Suppress the error if the reference is inside an
// implicit function. This avoids spurious errors for synthesized
// methods (for example, for nil literal conformances of unavailable
// imported enums) but also erroneously allows some references
// to unavailable symbols (for example, a synthesized call to
// to an unavailable default constructor of a super class).
// We need to handle these properly. rdar://problem/20024980 tracks this.
if (TypeChecker::isInsideImplicitFunction(DC))
return false;
SourceLoc Loc = R.Start;
if (auto Attr = AvailabilityAttr::isUnavailable(D)) {
auto Name = D->getFullName();