Skip to content

Commit afd00af

Browse files
authored
Merge pull request #7104 from jrose-apple/3.1-accessor-argument-labels
[Importer] Preserve argument labels even for accessors.
2 parents d7601b6 + 3daa36b commit afd00af

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,7 @@ namespace {
35573557
prop->getSetterMethodDecl() != decl)
35583558
return nullptr;
35593559
type = Impl.importAccessorMethodType(dc, prop, decl,
3560-
isInSystemModule(dc),
3560+
isInSystemModule(dc), importedName,
35613561
&bodyParams.back());
35623562
} else {
35633563
type = Impl.importMethodType(dc, decl, decl->parameters(),

lib/ClangImporter/ImportType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,7 @@ Type ClangImporter::Implementation::importAccessorMethodType(
21412141
const clang::ObjCPropertyDecl *property,
21422142
const clang::ObjCMethodDecl *clangDecl,
21432143
bool isFromSystemModule,
2144+
ImportedName functionName,
21442145
swift::ParameterList **params) {
21452146
// Note: We're using a pointer instead of a reference here to make it clear
21462147
// at the call site that this is an out-parameter.
@@ -2196,13 +2197,14 @@ Type ClangImporter::Implementation::importAccessorMethodType(
21962197
ImportedName fullBodyName = importFullName(param,ImportNameVersion::Swift3);
21972198
Identifier bodyName = fullBodyName.getDeclName().getBaseName();
21982199
SourceLoc nameLoc = importSourceLoc(param->getLocation());
2200+
Identifier argLabel = functionName.getDeclName().getArgumentNames().front();
21992201
auto paramInfo
22002202
= createDeclWithClangNode<ParamDecl>(param, Accessibility::Private,
22012203
/*IsLet*/true,
22022204
/*let loc*/SourceLoc(),
22032205
/*label loc*/SourceLoc(),
2204-
/*argument label*/Identifier(),
2205-
nameLoc, bodyName, propertyTy,
2206+
argLabel, nameLoc, bodyName,
2207+
propertyTy,
22062208
/*dummy DC*/ImportedHeaderUnit);
22072209
paramInfo->setInterfaceType(propertyInterfaceTy);
22082210

lib/ClangImporter/ImporterImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,9 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
995995
/// \param clangDecl The underlying declaration.
996996
/// \param isFromSystemModule Whether to apply special rules that only apply
997997
/// to system APIs.
998+
/// \param importedName How to import the name of the method. This is still
999+
/// important to satisfy the AST verifier, even though the method is an
1000+
/// accessor.
9981001
/// \param[out] params The patterns visible inside the function body.
9991002
///
10001003
/// \returns the imported function type, or null if the type cannot be
@@ -1003,6 +1006,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
10031006
const clang::ObjCPropertyDecl *property,
10041007
const clang::ObjCMethodDecl *clangDecl,
10051008
bool isFromSystemModule,
1009+
importer::ImportedName importedName,
10061010
ParameterList **params);
10071011

10081012
/// \brief Determine whether the given typedef-name is "special", meaning

test/ClangImporter/Inputs/custom-modules/ObjCParseExtras.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,8 @@ typedef SomeCell <NSCopying> *CopyableSomeCell;
172172
- (nullable instancetype)initWithValue:(NSInteger)val error:(NSError **)error;
173173
+ (BOOL)processValueAndReturnError:(NSError **)error;
174174
@end
175+
176+
@interface SelectorSplittingAccessors : NSObject
177+
// Note the custom setter name here; this is important.
178+
@property (setter=takeFooForBar:) BOOL fooForBar;
179+
@end

test/ClangImporter/objc_parse.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func properties(_ b: B) {
134134

135135
// Properties that are Swift keywords
136136
var prot = b.`protocol`
137+
138+
// Properties whose accessors run afoul of selector splitting.
139+
_ = SelectorSplittingAccessors()
137140
}
138141

139142
// Construction.

0 commit comments

Comments
 (0)