diff --git a/Sources/SwiftParser/Declarations.swift b/Sources/SwiftParser/Declarations.swift index b463e0f2104..43d6edcbf70 100644 --- a/Sources/SwiftParser/Declarations.swift +++ b/Sources/SwiftParser/Declarations.swift @@ -138,6 +138,8 @@ extension TokenConsumer { // FIXME: C++ parser returns true if this is a top-level non-"script" files. // But we don't have "is library" flag. return false + case .rhs(._borrowing), .rhs(._consuming), .rhs(._mutating): + return experimentalFeatures.contains(.referenceBindings) case .some(_): // All other decl start keywords unconditionally start a decl. return true diff --git a/Sources/SwiftParser/TokenConsumer.swift b/Sources/SwiftParser/TokenConsumer.swift index 59b3a7cf76a..d319d064445 100644 --- a/Sources/SwiftParser/TokenConsumer.swift +++ b/Sources/SwiftParser/TokenConsumer.swift @@ -17,6 +17,10 @@ protocol TokenConsumer { associatedtype Token /// The current token syntax being examined by the consumer var currentToken: Lexer.Lexeme { get } + + /// The experimental features that have been enabled. + var experimentalFeatures: Parser.ExperimentalFeatures { get } + /// Whether the current token matches the given kind. mutating func consumeAnyToken() -> Token diff --git a/Tests/SwiftParserTest/translated/PatternWithoutVariablesTests.swift b/Tests/SwiftParserTest/translated/PatternWithoutVariablesTests.swift index b8a61b8dac5..5cdc9ed69a2 100644 --- a/Tests/SwiftParserTest/translated/PatternWithoutVariablesTests.swift +++ b/Tests/SwiftParserTest/translated/PatternWithoutVariablesTests.swift @@ -117,4 +117,7 @@ final class PatternWithoutVariablesTests: ParserTestCase { ) } + func testMutatingNotADeclarationStartIfNotEnabled() { + assertParse("_mutating = 2") + } }