@@ -733,6 +733,53 @@ static void recordShadowedDeclsAfterTypeMatch(
733
733
}
734
734
}
735
735
736
+ // / Return an extended info for a function types that removes the use of
737
+ // / the thrown error type, if present.
738
+ // /
739
+ // / Returns \c None when no adjustment is needed.
740
+ static std::optional<ASTExtInfo>
741
+ extInfoRemovingThrownError (AnyFunctionType *fnType) {
742
+ if (!fnType->hasExtInfo ())
743
+ return std::nullopt;
744
+
745
+ auto extInfo = fnType->getExtInfo ();
746
+ if (!extInfo.isThrowing () || !extInfo.getThrownError ())
747
+ return std::nullopt;
748
+
749
+ return extInfo.withThrows (true , Type ());
750
+ }
751
+
752
+ // / Remove the thrown error type.
753
+ static CanType removeThrownError (Type type) {
754
+ ASTContext &ctx = type->getASTContext ();
755
+
756
+ return type.transformRec ([](TypeBase *type) -> std::optional<Type> {
757
+ if (auto funcTy = dyn_cast<FunctionType>(type)) {
758
+ if (auto newExtInfo = extInfoRemovingThrownError (funcTy)) {
759
+ return FunctionType::get (
760
+ funcTy->getParams (), funcTy->getResult (), *newExtInfo)
761
+ ->getCanonicalType ();
762
+ }
763
+
764
+ return std::nullopt;
765
+ }
766
+
767
+ if (auto genericFuncTy = dyn_cast<GenericFunctionType>(type)) {
768
+ if (auto newExtInfo = extInfoRemovingThrownError (genericFuncTy)) {
769
+ return GenericFunctionType::get (
770
+ genericFuncTy->getGenericSignature (),
771
+ genericFuncTy->getParams (), genericFuncTy->getResult (),
772
+ *newExtInfo)
773
+ ->getCanonicalType ();
774
+ }
775
+
776
+ return std::nullopt;
777
+ }
778
+
779
+ return std::nullopt;
780
+ })->getCanonicalType ();
781
+ }
782
+
736
783
// / Given a set of declarations whose names and generic signatures have matched,
737
784
// / figure out which of these declarations have been shadowed by others.
738
785
static void recordShadowedDeclsAfterSignatureMatch (
@@ -757,7 +804,7 @@ static void recordShadowedDeclsAfterSignatureMatch(
757
804
if (auto asd = dyn_cast<AbstractStorageDecl>(decl))
758
805
type = asd->getOverloadSignatureType ();
759
806
else
760
- type = decl->getInterfaceType ()->getCanonicalType ();
807
+ type = removeThrownError ( decl->getInterfaceType ()->getCanonicalType () );
761
808
762
809
// Record this declaration based on its signature.
763
810
auto &known = collisions[type];
0 commit comments