Skip to content

Commit c69c6df

Browse files
committed
Only enable _borrowing, _consuming and _mutating as declaration start keywors if the experimental feature is enabled
Otherwise `_mutating = 2` was rejected where it was previously accepted. rdar://115348117
1 parent a381b0d commit c69c6df

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)