@@ -1915,6 +1915,26 @@ static void inferProtocolMemberAvailability(ClangImporter::Implementation &impl,
1915
1915
applyAvailableAttribute (valueDecl, requiredRange, C);
1916
1916
}
1917
1917
1918
+ // / Synthesizer callback for the error domain property getter.
1919
+ static std::pair<BraceStmt *, bool >
1920
+ synthesizeErrorDomainGetterBody (AbstractFunctionDecl *afd, void *context) {
1921
+ auto getterDecl = cast<AccessorDecl>(afd);
1922
+ ASTContext &ctx = getterDecl->getASTContext ();
1923
+
1924
+ auto contextData =
1925
+ llvm::PointerIntPair<ValueDecl *, 1 , bool >::getFromOpaqueValue (context);
1926
+ auto swiftValueDecl = contextData.getPointer ();
1927
+ bool isImplicit = contextData.getInt ();
1928
+ DeclRefExpr *domainDeclRef = new (ctx)
1929
+ DeclRefExpr (ConcreteDeclRef (swiftValueDecl), {}, isImplicit);
1930
+ domainDeclRef->setType (
1931
+ getterDecl->mapTypeIntoContext (swiftValueDecl->getInterfaceType ()));
1932
+
1933
+ auto ret = new (ctx) ReturnStmt (SourceLoc (), domainDeclRef);
1934
+ return { BraceStmt::create (ctx, SourceLoc (), {ret}, SourceLoc (), isImplicit),
1935
+ /* isTypeChecked=*/ true };
1936
+ }
1937
+
1918
1938
// / Add a domain error member, as required by conformance to
1919
1939
// / _BridgedStoredNSError.
1920
1940
// / \returns true on success, false on failure
@@ -1942,10 +1962,6 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
1942
1962
errorDomainPropertyDecl->setValidationToChecked ();
1943
1963
errorDomainPropertyDecl->setAccess (AccessLevel::Public);
1944
1964
1945
- DeclRefExpr *domainDeclRef = new (C)
1946
- DeclRefExpr (ConcreteDeclRef (swiftValueDecl), {}, isImplicit);
1947
- domainDeclRef->setType (swiftValueDecl->getInterfaceType ());
1948
-
1949
1965
auto *params = ParameterList::createEmpty (C);
1950
1966
1951
1967
auto getterDecl = AccessorDecl::create (C,
@@ -1974,10 +1990,10 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
1974
1990
getterDecl->setStatic (isStatic);
1975
1991
getterDecl->setAccess (AccessLevel::Public);
1976
1992
1977
- auto ret = new (C) ReturnStmt ( SourceLoc (), domainDeclRef);
1978
- getterDecl-> setBody (
1979
- BraceStmt::create (C, SourceLoc (), {ret}, SourceLoc (), isImplicit) ,
1980
- AbstractFunctionDecl::BodyKind::TypeChecked );
1993
+ llvm::PointerIntPair<ValueDecl *, 1 , bool > contextData (swiftValueDecl,
1994
+ isImplicit);
1995
+ getterDecl-> setBodySynthesizer (synthesizeErrorDomainGetterBody ,
1996
+ contextData. getOpaqueValue () );
1981
1997
1982
1998
return true ;
1983
1999
}
0 commit comments