mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
ASTPrinter: Fix printing of let properties inside @objc @implementation extensions
A `let` here is really just a `var` with a `{ get }`.
Fixes rdar://problem/127120469.
This commit is contained in:
@@ -3508,12 +3508,14 @@ void PrintAST::visitPatternBindingDecl(PatternBindingDecl *decl) {
|
||||
if (decl->isStatic())
|
||||
printStaticKeyword(decl->getCorrectStaticSpelling());
|
||||
|
||||
bool printAsVar = false;
|
||||
if (anyVar) {
|
||||
Printer << (anyVar->isSettable(anyVar->getDeclContext()) ? "var " : "let ");
|
||||
} else {
|
||||
Printer << "let ";
|
||||
printAsVar = (anyVar->isSettable(anyVar->getDeclContext()) ||
|
||||
isInObjCImpl(anyVar));
|
||||
}
|
||||
|
||||
Printer << (printAsVar ? "var " : "let ");
|
||||
|
||||
bool isFirst = true;
|
||||
for (auto idx : range(decl->getNumPatternEntries())) {
|
||||
auto *pattern = decl->getPattern(idx);
|
||||
@@ -3958,9 +3960,9 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
|
||||
// Map all non-let specifiers to 'var'. This is not correct, but
|
||||
// SourceKit relies on this for info about parameter decls.
|
||||
|
||||
Printer.printIntroducerKeyword(
|
||||
introducer == VarDecl::Introducer::Let ? "let" : "var",
|
||||
Options, " ");
|
||||
bool printAsVar = (introducer != VarDecl::Introducer::Let ||
|
||||
isInObjCImpl(decl));
|
||||
Printer.printIntroducerKeyword(printAsVar ? "var" : "let", Options, " ");
|
||||
}
|
||||
printContextIfNeeded(decl);
|
||||
recordDeclLoc(decl,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
- (nonnull instancetype)init;
|
||||
|
||||
@property (readonly) int letProperty1;
|
||||
@property (assign) int implProperty;
|
||||
|
||||
- (void)mainMethod:(int)param;
|
||||
|
||||
@@ -42,6 +42,12 @@ import Foundation
|
||||
didSet { print(implProperty) }
|
||||
}
|
||||
|
||||
// CHECK-NOT: var letProperty1:
|
||||
@objc public let letProperty1: Int32
|
||||
|
||||
// CHECK-DAG: @nonobjc public var letProperty2: Swift.Int32 { get }
|
||||
@nonobjc public let letProperty2: Int32
|
||||
|
||||
// CHECK-DAG: final public var implProperty2: ObjectiveC.NSObject? { get set }
|
||||
public final var implProperty2: NSObject?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user