Skip to content

Commit 9a98834

Browse files
committed
[NFC-ish] Do lookahead without llvm::function_ref
1 parent 99213ac commit 9a98834

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

include/swift/Parse/Parser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,8 @@ class Parser {
487487
/// \returns the value returned by \c f
488488
/// \note When calling, you may need to specify the \c Val type
489489
/// explicitly as a type parameter.
490-
template <typename Val>
491-
Val lookahead(unsigned char K,
492-
llvm::function_ref<Val(CancellableBacktrackingScope &)> f) {
490+
template <typename Fn>
491+
decltype(auto) lookahead(unsigned char K, Fn f) {
493492
CancellableBacktrackingScope backtrackScope(*this);
494493

495494
for (unsigned char i = 0; i < K; ++i)

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3014,7 +3014,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
30143014

30153015
// Backwards support for @cdecl("stringId"). Remove before enabling in
30163016
// production so we accept only the identifier format.
3017-
lookahead<bool>(1, [&](CancellableBacktrackingScope &) {
3017+
lookahead(1, [&](CancellableBacktrackingScope &) {
30183018
return Tok.isNot(tok::string_literal);
30193019
})) {
30203020

lib/Parse/ParsePattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool Parser::startsParameterName(bool isClosure) {
122122
// contextual keywords, so look ahead one more token (two total) and see
123123
// if we have a ':' that would
124124
// indicate that this is an argument label.
125-
return lookahead<bool>(2, [&](CancellableBacktrackingScope &) {
125+
return lookahead(2, [&](CancellableBacktrackingScope &) {
126126
if (Tok.is(tok::colon))
127127
return true; // isolated :
128128

@@ -235,7 +235,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
235235
// is this token the identifier of an argument label? `inout` is a
236236
// reserved keyword but the other modifiers are not.
237237
if (!Tok.is(tok::kw_inout)) {
238-
bool partOfArgumentLabel = lookahead<bool>(1, [&](CancellableBacktrackingScope &) {
238+
bool partOfArgumentLabel = lookahead(1, [&](CancellableBacktrackingScope &) {
239239
if (Tok.is(tok::colon))
240240
return true; // isolated :
241241

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
func fn() {
4+
_ = 1.description
5+
_ = 1.5.description
6+
7+
print(1.description)
8+
print(1.5.description)
9+
}

0 commit comments

Comments
 (0)