Skip to content

Commit 89d4e63

Browse files
committed
[Diagnostics]: Fix broken diagnostic for unnamed static class property
1 parent 1a23a75 commit 89d4e63

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ class Parser {
10121012
ParserResult<VarDecl> parseDeclVarGetSet(Pattern *pattern,
10131013
ParseDeclOptions Flags,
10141014
SourceLoc StaticLoc,
1015+
StaticSpellingKind StaticSpelling,
10151016
SourceLoc VarLoc,
10161017
bool hasInitializer,
10171018
const DeclAttributes &Attributes,

lib/Parse/ParseDecl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,8 +4675,9 @@ static void fillInAccessorTypeErrors(Parser &P,
46754675
/// Parse the brace-enclosed getter and setter for a variable.
46764676
ParserResult<VarDecl>
46774677
Parser::parseDeclVarGetSet(Pattern *pattern, ParseDeclOptions Flags,
4678-
SourceLoc StaticLoc, SourceLoc VarLoc,
4679-
bool hasInitializer,
4678+
SourceLoc StaticLoc,
4679+
StaticSpellingKind StaticSpelling,
4680+
SourceLoc VarLoc, bool hasInitializer,
46804681
const DeclAttributes &Attributes,
46814682
SmallVectorImpl<Decl *> &Decls) {
46824683
bool Invalid = false;
@@ -4740,7 +4741,7 @@ Parser::parseDeclVarGetSet(Pattern *pattern, ParseDeclOptions Flags,
47404741
PatternBindingEntry entry(pattern, /*EqualLoc*/ SourceLoc(),
47414742
/*Init*/ nullptr, /*InitContext*/ nullptr);
47424743
auto binding = PatternBindingDecl::create(Context, StaticLoc,
4743-
StaticSpellingKind::None,
4744+
StaticSpelling,
47444745
VarLoc, entry, CurDeclContext);
47454746
binding->setInvalid(true);
47464747
storage->setParentPatternBinding(binding);
@@ -5362,9 +5363,9 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
53625363
// var-get-set clause, parse the var-get-set clause.
53635364
if (Tok.is(tok::l_brace)) {
53645365
HasAccessors = true;
5365-
auto boundVar = parseDeclVarGetSet(pattern, Flags, StaticLoc, VarLoc,
5366-
PatternInit != nullptr,Attributes,
5367-
Decls);
5366+
auto boundVar =
5367+
parseDeclVarGetSet(pattern, Flags, StaticLoc, StaticSpelling, VarLoc,
5368+
PatternInit != nullptr, Attributes, Decls);
53685369
if (boundVar.hasCodeCompletion())
53695370
return makeResult(makeParserCodeCompletionStatus());
53705371
if (PatternInit && boundVar.isNonNull() &&

test/Parse/pattern_without_variables.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ func testVarLetPattern(a : SimpleEnum) {
3737
// expected-warning @+1 {{'if' condition is always true}}
3838
if case let _ = "str" {} // expected-warning {{'let' pattern has no effect; sub-pattern didn't bind any variables}} {{11-15=}}
3939
}
40+
41+
class SR10903 {
42+
static var _: Int { 0 } //expected-error {{getter/setter can only be defined for a single variable}}
43+
//expected-error@-1 {{property declaration does not bind any variables}}
44+
}

0 commit comments

Comments
 (0)