Skip to content

[Importer] Preserve argument labels even for accessors. #7104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3557,7 +3557,7 @@ namespace {
prop->getSetterMethodDecl() != decl)
return nullptr;
type = Impl.importAccessorMethodType(dc, prop, decl,
isInSystemModule(dc),
isInSystemModule(dc), importedName,
&bodyParams.back());
} else {
type = Impl.importMethodType(dc, decl, decl->parameters(),
Expand Down
6 changes: 4 additions & 2 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,7 @@ Type ClangImporter::Implementation::importAccessorMethodType(
const clang::ObjCPropertyDecl *property,
const clang::ObjCMethodDecl *clangDecl,
bool isFromSystemModule,
ImportedName functionName,
swift::ParameterList **params) {
// Note: We're using a pointer instead of a reference here to make it clear
// at the call site that this is an out-parameter.
Expand Down Expand Up @@ -2196,13 +2197,14 @@ Type ClangImporter::Implementation::importAccessorMethodType(
ImportedName fullBodyName = importFullName(param,ImportNameVersion::Swift3);
Identifier bodyName = fullBodyName.getDeclName().getBaseName();
SourceLoc nameLoc = importSourceLoc(param->getLocation());
Identifier argLabel = functionName.getDeclName().getArgumentNames().front();
auto paramInfo
= createDeclWithClangNode<ParamDecl>(param, Accessibility::Private,
/*IsLet*/true,
/*let loc*/SourceLoc(),
/*label loc*/SourceLoc(),
/*argument label*/Identifier(),
nameLoc, bodyName, propertyTy,
argLabel, nameLoc, bodyName,
propertyTy,
/*dummy DC*/ImportedHeaderUnit);
paramInfo->setInterfaceType(propertyInterfaceTy);

Expand Down
4 changes: 4 additions & 0 deletions lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
/// \param clangDecl The underlying declaration.
/// \param isFromSystemModule Whether to apply special rules that only apply
/// to system APIs.
/// \param importedName How to import the name of the method. This is still
/// important to satisfy the AST verifier, even though the method is an
/// accessor.
/// \param[out] params The patterns visible inside the function body.
///
/// \returns the imported function type, or null if the type cannot be
Expand All @@ -1003,6 +1006,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
const clang::ObjCPropertyDecl *property,
const clang::ObjCMethodDecl *clangDecl,
bool isFromSystemModule,
importer::ImportedName importedName,
ParameterList **params);

/// \brief Determine whether the given typedef-name is "special", meaning
Expand Down
5 changes: 5 additions & 0 deletions test/ClangImporter/Inputs/custom-modules/ObjCParseExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,8 @@ typedef SomeCell <NSCopying> *CopyableSomeCell;
- (nullable instancetype)initWithValue:(NSInteger)val error:(NSError **)error;
+ (BOOL)processValueAndReturnError:(NSError **)error;
@end

@interface SelectorSplittingAccessors : NSObject
// Note the custom setter name here; this is important.
@property (setter=takeFooForBar:) BOOL fooForBar;
@end
3 changes: 3 additions & 0 deletions test/ClangImporter/objc_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func properties(_ b: B) {

// Properties that are Swift keywords
var prot = b.`protocol`

// Properties whose accessors run afoul of selector splitting.
_ = SelectorSplittingAccessors()
}

// Construction.
Expand Down