Skip to content

Commit c2279d2

Browse files
authored
[Parse] Allow whitespaces before period in superclass-expression (swiftlang#5423)
Previously: error: expected '.' or '[' after 'super' super .init() ^ There's no reason to reject this while accepting 'self .init()'
1 parent bf40426 commit c2279d2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ ParserResult<Expr> Parser::parseExprSuper(bool isExprBasic) {
743743
/*Implicit=*/false))
744744
: cast<Expr>(new (Context) ErrorExpr(superLoc));
745745

746-
if (Tok.is(tok::period)) {
746+
if (Tok.isAny(tok::period, tok::period_prefix)) {
747747
// 'super.' must be followed by a member or initializer ref.
748748

749-
SourceLoc dotLoc = consumeToken(tok::period);
749+
SourceLoc dotLoc = consumeToken();
750750

751751
if (Tok.is(tok::code_complete)) {
752752
if (CodeCompletion) {

test/Parse/super.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class D : B {
2626
let _: () -> D = self.init // expected-error {{partial application of 'self.init' initializer delegation is not allowed}}
2727
}
2828

29+
init(z: Int) {
30+
super
31+
.init(x: z)
32+
}
33+
2934
func super_calls() {
3035
super.foo // expected-error {{expression resolves to an unused l-value}}
3136
super.foo.bar // expected-error {{value of type 'Int' has no member 'bar'}}
@@ -35,6 +40,8 @@ class D : B {
3540
super.init() // expected-error{{'super.init' cannot be called outside of an initializer}}
3641
super.init(0) // expected-error{{'super.init' cannot be called outside of an initializer}}
3742
super[0] // expected-error {{expression resolves to an unused l-value}}
43+
super
44+
.bar()
3845
}
3946

4047
func bad_super_1() {

0 commit comments

Comments
 (0)