Skip to content

Commit 1425473

Browse files
committed
[wip] disable let stored property destructuring
1 parent 2548312 commit 1425473

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,9 @@ ERROR(pattern_binds_no_variables,none,
21362136
ERROR(variable_bound_by_no_pattern,none,
21372137
"variable %0 is not bound by any pattern",
21382138
(const VarDecl *))
2139+
ERROR(destructuring_let_struct_stored_property_unsupported,none,
2140+
"binding multiple 'let' stored properties from a single initializer expression in a struct is unsupported",
2141+
())
21392142

21402143
WARNING(optional_ambiguous_case_ref,none,
21412144
"assuming you mean '%0.%2'; did you mean '%1.%2' instead?",

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ bool TypeChecker::typeCheckPatternBinding(PatternBindingDecl *PBD,
869869
if (hadError)
870870
PBD->setInvalid();
871871
PBD->setInitializerChecked(patternNumber);
872+
872873
return hadError;
873874
}
874875

lib/Sema/TypeCheckStorage.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,20 @@ const PatternBindingEntry *PatternBindingEntryRequest::evaluate(
567567
: GlobalVariable);
568568
}
569569
}
570+
571+
// If the pattern binding appears as a compound stored `let` property with an
572+
// initializer inside of a struct type, diagnose it as unsupported.
573+
// This hasn't ever been implemented properly.
574+
if (!binding->isStatic()
575+
&& binding->isInitialized(entryNumber)
576+
&& isa<StructDecl>(binding->getDeclContext())
577+
&& !pattern->getSingleVar()
578+
&& !vars.empty()
579+
&& vars[0]->isLet()) {
580+
Context.Diags.diagnose(binding->getPattern(entryNumber)->getLoc(),
581+
diag::destructuring_let_struct_stored_property_unsupported);
582+
}
583+
570584
return &pbe;
571585
}
572586

0 commit comments

Comments
 (0)