Skip to content

Commit 1b2a4ac

Browse files
committed
[AST] Add Pattern::hasAnyMutableBindings
1 parent 6368c74 commit 1b2a4ac

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/swift/AST/Pattern.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ class alignas(8) Pattern {
202202
/// Does this binding declare something that requires storage?
203203
bool hasStorage() const;
204204

205+
/// Does this pattern have any mutable 'var' bindings?
206+
bool hasAnyMutableBindings() const;
207+
205208
static bool classof(const Pattern *P) { return true; }
206209

207210
//*** Allocation Routines ************************************************/

lib/AST/Pattern.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ bool Pattern::hasStorage() const {
291291
return HasStorage;
292292
}
293293

294+
bool Pattern::hasAnyMutableBindings() const {
295+
auto HasMutable = false;
296+
forEachVariable([&](VarDecl *VD) {
297+
if (!VD->isLet())
298+
HasMutable = true;
299+
});
300+
return HasMutable;
301+
}
302+
294303
/// Return true if this is a non-resolved ExprPattern which is syntactically
295304
/// irrefutable.
296305
static bool isIrrefutableExprPattern(const ExprPattern *EP) {

0 commit comments

Comments
 (0)