@@ -813,29 +813,6 @@ UnresolvedDeclRefExpr *Parser::parseExprOperator() {
813
813
return new (Context) UnresolvedDeclRefExpr (name, refKind, DeclNameLoc (loc));
814
814
}
815
815
816
- static VarDecl *getImplicitSelfDeclForSuperContext (Parser &P,
817
- DeclContext *DC,
818
- SourceLoc Loc) {
819
- auto *methodContext = DC->getInnermostMethodContext ();
820
- if (!methodContext) {
821
- P.diagnose (Loc, diag::super_not_in_class_method);
822
- return nullptr ;
823
- }
824
-
825
- // Do an actual lookup for 'self' in case it shows up in a capture list.
826
- auto *methodSelf = methodContext->getImplicitSelfDecl ();
827
- auto *lookupSelf = P.lookupInScope (P.Context .Id_self );
828
- if (lookupSelf && lookupSelf != methodSelf) {
829
- // FIXME: This is the wrong diagnostic for if someone manually declares a
830
- // variable named 'self' using backticks.
831
- P.diagnose (Loc, diag::super_in_closure_with_capture);
832
- P.diagnose (lookupSelf->getLoc (), diag::super_in_closure_with_capture_here);
833
- return nullptr ;
834
- }
835
-
836
- return methodSelf;
837
- }
838
-
839
816
// / parseExprSuper
840
817
// /
841
818
// / expr-super:
@@ -848,28 +825,36 @@ static VarDecl *getImplicitSelfDeclForSuperContext(Parser &P,
848
825
// / 'super' '.' 'init'
849
826
// / expr-super-subscript:
850
827
// / 'super' '[' expr ']'
851
- ParserResult<Expr> Parser::parseExprSuper () {
852
- SyntaxParsingContext SuperCtxt (SyntaxContext, SyntaxContextKind::Expr);
853
- // Parse the 'super' reference.
854
- SourceLoc superLoc = consumeToken (tok::kw_super);
855
- SyntaxContext->createNodeInPlace (SyntaxKind::SuperRefExpr);
828
+ ParsedSyntaxResult<ParsedExprSyntax> Parser::parseExprSuperSyntax () {
829
+ auto superTok = consumeTokenSyntax (tok::kw_super);
856
830
857
831
// 'super.' must be followed by a member ref, explicit initializer ref, or
858
832
// subscript call.
859
833
if (!Tok.isAny (tok::period, tok::period_prefix, tok::code_complete) &&
860
834
!Tok.isFollowingLSquare ()) {
861
- if (!consumeIf (tok::unknown))
835
+ SmallVector<ParsedSyntax, 2 > junk;
836
+ junk.emplace_back (std::move (superTok));
837
+ if (auto unknown = consumeTokenSyntaxIf (tok::unknown)) {
838
+ junk.emplace_back (std::move (*unknown));
839
+ } else {
862
840
diagnose (Tok, diag::expected_dot_or_subscript_after_super);
863
- return nullptr ;
841
+ }
842
+
843
+ return makeParsedError (
844
+ ParsedSyntaxRecorder::makeUnknownExpr (junk, *SyntaxContext));
864
845
}
865
846
866
- VarDecl *selfDecl =
867
- getImplicitSelfDeclForSuperContext (*this , CurDeclContext, superLoc);
868
- if (!selfDecl)
869
- return makeParserResult (new (Context) ErrorExpr (superLoc));
847
+ return makeParsedResult (ParsedSyntaxRecorder::makeSuperRefExpr (
848
+ std::move (superTok), *SyntaxContext));
849
+ }
870
850
871
- return makeParserResult (new (Context) SuperRefExpr (selfDecl, superLoc,
872
- /* Implicit=*/ false ));
851
+ ParserResult<Expr> Parser::parseExprSuper () {
852
+ auto leadingLoc = leadingTriviaLoc ();
853
+ auto parsed = parseExprSuperSyntax ();
854
+ SyntaxContext->addSyntax (parsed.get ());
855
+ auto syntax = SyntaxContext->topNode <ExprSyntax>();
856
+ auto expr = Generator.generate (syntax, leadingLoc);
857
+ return makeParserResult (parsed.getStatus (), expr);
873
858
}
874
859
875
860
StringRef Parser::copyAndStripUnderscores (StringRef orig) {
0 commit comments