Skip to content

Commit cbb9e15

Browse files
committed
Restore sema code that bans consuming from being applied to no escape functions.
1 parent 07677c2 commit cbb9e15

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4288,7 +4288,31 @@ TypeResolver::resolveOwnershipTypeRepr(OwnershipTypeRepr *repr,
42884288
// Remember that we've seen an ownership specifier for this base type.
42894289
options |= TypeResolutionFlags::HasOwnership;
42904290

4291-
return resolveType(repr->getBase(), options);
4291+
auto result = resolveType(repr->getBase(), options);
4292+
if (result->hasError())
4293+
return result;
4294+
4295+
// Check for illegal combinations of ownership specifiers and types.
4296+
switch (ownershipRepr->getSpecifier()) {
4297+
case ParamSpecifier::Default:
4298+
case ParamSpecifier::InOut:
4299+
case ParamSpecifier::LegacyShared:
4300+
case ParamSpecifier::LegacyOwned:
4301+
case ParamSpecifier::Borrowing:
4302+
break;
4303+
case ParamSpecifier::Consuming:
4304+
if (auto *fnTy = result->getAs<FunctionType>()) {
4305+
if (fnTy->isNoEscape()) {
4306+
diagnoseInvalid(ownershipRepr, ownershipRepr->getLoc(),
4307+
diag::ownership_specifier_nonescaping_closure,
4308+
ownershipRepr->getSpecifierSpelling());
4309+
return ErrorType::get(getASTContext());
4310+
}
4311+
}
4312+
break;
4313+
}
4314+
4315+
return result;
42924316
}
42934317

42944318
NeverNullType

0 commit comments

Comments
 (0)