Skip to content

Commit f797e19

Browse files
committed
[Parse] Updated protocol diagnostic to allow read.
With the `CoroutineAccessors` feature, `read` is allowed along with `get` and `set`; alter the diagnostic that's issued when a disallowed introducer is listed in the requirement list to indicate that `read` is one of those which are valid, but only when the feature is enabled.
1 parent f2e3e8e commit f797e19

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ ERROR(static_var_decl_global_scope,none,
255255
(StaticSpellingKind))
256256
ERROR(expected_getset_in_protocol,none,
257257
"expected get or set in a protocol property", ())
258+
ERROR(expected_getreadset_in_protocol,none,
259+
"expected get, read, or set in a protocol property", ())
258260
ERROR(unexpected_getset_implementation_in_protocol,none,
259261
"protocol property %0 cannot have a default implementation specified "
260262
"here; use extension instead", (StringRef))

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8144,7 +8144,10 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
81448144

81458145
// parsingLimitedSyntax mode cannot have a body.
81468146
if (parsingLimitedSyntax) {
8147-
diagnose(Tok, diag::expected_getset_in_protocol);
8147+
auto diag = Context.LangOpts.hasFeature(Feature::CoroutineAccessors)
8148+
? diag::expected_getreadset_in_protocol
8149+
: diag::expected_getset_in_protocol;
8150+
diagnose(Tok, diag);
81488151
Status |= makeParserError();
81498152
break;
81508153
}
@@ -8178,7 +8181,10 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
81788181
// avoid having to deal with them everywhere.
81798182
if (parsingLimitedSyntax && !isAllowedWhenParsingLimitedSyntax(
81808183
Kind, SF.Kind == SourceFileKind::SIL)) {
8181-
diagnose(Loc, diag::expected_getset_in_protocol);
8184+
auto diag = Context.LangOpts.hasFeature(Feature::CoroutineAccessors)
8185+
? diag::expected_getreadset_in_protocol
8186+
: diag::expected_getset_in_protocol;
8187+
diagnose(Loc, diag);
81828188
continue;
81838189
}
81848190

test/Parse/coroutine_accessors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ var ir_rm_m: Int {
334334
protocol P {
335335
var goodP: Int { read set } //expected-disabled-error{{property in protocol must have explicit { get } or { get set } specifier}}
336336
//expected-disabled-error@-1{{expected get or set in a protocol property}}
337-
var badP: Int { read modify } //expected-enabled-error{{expected get or set in a protocol property}}
337+
var badP: Int { read modify } //expected-enabled-error{{expected get, read, or set in a protocol property}}
338338
//expected-disabled-error@-1{{property in protocol must have explicit { get } or { get set } specifier}}
339339
//expected-disabled-error@-2{{expected get or set in a protocol property}}
340340
subscript(goodS goodS: Int) -> Int { read set } //expected-disabled-error{{expected get or set in a protocol property}}
341-
subscript(badS badS: Int) -> Int { read modify } //expected-enabled-error{{expected get or set in a protocol property}}
341+
subscript(badS badS: Int) -> Int { read modify } //expected-enabled-error{{expected get, read, or set in a protocol property}}
342342
//expected-disabled-error@-1{{expected get or set in a protocol property}}
343343
}

0 commit comments

Comments
 (0)