Skip to content

Commit ffe22f6

Browse files
authored
Merge pull request #5104 from rintaro/static-toplevel
2 parents 5877db3 + d07d0da commit ffe22f6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,6 +4001,7 @@ ParserStatus Parser::parseDeclVar(ParseDeclOptions Flags,
40014001
diagnose(Tok, diag::static_var_decl_global_scope, StaticSpelling)
40024002
.fixItRemove(StaticLoc);
40034003
StaticLoc = SourceLoc();
4004+
StaticSpelling = StaticSpellingKind::None;
40044005
} else if (Flags.contains(PD_InStruct) || Flags.contains(PD_InEnum) ||
40054006
Flags.contains(PD_InProtocol)) {
40064007
if (StaticSpelling == StaticSpellingKind::KeywordClass)
@@ -4375,6 +4376,7 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
43754376
diagnose(Tok, diag::static_func_decl_global_scope, StaticSpelling)
43764377
.fixItRemove(StaticLoc);
43774378
StaticLoc = SourceLoc();
4379+
StaticSpelling = StaticSpellingKind::None;
43784380
} else if (Flags.contains(PD_InStruct) || Flags.contains(PD_InEnum) ||
43794381
Flags.contains(PD_InProtocol)) {
43804382
if (StaticSpelling == StaticSpellingKind::KeywordClass) {

test/IDE/print_ast_tc_decls_errors.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,10 @@ class OuterContext {
218218
// CHECK: func protocolFunc()
219219
}
220220
}
221+
222+
static func topLevelStaticFunc() {} // expected-error {{static methods may only be declared on a type}}
223+
// NO-TYPEPR: {{^}}func topLevelStaticFunc() -> <<error type>>{{$}}
224+
// TYPEPR: {{^}}func topLevelStaticFunc() {{$}}
225+
226+
static var topLevelStaticVar = 42 // expected-error {{static properties may only be declared on a type}}
227+
// CHECK: {{^}}var topLevelStaticVar: Int{{$}}

0 commit comments

Comments
 (0)