|
21 | 21 | #include "TypeCheckUnsafe.h" |
22 | 22 |
|
23 | 23 | #include "swift/AST/ASTContext.h" |
24 | | -#include "swift/AST/Effects.h" |
25 | | -#include "swift/AST/UnsafeUse.h" |
26 | 24 | #include "swift/AST/DiagnosticsSema.h" |
| 25 | +#include "swift/AST/Effects.h" |
27 | 26 | #include "swift/AST/PackConformance.h" |
28 | 27 | #include "swift/AST/SourceFile.h" |
| 28 | +#include "swift/AST/Types.h" |
| 29 | +#include "swift/AST/UnsafeUse.h" |
29 | 30 |
|
30 | 31 | using namespace swift; |
31 | 32 |
|
@@ -243,19 +244,29 @@ bool swift::enumerateUnsafeUses(ConcreteDeclRef declRef, |
243 | 244 | // If the type of this declaration involves unsafe types, diagnose that. |
244 | 245 | ASTContext &ctx = decl->getASTContext(); |
245 | 246 | auto subs = declRef.getSubstitutions(); |
246 | | - if (!skipTypeCheck) { |
247 | | - auto type = decl->getInterfaceType(); |
248 | | - if (subs) { |
249 | | - if (auto *genericFnType = type->getAs<GenericFunctionType>()) |
250 | | - type = genericFnType->substGenericArgs(subs); |
251 | | - else |
252 | | - type = type.subst(subs); |
253 | | - } |
| 247 | + auto type = decl->getInterfaceType(); |
| 248 | + if (subs) { |
| 249 | + if (auto *genericFnType = type->getAs<GenericFunctionType>()) |
| 250 | + type = genericFnType->substGenericArgs(subs); |
| 251 | + else |
| 252 | + type = type.subst(subs); |
| 253 | + } |
254 | 254 |
|
| 255 | + if (skipTypeCheck) { |
| 256 | + // We check the arguements instead of the funcion type for function calls. |
| 257 | + // On the other hand, we still need to check the return type as we might not |
| 258 | + // have a declRef with the type of the return type. E.g. in |
| 259 | + // `return funcionCall()`. |
| 260 | + if (auto *fnTy = type->getAs<AnyFunctionType>()) |
| 261 | + type = fnTy->getResult(); |
| 262 | + else |
| 263 | + type = Type(); |
| 264 | + } |
| 265 | + if (type) { |
255 | 266 | bool shouldReturnTrue = false; |
256 | 267 | diagnoseUnsafeType(ctx, loc, type, [&](Type unsafeType) { |
257 | 268 | if (fn(UnsafeUse::forReferenceToUnsafe( |
258 | | - decl, isCall && !isa<ParamDecl>(decl), unsafeType, loc))) |
| 269 | + decl, isCall && !isa<ParamDecl>(decl), unsafeType, loc))) |
259 | 270 | shouldReturnTrue = true; |
260 | 271 | }); |
261 | 272 |
|
|
0 commit comments