Skip to content

Commit af32a12

Browse files
authored
Merge pull request #2181 from ahoppen/ahoppen/mutating-declaration-start
Only enable `_borrowing`, `_consuming` and `_mutating` as declaration start keywors if the experimental feature is enabled
2 parents ddd05ef + e1657a5 commit af32a12

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ extension TokenConsumer {
138138
// FIXME: C++ parser returns true if this is a top-level non-"script" files.
139139
// But we don't have "is library" flag.
140140
return false
141+
case .rhs(._borrowing), .rhs(._consuming), .rhs(._mutating):
142+
return experimentalFeatures.contains(.referenceBindings)
141143
case .some(_):
142144
// All other decl start keywords unconditionally start a decl.
143145
return true

Sources/SwiftParser/TokenConsumer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ protocol TokenConsumer {
1717
associatedtype Token
1818
/// The current token syntax being examined by the consumer
1919
var currentToken: Lexer.Lexeme { get }
20+
21+
/// The experimental features that have been enabled.
22+
var experimentalFeatures: Parser.ExperimentalFeatures { get }
23+
2024
/// Whether the current token matches the given kind.
2125
mutating func consumeAnyToken() -> Token
2226

Tests/SwiftParserTest/translated/PatternWithoutVariablesTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,7 @@ final class PatternWithoutVariablesTests: ParserTestCase {
117117
)
118118
}
119119

120+
func testMutatingNotADeclarationStartIfNotEnabled() {
121+
assertParse("_mutating = 2")
122+
}
120123
}

0 commit comments

Comments
 (0)