@@ -4132,35 +4132,49 @@ bool ClangImporter::Implementation::lookupValue(SwiftLookupTable &table,
41324132 bool declFound = false ;
41334133
41344134 if (name.isOperator ()) {
4135-
4136- auto findAndConsumeBaseNameFromTable = [this , &table, &consumer, &declFound,
4137- &name](DeclBaseName declBaseName) {
4138- for (auto entry : table.lookupMemberOperators (declBaseName)) {
4139- if (isVisibleClangEntry (entry)) {
4140- if (auto decl = dyn_cast_or_null<ValueDecl>(
4141- importDeclReal (entry->getMostRecentDecl (), CurrentVersion))) {
4142- consumer.foundDecl (decl, DeclVisibilityKind::VisibleAtTopLevel);
4143- declFound = true ;
4144- for (auto alternate : getAlternateDecls (decl)) {
4145- if (alternate->getName ().matchesRef (name)) {
4146- consumer.foundDecl (alternate, DeclVisibilityKind::DynamicLookup,
4147- DynamicLookupInfo::AnyObject);
4148- }
4149- }
4150- }
4135+ for (auto entry : table.lookupMemberOperators (name.getBaseName ())) {
4136+ if (isVisibleClangEntry (entry)) {
4137+ if (auto decl = dyn_cast_or_null<ValueDecl>(
4138+ importDeclReal (entry->getMostRecentDecl (), CurrentVersion))) {
4139+ consumer.foundDecl (decl, DeclVisibilityKind::VisibleAtTopLevel);
4140+ declFound = true ;
41514141 }
41524142 }
4153- };
4154-
4155- findAndConsumeBaseNameFromTable (name.getBaseName ());
4143+ }
41564144
41574145 // If CXXInterop is enabled we need to check the modified operator name as
41584146 // well
41594147 if (SwiftContext.LangOpts .EnableCXXInterop ) {
4160- auto declBaseName = DeclBaseName (SwiftContext.getIdentifier (
4148+ auto funcBaseName = DeclBaseName (SwiftContext.getIdentifier (
41614149 " __operator" + getOperatorNameForToken (
41624150 name.getBaseName ().getIdentifier ().str ().str ())));
4163- findAndConsumeBaseNameFromTable (declBaseName);
4151+ for (auto entry : table.lookupMemberOperators (funcBaseName)) {
4152+ if (isVisibleClangEntry (entry)) {
4153+ if (auto func = dyn_cast_or_null<ValueDecl>(
4154+ importDeclReal (entry->getMostRecentDecl (), CurrentVersion))) {
4155+ // `func` is not an operator, it is a regular function which has a
4156+ // name that starts with `__operator`. We were asked for a
4157+ // corresponding synthesized Swift operator, so let's retrieve it.
4158+
4159+ // The synthesized Swift operator was added as an alternative decl
4160+ // for `func`.
4161+ auto alternateDecls = getAlternateDecls (func);
4162+ // Did we actually synthesize an operator for `func`?
4163+ if (alternateDecls.empty ())
4164+ continue ;
4165+ // If we did, then we should have only synthesized one.
4166+ assert (alternateDecls.size () == 1 &&
4167+ " expected only the synthesized operator as an alternative" );
4168+
4169+ auto synthesizedOperator = alternateDecls.front ();
4170+ assert (synthesizedOperator->isOperator () &&
4171+ " expected the alternative to be a synthesized operator" );
4172+
4173+ consumer.foundDecl (synthesizedOperator,
4174+ DeclVisibilityKind::VisibleAtTopLevel);
4175+ }
4176+ }
4177+ }
41644178 }
41654179 }
41664180
0 commit comments