mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #62742 from gottesmm/pr-947919228bebf49e02eae5aedb1efee8038c2b4b
[borrow-expr] Add simple support for borrow-expr and wire it up to SILGenApply
This commit is contained in:
@@ -345,6 +345,11 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
|
||||
checkMoveExpr(moveExpr);
|
||||
}
|
||||
|
||||
// Diagnose move expression uses where the sub expression is not a declref expr
|
||||
if (auto *borrowExpr = dyn_cast<BorrowExpr>(E)) {
|
||||
checkBorrowExpr(borrowExpr);
|
||||
}
|
||||
|
||||
if (!HasReachedSemanticsProvidingExpr &&
|
||||
E == E->getSemanticsProvidingExpr()) {
|
||||
HasReachedSemanticsProvidingExpr = true;
|
||||
@@ -409,6 +414,26 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
|
||||
}
|
||||
}
|
||||
|
||||
void checkBorrowExpr(BorrowExpr *borrowExpr) {
|
||||
// Make sure the MoveOnly feature is set. If not, error.
|
||||
// This should not currently be reached because the parse should ignore
|
||||
// the _move keyword unless the feature flag is set.
|
||||
if (!Ctx.LangOpts.hasFeature(Feature::MoveOnly)) {
|
||||
auto error =
|
||||
diag::experimental_moveonly_feature_can_only_be_used_when_enabled;
|
||||
Ctx.Diags.diagnose(borrowExpr->getLoc(), error);
|
||||
}
|
||||
|
||||
// Allow for a chain of member_ref exprs that end in a decl_ref expr.
|
||||
auto *subExpr = borrowExpr->getSubExpr();
|
||||
while (auto *memberRef = dyn_cast<MemberRefExpr>(subExpr))
|
||||
subExpr = memberRef->getBase();
|
||||
if (!isa<DeclRefExpr>(subExpr)) {
|
||||
Ctx.Diags.diagnose(borrowExpr->getLoc(),
|
||||
diag::borrow_expression_not_passed_lvalue);
|
||||
}
|
||||
}
|
||||
|
||||
static Expr *lookThroughArgument(Expr *arg) {
|
||||
while (1) {
|
||||
if (auto conv = dyn_cast<ImplicitConversionExpr>(arg))
|
||||
|
||||
Reference in New Issue
Block a user