Skip to content

Commit e05dbb6

Browse files
committed
AST: Trigger IsFinalRequest when retrieving semantic attributes.
ASTPrinter already had special logic to handle ensuring that `final` is printed when necessary, but we can remove that logic and instead ensure that `IsFinalRequest` runs as part of computing semantic attributes before printing.
1 parent ff371f9 commit e05dbb6

File tree

4 files changed

+5
-14
lines changed

4 files changed

+5
-14
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,20 +1239,6 @@ void PrintAST::printAttributes(const Decl *D) {
12391239

12401240
attrs.print(Printer, Options, D);
12411241

1242-
// Print the implicit 'final' attribute.
1243-
if (auto VD = dyn_cast<ValueDecl>(D)) {
1244-
auto VarD = dyn_cast<VarDecl>(D);
1245-
if (VD->isFinal() &&
1246-
!attrs.hasAttribute<FinalAttr>() &&
1247-
// Don't print a redundant 'final' if printing a 'let' or 'static' decl.
1248-
!(VarD && VarD->isLet()) &&
1249-
getCorrectStaticSpelling(D) != StaticSpellingKind::KeywordStatic &&
1250-
VD->getKind() != DeclKind::Accessor) {
1251-
Printer.printAttrName("final");
1252-
Printer << " ";
1253-
}
1254-
}
1255-
12561242
Options.ExcludeAttrList.resize(originalExcludeAttrCount);
12571243
}
12581244

lib/AST/TypeCheckRequests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,9 @@ DeclAttributes SemanticDeclAttrsRequest::evaluate(Evaluator &evaluator,
20752075
{});
20762076

20772077
// Trigger requests that cause additional semantic attributes to be added.
2078+
if (auto vd = dyn_cast<ValueDecl>(decl)) {
2079+
(void)vd->isFinal();
2080+
}
20782081
if (auto afd = dyn_cast<AbstractFunctionDecl>(decl)) {
20792082
(void)afd->isTransparent();
20802083
} else if (auto asd = dyn_cast<AbstractStorageDecl>(decl)) {

test/Inputs/lazy_typecheck.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct InternalStruct: NoTypecheckProto {
184184
public class PublicClass {
185185
public var publicProperty: Int
186186
public var publicPropertyInferredType = ""
187+
@PublicWrapper public final var publicFinalWrappedProperty: Bool = false
187188

188189
public init(x: Int) {
189190
self.publicProperty = x

test/Inputs/lazy_typecheck_client.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func testPublicClasses() {
5151
let _: Int = c.publicMethod()
5252
let _: Int = c.publicProperty
5353
let _: String = c.publicPropertyInferredType
54+
c.publicFinalWrappedProperty = true
5455
PublicClass.publicClassMethod()
5556

5657
let d = PublicDerivedClass(x: 3)

0 commit comments

Comments
 (0)