@@ -2700,7 +2700,7 @@ static bool isStringNestedType(const ValueDecl *VD, StringRef Typename) {
27002700
27012701static bool hasExposeAttr (const ValueDecl *VD, bool isExtension = false ) {
27022702 if (isa<NominalTypeDecl>(VD) && VD->getModuleContext ()->isStdlibModule ()) {
2703- if (VD == VD->getASTContext ().getStringDecl () && !isExtension )
2703+ if (VD == VD->getASTContext ().getStringDecl ())
27042704 return true ;
27052705 if (VD == VD->getASTContext ().getArrayDecl ())
27062706 return true ;
@@ -2721,47 +2721,24 @@ static bool hasExposeAttr(const ValueDecl *VD, bool isExtension = false) {
27212721 // FIXME: Do not expose 'index' methods as the overloads are conflicting.
27222722 // this should either be prohibited in the stdlib module, or the overloads
27232723 // should be renamed automatically or using the expose attribute.
2724- if (ED->getExtendedNominal () == VD->getASTContext ().getArrayDecl ()) {
2725- if (isa<AbstractFunctionDecl>(VD) &&
2726- !cast<AbstractFunctionDecl>(VD)
2727- ->getName ()
2728- .getBaseName ()
2729- .isSpecial () &&
2730- cast<AbstractFunctionDecl>(VD)
2731- ->getName ()
2732- .getBaseName ()
2733- .getIdentifier ()
2734- .str ()
2735- .contains_insensitive (" index" ))
2736- return false ;
2737- }
2724+ if ((ED->getExtendedNominal () == VD->getASTContext ().getArrayDecl () ||
2725+ ED->getExtendedNominal () == VD->getASTContext ().getStringDecl ()) &&
2726+ (isa<AbstractFunctionDecl>(VD) &&
2727+ !cast<AbstractFunctionDecl>(VD)->getName ().getBaseName ().isSpecial () &&
2728+ cast<AbstractFunctionDecl>(VD)
2729+ ->getName ()
2730+ .getBaseName ()
2731+ .getIdentifier ()
2732+ .str ()
2733+ .contains_insensitive (" index" )))
2734+ return false ;
2735+ // Limit exposition of String constructors as there's overloading conflict.
2736+ // FIXME: resolve it in some other way.
27382737 if (ED->getExtendedNominal () == VD->getASTContext ().getStringDecl ()) {
2739- if (isa<ValueDecl>(VD) &&
2740- !cast<ValueDecl>(VD)->getName ().getBaseName ().isSpecial () &&
2741- cast<ValueDecl>(VD)
2742- ->getName ()
2743- .getBaseName ()
2744- .getIdentifier ()
2745- .str ()
2746- .contains_insensitive (" utf8" ))
2747- return true ;
2748- }
2749- if (isStringNestedType (ED->getExtendedNominal (), " UTF8View" )) {
2750- // Do not expose ambiguous 'index(after:' / 'index(before:' overloads.
2751- if (isa<AbstractFunctionDecl>(VD) &&
2752- cast<AbstractFunctionDecl>(VD)->getParameters ()->size () == 1 &&
2753- !cast<AbstractFunctionDecl>(VD)
2754- ->getName ()
2755- .getBaseName ()
2756- .isSpecial () &&
2757- cast<AbstractFunctionDecl>(VD)
2758- ->getName ()
2759- .getBaseName ()
2760- .getIdentifier ()
2761- .str ()
2762- .contains_insensitive (" index" ))
2738+ if (isa<ConstructorDecl>(VD))
27632739 return false ;
27642740 }
2741+
27652742 return hasExposeAttr (ED->getExtendedNominal (), /* isExtension=*/ true );
27662743 }
27672744 return false ;
0 commit comments