|
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 |
|
@@ -240,19 +241,29 @@ bool swift::enumerateUnsafeUses(ConcreteDeclRef declRef,
|
240 | 241 | // If the type of this declaration involves unsafe types, diagnose that.
|
241 | 242 | ASTContext &ctx = decl->getASTContext();
|
242 | 243 | auto subs = declRef.getSubstitutions();
|
243 |
| - if (!skipTypeCheck) { |
244 |
| - auto type = decl->getInterfaceType(); |
245 |
| - if (subs) { |
246 |
| - if (auto *genericFnType = type->getAs<GenericFunctionType>()) |
247 |
| - type = genericFnType->substGenericArgs(subs); |
248 |
| - else |
249 |
| - type = type.subst(subs); |
250 |
| - } |
| 244 | + auto type = decl->getInterfaceType(); |
| 245 | + if (subs) { |
| 246 | + if (auto *genericFnType = type->getAs<GenericFunctionType>()) |
| 247 | + type = genericFnType->substGenericArgs(subs); |
| 248 | + else |
| 249 | + type = type.subst(subs); |
| 250 | + } |
251 | 251 |
|
| 252 | + if (skipTypeCheck) { |
| 253 | + // We check the arguements instead of the funcion type for function calls. |
| 254 | + // On the other hand, we still need to check the return type as we might not |
| 255 | + // have a declRef with the type of the return type. E.g. in |
| 256 | + // `return funcionCall()`. |
| 257 | + if (auto *fnTy = type->getAs<AnyFunctionType>()) |
| 258 | + type = fnTy->getResult(); |
| 259 | + else |
| 260 | + type = Type(); |
| 261 | + } |
| 262 | + if (type) { |
252 | 263 | bool shouldReturnTrue = false;
|
253 | 264 | diagnoseUnsafeType(ctx, loc, type, [&](Type unsafeType) {
|
254 | 265 | if (fn(UnsafeUse::forReferenceToUnsafe(
|
255 |
| - decl, isCall && !isa<ParamDecl>(decl), unsafeType, loc))) |
| 266 | + decl, isCall && !isa<ParamDecl>(decl), unsafeType, loc))) |
256 | 267 | shouldReturnTrue = true;
|
257 | 268 | });
|
258 | 269 |
|
|
0 commit comments