@@ -2716,7 +2716,7 @@ static bool isStringNestedType(const ValueDecl *VD, StringRef Typename) {
27162716
27172717static bool hasExposeAttr (const ValueDecl *VD, bool isExtension = false ) {
27182718 if (isa<NominalTypeDecl>(VD) && VD->getModuleContext ()->isStdlibModule ()) {
2719- if (VD == VD->getASTContext ().getStringDecl () && !isExtension )
2719+ if (VD == VD->getASTContext ().getStringDecl ())
27202720 return true ;
27212721 if (VD == VD->getASTContext ().getArrayDecl ())
27222722 return true ;
@@ -2737,47 +2737,24 @@ static bool hasExposeAttr(const ValueDecl *VD, bool isExtension = false) {
27372737 // FIXME: Do not expose 'index' methods as the overloads are conflicting.
27382738 // this should either be prohibited in the stdlib module, or the overloads
27392739 // should be renamed automatically or using the expose attribute.
2740- if (ED->getExtendedNominal () == VD->getASTContext ().getArrayDecl ()) {
2741- if (isa<AbstractFunctionDecl>(VD) &&
2742- !cast<AbstractFunctionDecl>(VD)
2743- ->getName ()
2744- .getBaseName ()
2745- .isSpecial () &&
2746- cast<AbstractFunctionDecl>(VD)
2747- ->getName ()
2748- .getBaseName ()
2749- .getIdentifier ()
2750- .str ()
2751- .contains_insensitive (" index" ))
2752- return false ;
2753- }
2740+ if ((ED->getExtendedNominal () == VD->getASTContext ().getArrayDecl () ||
2741+ ED->getExtendedNominal () == VD->getASTContext ().getStringDecl ()) &&
2742+ (isa<AbstractFunctionDecl>(VD) &&
2743+ !cast<AbstractFunctionDecl>(VD)->getName ().getBaseName ().isSpecial () &&
2744+ cast<AbstractFunctionDecl>(VD)
2745+ ->getName ()
2746+ .getBaseName ()
2747+ .getIdentifier ()
2748+ .str ()
2749+ .contains_insensitive (" index" )))
2750+ return false ;
2751+ // Limit exposition of String constructors as there's overloading conflict.
2752+ // FIXME: resolve it in some other way.
27542753 if (ED->getExtendedNominal () == VD->getASTContext ().getStringDecl ()) {
2755- if (isa<ValueDecl>(VD) &&
2756- !cast<ValueDecl>(VD)->getName ().getBaseName ().isSpecial () &&
2757- cast<ValueDecl>(VD)
2758- ->getName ()
2759- .getBaseName ()
2760- .getIdentifier ()
2761- .str ()
2762- .contains_insensitive (" utf8" ))
2763- return true ;
2764- }
2765- if (isStringNestedType (ED->getExtendedNominal (), " UTF8View" )) {
2766- // Do not expose ambiguous 'index(after:' / 'index(before:' overloads.
2767- if (isa<AbstractFunctionDecl>(VD) &&
2768- cast<AbstractFunctionDecl>(VD)->getParameters ()->size () == 1 &&
2769- !cast<AbstractFunctionDecl>(VD)
2770- ->getName ()
2771- .getBaseName ()
2772- .isSpecial () &&
2773- cast<AbstractFunctionDecl>(VD)
2774- ->getName ()
2775- .getBaseName ()
2776- .getIdentifier ()
2777- .str ()
2778- .contains_insensitive (" index" ))
2754+ if (isa<ConstructorDecl>(VD))
27792755 return false ;
27802756 }
2757+
27812758 return hasExposeAttr (ED->getExtendedNominal (), /* isExtension=*/ true );
27822759 }
27832760 return false ;
0 commit comments