@@ -1245,12 +1245,14 @@ static void validatePatternBindingEntries(TypeChecker &tc,
1245
1245
1246
1246
void swift::makeFinal (ASTContext &ctx, ValueDecl *D) {
1247
1247
if (D && !D->isFinal ()) {
1248
+ assert (!D->isDynamic ());
1248
1249
D->getAttrs ().add (new (ctx) FinalAttr (/* IsImplicit=*/ true ));
1249
1250
}
1250
1251
}
1251
1252
1252
1253
void swift::makeDynamic (ASTContext &ctx, ValueDecl *D) {
1253
1254
if (D && !D->isDynamic ()) {
1255
+ assert (!D->isFinal ());
1254
1256
D->getAttrs ().add (new (ctx) DynamicAttr (/* IsImplicit=*/ true ));
1255
1257
}
1256
1258
}
@@ -2556,15 +2558,29 @@ static void inferDynamic(ASTContext &ctx, ValueDecl *D) {
2556
2558
2557
2559
// Variables declared with 'let' cannot be 'dynamic'.
2558
2560
if (auto VD = dyn_cast<VarDecl>(D)) {
2559
- if (VD->isLet () && !isNSManaged) return ;
2561
+ auto staticSpelling = VD->getParentPatternBinding ()->getStaticSpelling ();
2562
+
2563
+ // The presence of 'static' bocks the inference of 'dynamic'.
2564
+ if (VD->isStatic () && staticSpelling == StaticSpellingKind::KeywordStatic)
2565
+ return ;
2566
+
2567
+ if (VD->isLet () && !isNSManaged)
2568
+ return ;
2560
2569
}
2561
2570
2562
2571
// Accessors should not infer 'dynamic' on their own; they can get it from
2563
2572
// their storage decls.
2564
- if (auto FD = dyn_cast<FuncDecl>(D))
2573
+ if (auto FD = dyn_cast<FuncDecl>(D)) {
2565
2574
if (FD->isAccessor ())
2566
2575
return ;
2567
2576
2577
+ auto staticSpelling = FD->getStaticSpelling ();
2578
+
2579
+ // The presence of 'static' bocks the inference of 'dynamic'.
2580
+ if (FD->isStatic () && staticSpelling == StaticSpellingKind::KeywordStatic)
2581
+ return ;
2582
+ }
2583
+
2568
2584
// The presence of 'final' on a class prevents 'dynamic'.
2569
2585
auto classDecl = D->getDeclContext ()->getAsClassOrClassExtensionContext ();
2570
2586
if (!classDecl) return ;
@@ -5176,8 +5192,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
5176
5192
5177
5193
// If the storage is dynamic or final, propagate to this accessor.
5178
5194
if (isObjC &&
5179
- storage->isDynamic () &&
5180
- !storage->isFinal ())
5195
+ storage->isDynamic ())
5181
5196
makeDynamic (TC.Context , FD);
5182
5197
5183
5198
if (storage->isFinal ())
0 commit comments