Skip to content

Commit 994f9a9

Browse files
committed
[Diagnostics] Result Builders: Improve diagnostic for unsupported observed vars
1 parent 0074adc commit 994f9a9

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5886,7 +5886,7 @@ ERROR(result_builder_requires_explicit_var_initialization,none,
58865886
"local variable%select{| '%1'}0 requires explicit initializer to be used with "
58875887
"result builder %2", (bool, StringRef, DeclName))
58885888
ERROR(cannot_declare_computed_var_in_result_builder,none,
5889-
"cannot declare local %select{lazy|wrapped|computed}0 variable "
5889+
"cannot declare local %select{lazy|wrapped|computed|observed}0 variable "
58905890
"in result builder", (unsigned))
58915891

58925892
//------------------------------------------------------------------------------

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,7 +5877,8 @@ bool SkipUnhandledConstructInResultBuilderFailure::diagnosePatternBinding(
58775877
for (unsigned i : range(PB->getNumPatternEntries())) {
58785878
auto *pattern = PB->getPattern(i);
58795879

5880-
// Each variable bound by the pattern must be stored.
5880+
// Each variable bound by the pattern must be stored and cannot have
5881+
// observers.
58815882
{
58825883
SmallVector<VarDecl *, 8> variables;
58835884
pattern->collectVariables(variables);
@@ -5917,7 +5918,7 @@ bool SkipUnhandledConstructInResultBuilderFailure::diagnosePatternBinding(
59175918

59185919
bool SkipUnhandledConstructInResultBuilderFailure::diagnoseStorage(
59195920
VarDecl *var) const {
5920-
enum class PropertyKind : unsigned { lazy, wrapped, computed };
5921+
enum class PropertyKind : unsigned { lazy, wrapped, computed, observed };
59215922

59225923
if (var->getImplInfo().isSimpleStored())
59235924
return false;
@@ -5927,6 +5928,8 @@ bool SkipUnhandledConstructInResultBuilderFailure::diagnoseStorage(
59275928
kind = PropertyKind::lazy;
59285929
} else if (var->hasAttachedPropertyWrapper()) {
59295930
kind = PropertyKind::wrapped;
5931+
} else if (var->hasObservers()) {
5932+
kind = PropertyKind::observed;
59305933
} else {
59315934
kind = PropertyKind::computed;
59325935
}

test/Constraints/result_builder_invalid_vars.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ dummy {
2020
}
2121

2222
dummy {
23-
var observedVar: Int = 123 { // expected-error {{closure containing a declaration cannot be used with result builder 'DummyBuilder'}}
23+
var observedVar: Int = 123 { // expected-error {{cannot declare local observed variable in result builder}}
2424
didSet {}
2525
}
2626

2727
()
2828
}
2929

3030
dummy {
31-
var observedVar: Int = 123 { // expected-error {{closure containing a declaration cannot be used with result builder 'DummyBuilder'}}
31+
var observedVar: Int = 123 { // expected-error {{cannot declare local observed variable in result builder}}
3232
willSet {}
3333
}
3434

0 commit comments

Comments
 (0)