Skip to content

Commit fa4c30e

Browse files
authored
Merge pull request #82051 from slavapestov/fix-rdar127120469-6.2
[6.2] ASTPrinter: Fix printing of let properties inside @objc @implementation extensions
2 parents 7bf1b0a + 2c53876 commit fa4c30e

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,12 +3506,14 @@ void PrintAST::visitPatternBindingDecl(PatternBindingDecl *decl) {
35063506
if (decl->isStatic())
35073507
printStaticKeyword(decl->getCorrectStaticSpelling());
35083508

3509+
bool printAsVar = false;
35093510
if (anyVar) {
3510-
Printer << (anyVar->isSettable(anyVar->getDeclContext()) ? "var " : "let ");
3511-
} else {
3512-
Printer << "let ";
3511+
printAsVar = (anyVar->isSettable(anyVar->getDeclContext()) ||
3512+
isInObjCImpl(anyVar));
35133513
}
35143514

3515+
Printer << (printAsVar ? "var " : "let ");
3516+
35153517
bool isFirst = true;
35163518
for (auto idx : range(decl->getNumPatternEntries())) {
35173519
auto *pattern = decl->getPattern(idx);
@@ -3949,9 +3951,9 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
39493951
// Map all non-let specifiers to 'var'. This is not correct, but
39503952
// SourceKit relies on this for info about parameter decls.
39513953

3952-
Printer.printIntroducerKeyword(
3953-
decl->getIntroducer() == VarDecl::Introducer::Let ? "let" : "var",
3954-
Options, " ");
3954+
bool printAsVar = (decl->getIntroducer() != VarDecl::Introducer::Let ||
3955+
isInObjCImpl(decl));
3956+
Printer.printIntroducerKeyword(printAsVar ? "var" : "let", Options, " ");
39553957
}
39563958
printContextIfNeeded(decl);
39573959
recordDeclLoc(decl,

test/ModuleInterface/Inputs/objc_implementation/objc_implementation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- (nonnull instancetype)init;
66

7+
@property (readonly) int letProperty1;
78
@property (assign) int implProperty;
89

910
- (void)mainMethod:(int)param;

test/ModuleInterface/objc_implementation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ import Foundation
4242
didSet { print(implProperty) }
4343
}
4444

45+
// CHECK-NOT: var letProperty1:
46+
@objc public let letProperty1: Int32
47+
48+
// CHECK-DAG: @nonobjc public var letProperty2: Swift.Int32 { get }
49+
@nonobjc public let letProperty2: Int32
50+
4551
// CHECK-DAG: final public var implProperty2: ObjectiveC.NSObject? { get set }
4652
public final var implProperty2: NSObject?
4753

0 commit comments

Comments
 (0)