|
18 | 18 |
|
19 | 19 | #include "MiscDiagnostics.h" |
20 | 20 | #include "TypeChecker.h" |
| 21 | +#include "TypeCheckAvailability.h" |
21 | 22 | #include "swift/AST/ASTVisitor.h" |
22 | 23 | #include "swift/AST/ASTWalker.h" |
23 | 24 | #include "swift/AST/DiagnosticSuppression.h" |
@@ -272,12 +273,14 @@ class FunctionSyntacticDiagnosticWalker : public ASTWalker { |
272 | 273 | } // end anonymous namespace |
273 | 274 |
|
274 | 275 | void constraints::performSyntacticDiagnosticsForTarget( |
275 | | - const SolutionApplicationTarget &target, bool isExprStmt) { |
| 276 | + const SolutionApplicationTarget &target, |
| 277 | + bool isExprStmt, bool disableExprAvailabiltyChecking) { |
276 | 278 | auto *dc = target.getDeclContext(); |
277 | 279 | switch (target.kind) { |
278 | 280 | case SolutionApplicationTarget::Kind::expression: { |
279 | 281 | // First emit diagnostics for the main expression. |
280 | | - performSyntacticExprDiagnostics(target.getAsExpr(), dc, isExprStmt); |
| 282 | + performSyntacticExprDiagnostics(target.getAsExpr(), dc, |
| 283 | + isExprStmt, disableExprAvailabiltyChecking); |
281 | 284 |
|
282 | 285 | // If this is a for-in statement, we also need to check the where clause if |
283 | 286 | // present. |
@@ -400,7 +403,9 @@ TypeChecker::typeCheckExpression( |
400 | 403 | // expression now. |
401 | 404 | if (!cs.shouldSuppressDiagnostics()) { |
402 | 405 | bool isExprStmt = options.contains(TypeCheckExprFlags::IsExprStmt); |
403 | | - performSyntacticDiagnosticsForTarget(*resultTarget, isExprStmt); |
| 406 | + performSyntacticDiagnosticsForTarget( |
| 407 | + *resultTarget, isExprStmt, |
| 408 | + options.contains(TypeCheckExprFlags::DisableExprAvailabilityChecking)); |
404 | 409 | } |
405 | 410 |
|
406 | 411 | resultTarget->setExpr(result); |
@@ -428,8 +433,19 @@ bool TypeChecker::typeCheckBinding( |
428 | 433 | initializer, DC, patternType, pattern, |
429 | 434 | /*bindPatternVarsOneWay=*/false); |
430 | 435 |
|
| 436 | + auto options = TypeCheckExprOptions(); |
| 437 | + if (DC->getASTContext().LangOpts.CheckAPIAvailabilityOnly && |
| 438 | + PBD && !DC->getAsDecl()) { |
| 439 | + // Skip checking the initializer for non-public decls when |
| 440 | + // checking the API only. |
| 441 | + auto VD = PBD->getAnchoringVarDecl(0); |
| 442 | + if (!swift::shouldCheckAvailability(VD)) { |
| 443 | + options |= TypeCheckExprFlags::DisableExprAvailabilityChecking; |
| 444 | + } |
| 445 | + } |
| 446 | + |
431 | 447 | // Type-check the initializer. |
432 | | - auto resultTarget = typeCheckExpression(target); |
| 448 | + auto resultTarget = typeCheckExpression(target, options); |
433 | 449 |
|
434 | 450 | if (resultTarget) { |
435 | 451 | initializer = resultTarget->getAsExpr(); |
|
0 commit comments