Skip to content

Commit e52feac

Browse files
authored
Merge pull request swiftlang#25565 from owenv/unnamed_static_var_diag
[Diagnostics]: Fix broken diagnostic for unnamed static class property
2 parents 990a75e + 89d4e63 commit e52feac

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
@@ -4684,8 +4684,9 @@ static void fillInAccessorTypeErrors(Parser &P,
46844684
/// Parse the brace-enclosed getter and setter for a variable.
46854685
ParserResult<VarDecl>
46864686
Parser::parseDeclVarGetSet(Pattern *pattern, ParseDeclOptions Flags,
4687-
SourceLoc StaticLoc, SourceLoc VarLoc,
4688-
bool hasInitializer,
4687+
SourceLoc StaticLoc,
4688+
StaticSpellingKind StaticSpelling,
4689+
SourceLoc VarLoc, bool hasInitializer,
46894690
const DeclAttributes &Attributes,
46904691
SmallVectorImpl<Decl *> &Decls) {
46914692
bool Invalid = false;
@@ -4749,7 +4750,7 @@ Parser::parseDeclVarGetSet(Pattern *pattern, ParseDeclOptions Flags,
47494750
PatternBindingEntry entry(pattern, /*EqualLoc*/ SourceLoc(),
47504751
/*Init*/ nullptr, /*InitContext*/ nullptr);
47514752
auto binding = PatternBindingDecl::create(Context, StaticLoc,
4752-
StaticSpellingKind::None,
4753+
StaticSpelling,
47534754
VarLoc, entry, CurDeclContext);
47544755
binding->setInvalid(true);
47554756
storage->setParentPatternBinding(binding);
@@ -5371,9 +5372,9 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
53715372
// var-get-set clause, parse the var-get-set clause.
53725373
if (Tok.is(tok::l_brace)) {
53735374
HasAccessors = true;
5374-
auto boundVar = parseDeclVarGetSet(pattern, Flags, StaticLoc, VarLoc,
5375-
PatternInit != nullptr,Attributes,
5376-
Decls);
5375+
auto boundVar =
5376+
parseDeclVarGetSet(pattern, Flags, StaticLoc, StaticSpelling, VarLoc,
5377+
PatternInit != nullptr, Attributes, Decls);
53775378
if (boundVar.hasCodeCompletion())
53785379
return makeResult(makeParserCodeCompletionStatus());
53795380
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)