diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 93ba8b3e361..eceb9aef095 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -940,6 +940,7 @@ namespace { selfPat->setType(selfVar->getType()); argPatterns.push_back(selfPat); bodyPatterns.push_back(selfPat); + bool hasSelectorStyleSignature; // Import the type that this method will have. auto type = Impl.importFunctionType(decl->getResultType(), @@ -948,6 +949,7 @@ namespace { decl->isVariadic(), argPatterns, bodyPatterns, + &hasSelectorStyleSignature, decl->getSelector()); if (!type) return nullptr; @@ -966,6 +968,9 @@ namespace { /*GenericParams=*/nullptr, type, argPatterns, bodyPatterns, TypeLoc::withoutLoc(resultTy), dc); result->setBodyResultType(resultTy); + + if (hasSelectorStyleSignature) + result->setHasSelectorStyleSignature(); setVarDeclContexts(argPatterns, result); setVarDeclContexts(bodyPatterns, result); @@ -1191,6 +1196,7 @@ namespace { argPatterns.push_back(selfPat); bodyPatterns.push_back(selfPat); + bool hasSelectorStyleSignature; // Import the type that this method will have. auto type = Impl.importFunctionType(objcMethod->getResultType(), @@ -1199,6 +1205,7 @@ namespace { objcMethod->isVariadic(), argPatterns, bodyPatterns, + &hasSelectorStyleSignature, objcMethod->getSelector(), /*isConstructor=*/true); assert(type && "Type has already been successfully converted?"); @@ -1216,6 +1223,7 @@ namespace { VarDecl *selfVar = new (Impl.SwiftContext) VarDecl(SourceLoc(), selfName, selfTy, dc); + selfVar->isImplicit(); // Create the actual constructor. auto result = new (Impl.SwiftContext) ConstructorDecl(name, loc, @@ -1229,6 +1237,9 @@ namespace { result->setIsObjC(true); result->setClangNode(objcMethod); + if (hasSelectorStyleSignature) + result->setHasSelectorStyleSignature(); + selfVar->setDeclContext(result); setVarDeclContexts(argPatterns, result); setVarDeclContexts(bodyPatterns, result); diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index 96b8ba367e9..1b0499a1498 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -598,8 +598,13 @@ Type ClangImporter::Implementation::importFunctionType( bool isVariadic, SmallVectorImpl &argPatterns, SmallVectorImpl &bodyPatterns, + bool *pHasSelectorStyleSignature, clang::Selector selector, bool isConstructor) { + + if (pHasSelectorStyleSignature) + *pHasSelectorStyleSignature = false; + // Cannot import variadic types. if (isVariadic) return Type(); @@ -672,11 +677,13 @@ Type ClangImporter::Implementation::importFunctionType( Pattern *argPattern = bodyPattern; if (bodyName != name) { if (name.empty()) { - argPattern = new (SwiftContext) AnyPattern(SourceLoc()); + argPattern = new (SwiftContext) AnyPattern(SourceLoc(), + /*Implicit=*/true); } else { auto argVar = new (SwiftContext) VarDecl(SourceLoc(), name, swiftParamTy, firstClangModule); + argVar->setImplicit(); argVar->setClangNode(param); argPattern = new (SwiftContext) NamedPattern(argVar); } @@ -684,10 +691,14 @@ Type ClangImporter::Implementation::importFunctionType( argPattern = new (SwiftContext) TypedPattern(argPattern, - TypeLoc::withoutLoc(swiftParamTy)); + TypeLoc::withoutLoc(swiftParamTy), + /*Implicit=*/true); argPattern->setType(swiftParamTy); } argPatternElts.push_back(TuplePatternElt(argPattern)); + + if (argPattern != bodyPattern && pHasSelectorStyleSignature) + *pHasSelectorStyleSignature = true; // Add the tuple elements for the function types. swiftArgParams.push_back(TupleTypeElt(swiftParamTy, name)); @@ -730,7 +741,9 @@ Type ClangImporter::Implementation::importFunctionType( bodyPatternElts, SourceLoc())); bodyPatterns.back()->setType(bodyParamsTy); argPatterns.push_back(TuplePattern::create(SwiftContext, SourceLoc(), - argPatternElts, SourceLoc())); + argPatternElts, SourceLoc(), + false, SourceLoc(), + /*Implicit=*/true)); argPatterns.back()->setType(argParamsTy); // Form the function type. diff --git a/lib/ClangImporter/ImporterImpl.h b/lib/ClangImporter/ImporterImpl.h index 44cab7b3a27..d175f106f82 100644 --- a/lib/ClangImporter/ImporterImpl.h +++ b/lib/ClangImporter/ImporterImpl.h @@ -384,6 +384,8 @@ public: /// \param isVariadic Whether the function is variadic. /// \param argPatterns The externally-visible patterns for the parameters. /// \param bodyPatterns The patterns visible inside the function body. + /// \param pHasSelectorStyleSignature if non-null it accepts a boolean for + /// whether the created arg/body patterns are different (selector-style). /// \param selector The Objective-C method selector to use for the names. /// \param isConstructor Whether we're building a function type for a /// constructor. @@ -395,6 +397,7 @@ public: bool isVariadic, SmallVectorImpl &argPatterns, SmallVectorImpl &bodyPatterns, + bool *pHasSelectorStyleSignature = nullptr, clang::Selector selector = clang::Selector(), bool isConstructor = false); diff --git a/lib/Parse/ParsePattern.cpp b/lib/Parse/ParsePattern.cpp index 1b30c188bf9..5143f72a2f3 100644 --- a/lib/Parse/ParsePattern.cpp +++ b/lib/Parse/ParsePattern.cpp @@ -87,11 +87,13 @@ parseSelectorArgument(Parser &P, assert(ArgPatternRes.isNonNull() && "selector argument did not start with an identifier!"); Pattern *ArgPattern = ArgPatternRes.get(); + ArgPattern->setImplicit(); // Check that a selector name isn't used multiple times, which would // lead to the function type having multiple arguments with the same name. if (NamedPattern *name = dyn_cast(ArgPattern)) { VarDecl *decl = name->getDecl(); + decl->setImplicit(); StringRef id = decl->getName().str(); auto prevName = selectorNames.find(id); if (prevName != selectorNames.end()) { @@ -132,7 +134,8 @@ parseSelectorArgument(Parser &P, recoverFromBadSelectorArgument(P); } - ArgPattern = new (P.Context) TypedPattern(ArgPattern, type.get()); + ArgPattern = new (P.Context) TypedPattern(ArgPattern, type.get(), + /*Implicit=*/true); BodyPattern = new (P.Context) TypedPattern(BodyPattern, type.get()); if (Status.isError()) return Status; @@ -176,9 +179,10 @@ static Pattern *getFirstSelectorPattern(ASTContext &Context, const Pattern *argPattern, SourceLoc loc) { - Pattern *pattern = new (Context) AnyPattern(loc); + Pattern *pattern = new (Context) AnyPattern(loc, /*Implicit=*/true); if (auto typed = dyn_cast(argPattern)) { - pattern = new (Context) TypedPattern(pattern, typed->getTypeLoc()); + pattern = new (Context) TypedPattern(pattern, typed->getTypeLoc(), + /*Implicit=*/true); } return pattern; } @@ -256,7 +260,8 @@ parseSelectorFunctionArguments(Parser &P, } ArgPatterns.push_back( - TuplePattern::create(P.Context, LParenLoc, ArgElts, RParenLoc)); + TuplePattern::create(P.Context, LParenLoc, ArgElts, RParenLoc, + /*hasVarArg=*/false,SourceLoc(), /*Implicit=*/true)); BodyPatterns.push_back( TuplePattern::create(P.Context, LParenLoc, BodyElts, RParenLoc)); return Status;