@@ -838,16 +838,21 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
838
838
auto selfDecl = getterDecl->getImplicitSelfDecl ();
839
839
Expr *expr = new (C) DeclRefExpr (selfDecl, DeclNameLoc (),
840
840
/* implicit*/ true );
841
+ expr->setType (selfDecl->getInterfaceType ());
842
+
841
843
expr = new (C) MemberRefExpr (expr, SourceLoc (), anonymousFieldDecl,
842
844
DeclNameLoc (), /* implicit*/ true );
845
+ expr->setType (anonymousFieldDecl->getInterfaceType ());
843
846
844
847
expr = new (C) MemberRefExpr (expr, SourceLoc (), anonymousInnerFieldDecl,
845
848
DeclNameLoc (), /* implicit*/ true );
849
+ expr->setType (anonymousInnerFieldDecl->getInterfaceType ());
846
850
847
851
auto ret = new (C) ReturnStmt (SourceLoc (), expr);
848
852
auto body = BraceStmt::create (C, SourceLoc (), ASTNode (ret), SourceLoc (),
849
853
/* implicit*/ true );
850
854
getterDecl->setBody (body);
855
+ getterDecl->setBodyTypeCheckedIfPresent ();
851
856
getterDecl->getAttrs ().add (new (C) TransparentAttr (/* implicit*/ true ));
852
857
Impl.registerExternalDecl (getterDecl);
853
858
}
@@ -857,22 +862,29 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
857
862
auto selfDecl = setterDecl->getImplicitSelfDecl ();
858
863
Expr *lhs = new (C) DeclRefExpr (selfDecl, DeclNameLoc (),
859
864
/* implicit*/ true );
865
+ lhs->setType (LValueType::get (selfDecl->getInterfaceType ()));
866
+
860
867
lhs = new (C) MemberRefExpr (lhs, SourceLoc (), anonymousFieldDecl,
861
- DeclNameLoc (), /* implicit*/ true );
868
+ DeclNameLoc (), /* implicit*/ true );
869
+ lhs->setType (LValueType::get (anonymousFieldDecl->getInterfaceType ()));
862
870
863
871
lhs = new (C) MemberRefExpr (lhs, SourceLoc (), anonymousInnerFieldDecl,
864
872
DeclNameLoc (), /* implicit*/ true );
873
+ lhs->setType (LValueType::get (anonymousInnerFieldDecl->getInterfaceType ()));
865
874
866
875
auto newValueDecl = setterDecl->getParameters ()->get (0 );
867
876
868
877
auto rhs = new (C) DeclRefExpr (newValueDecl, DeclNameLoc (),
869
878
/* implicit*/ true );
879
+ rhs->setType (newValueDecl->getInterfaceType ());
870
880
871
881
auto assign = new (C) AssignExpr (lhs, SourceLoc (), rhs, /* implicit*/ true );
882
+ assign->setType (TupleType::getEmpty (C));
872
883
873
884
auto body = BraceStmt::create (C, SourceLoc (), { assign }, SourceLoc (),
874
885
/* implicit*/ true );
875
886
setterDecl->setBody (body);
887
+ setterDecl->setBodyTypeCheckedIfPresent ();
876
888
setterDecl->getAttrs ().add (new (C) TransparentAttr (/* implicit*/ true ));
877
889
Impl.registerExternalDecl (setterDecl);
878
890
}
@@ -922,18 +934,35 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
922
934
923
935
auto selfRef = new (C) DeclRefExpr (selfDecl, DeclNameLoc (),
924
936
/* implicit*/ true );
937
+ selfRef->setType (selfDecl->getInterfaceType ());
938
+
925
939
auto reinterpretCast = cast<FuncDecl>(getBuiltinValueDecl (
926
940
C, C.getIdentifier (" reinterpretCast" )));
927
- auto reinterpretCastRef
928
- = new (C) DeclRefExpr (reinterpretCast, DeclNameLoc (), /* implicit*/ true );
929
- auto reinterpreted = CallExpr::createImplicit (C, reinterpretCastRef,
941
+
942
+ ConcreteDeclRef reinterpretCastRef (
943
+ reinterpretCast,
944
+ SubstitutionMap::get (reinterpretCast->getGenericSignature (),
945
+ {selfDecl->getInterfaceType (),
946
+ importedFieldDecl->getInterfaceType ()},
947
+ ArrayRef<ProtocolConformanceRef>()));
948
+ auto reinterpretCastRefExpr
949
+ = new (C) DeclRefExpr (reinterpretCastRef, DeclNameLoc (),
950
+ /* implicit*/ true );
951
+ reinterpretCastRefExpr->setType (
952
+ FunctionType::get (
953
+ AnyFunctionType::Param (selfDecl->getInterfaceType ()),
954
+ importedFieldDecl->getInterfaceType ()));
955
+
956
+ auto reinterpreted = CallExpr::createImplicit (C, reinterpretCastRefExpr,
930
957
{ selfRef },
931
958
{ Identifier () });
959
+ reinterpreted->setType (importedFieldDecl->getInterfaceType ());
932
960
reinterpreted->setThrows (false );
933
961
auto ret = new (C) ReturnStmt (SourceLoc (), reinterpreted);
934
962
auto body = BraceStmt::create (C, SourceLoc (), ASTNode (ret), SourceLoc (),
935
963
/* implicit*/ true );
936
964
getterDecl->setBody (body);
965
+ getterDecl->setBodyTypeCheckedIfPresent ();
937
966
getterDecl->getAttrs ().add (new (C) TransparentAttr (/* implicit*/ true ));
938
967
Impl.registerExternalDecl (getterDecl);
939
968
}
@@ -944,30 +973,56 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
944
973
945
974
auto inoutSelfRef = new (C) DeclRefExpr (inoutSelfDecl, DeclNameLoc (),
946
975
/* implicit*/ true );
976
+ inoutSelfRef->setType (LValueType::get (inoutSelfDecl->getInterfaceType ()));
947
977
auto inoutSelf = new (C) InOutExpr (SourceLoc (), inoutSelfRef,
948
978
importedUnionDecl->getDeclaredType (), /* implicit*/ true );
979
+ inoutSelf->setType (InOutType::get (inoutSelfDecl->getInterfaceType ()));
949
980
950
981
auto newValueDecl = setterDecl->getParameters ()->get (0 );
951
982
952
983
auto newValueRef = new (C) DeclRefExpr (newValueDecl, DeclNameLoc (),
953
984
/* implicit*/ true );
985
+ newValueRef->setType (newValueDecl->getInterfaceType ());
986
+
954
987
auto addressofFn = cast<FuncDecl>(getBuiltinValueDecl (
955
988
C, C.getIdentifier (" addressof" )));
956
- auto addressofFnRef
957
- = new (C) DeclRefExpr (addressofFn, DeclNameLoc (), /* implicit*/ true );
958
- auto selfPointer = CallExpr::createImplicit (C, addressofFnRef,
989
+ ConcreteDeclRef addressofFnRef (addressofFn,
990
+ SubstitutionMap::get (addressofFn->getGenericSignature (),
991
+ {inoutSelfDecl->getInterfaceType ()},
992
+ ArrayRef<ProtocolConformanceRef>()));
993
+ auto addressofFnRefExpr
994
+ = new (C) DeclRefExpr (addressofFnRef, DeclNameLoc (), /* implicit*/ true );
995
+ addressofFnRefExpr->setType (
996
+ FunctionType::get (AnyFunctionType::Param (inoutSelfDecl->getInterfaceType (),
997
+ Identifier (),
998
+ ParameterTypeFlags ().withInOut (true )),
999
+ C.TheRawPointerType ));
1000
+ auto selfPointer = CallExpr::createImplicit (C, addressofFnRefExpr,
959
1001
{ inoutSelf },
960
1002
{ Identifier () });
1003
+ selfPointer->setType (C.TheRawPointerType );
1004
+
961
1005
auto initializeFn = cast<FuncDecl>(getBuiltinValueDecl (
962
1006
C, C.getIdentifier (" initialize" )));
963
- auto initializeFnRef
964
- = new (C) DeclRefExpr (initializeFn, DeclNameLoc (), /* implicit*/ true );
965
- auto initialize = CallExpr::createImplicit (C, initializeFnRef,
1007
+ ConcreteDeclRef initializeFnRef (initializeFn,
1008
+ SubstitutionMap::get (initializeFn->getGenericSignature (),
1009
+ {newValueDecl->getInterfaceType ()},
1010
+ ArrayRef<ProtocolConformanceRef>()));
1011
+ auto initializeFnRefExpr
1012
+ = new (C) DeclRefExpr (initializeFnRef, DeclNameLoc (), /* implicit*/ true );
1013
+ initializeFnRefExpr->setType (
1014
+ FunctionType::get ({AnyFunctionType::Param (newValueDecl->getInterfaceType ()),
1015
+ AnyFunctionType::Param (C.TheRawPointerType )},
1016
+ TupleType::getEmpty (C)));
1017
+ auto initialize = CallExpr::createImplicit (C, initializeFnRefExpr,
966
1018
{ newValueRef, selfPointer },
967
1019
{ Identifier (), Identifier () });
1020
+ initialize->setType (TupleType::getEmpty (C));
1021
+
968
1022
auto body = BraceStmt::create (C, SourceLoc (), { initialize }, SourceLoc (),
969
1023
/* implicit*/ true );
970
1024
setterDecl->setBody (body);
1025
+ setterDecl->setBodyTypeCheckedIfPresent ();
971
1026
setterDecl->getAttrs ().add (new (C) TransparentAttr (/* implicit*/ true ));
972
1027
Impl.registerExternalDecl (setterDecl);
973
1028
}
@@ -1833,6 +1888,8 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
1833
1888
1834
1889
DeclRefExpr *domainDeclRef = new (C)
1835
1890
DeclRefExpr (ConcreteDeclRef (swiftValueDecl), {}, isImplicit);
1891
+ domainDeclRef->setType (swiftValueDecl->getInterfaceType ());
1892
+
1836
1893
auto *params = ParameterList::createEmpty (C);
1837
1894
1838
1895
auto getterDecl = AccessorDecl::create (C,
@@ -1864,6 +1921,8 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
1864
1921
auto ret = new (C) ReturnStmt (SourceLoc (), domainDeclRef);
1865
1922
getterDecl->setBody (
1866
1923
BraceStmt::create (C, SourceLoc (), {ret}, SourceLoc (), isImplicit));
1924
+ getterDecl->setBodyTypeCheckedIfPresent ();
1925
+
1867
1926
importer.registerExternalDecl (getterDecl);
1868
1927
return true ;
1869
1928
}
0 commit comments