Skip to content

Commit 22df21e

Browse files
committed
Parse negative integers in type arguments
1 parent 973fced commit 22df21e

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ extension Parser {
368368

369369
let (unexpectedBeforeName, name) = self.expect(anyIn: IdentifierTypeSyntax.NameOptions.self, default: .identifier)
370370
let generics: RawGenericArgumentClauseSyntax?
371-
if self.atContextualPunctuator("<") {
371+
if self.at(prefix: "<") {
372372
generics = self.parseGenericArguments()
373373
} else {
374374
generics = nil

Tests/SwiftParserTest/ValueGenericsTests.swift

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_spi(ExperimentalLanguageFeatures)
14+
import SwiftParser
1315
import SwiftSyntax
1416
import XCTest
1517

@@ -120,25 +122,22 @@ final class ValueGenericsTests: ParserTestCase {
120122
],
121123
fixedSource: """
122124
let x: <#type#> = 123
123-
"""
125+
""",
126+
experimentalFeatures: .valueGenerics
124127
)
125128

126129
assertParse(
127130
"""
128131
let x: Generic<123>
129-
"""
132+
""",
133+
experimentalFeatures: .valueGenerics
130134
)
131135

132-
// FIXME?: We can't parse this either in the old parser or the swift-syntax one.
133136
assertParse(
134137
"""
135-
let x: Generic1️⃣<-123>
138+
let x: Generic<-321>
136139
""",
137-
diagnostics: [
138-
DiagnosticSpec(
139-
message: "extraneous code '<-123>' at top level"
140-
)
141-
]
140+
experimentalFeatures: .valueGenerics
142141
)
143142

144143
assertParse(
@@ -153,31 +152,36 @@ final class ValueGenericsTests: ParserTestCase {
153152
],
154153
fixedSource: """
155154
typealias One = <#type#>1
156-
"""
155+
""",
156+
experimentalFeatures: .valueGenerics
157157
)
158158

159159
assertParse(
160160
"""
161161
extension Vector where N == 123 {}
162-
"""
162+
""",
163+
experimentalFeatures: .valueGenerics
163164
)
164165

165166
assertParse(
166167
"""
167168
extension Vector where 123 == N {}
168-
"""
169+
""",
170+
experimentalFeatures: .valueGenerics
169171
)
170172

171173
assertParse(
172174
"""
173175
extension Vector where N == -123 {}
174-
"""
176+
""",
177+
experimentalFeatures: .valueGenerics
175178
)
176179

177180
assertParse(
178181
"""
179182
extension Vector where -123 == N {}
180-
"""
183+
""",
184+
experimentalFeatures: .valueGenerics
181185
)
182186

183187
assertParse(
@@ -195,7 +199,8 @@ final class ValueGenericsTests: ParserTestCase {
195199
],
196200
fixedSource: """
197201
extension Vector where N: <#type#> 123 {}
198-
"""
202+
""",
203+
experimentalFeatures: .valueGenerics
199204
)
200205

201206
assertParse(
@@ -213,7 +218,8 @@ final class ValueGenericsTests: ParserTestCase {
213218
],
214219
fixedSource: """
215220
extension Vector where N: <#type#> -123 {}
216-
"""
221+
""",
222+
experimentalFeatures: .valueGenerics
217223
)
218224

219225
// FIXME: Not the best diagnostic
@@ -228,7 +234,8 @@ final class ValueGenericsTests: ParserTestCase {
228234
DiagnosticSpec(
229235
message: "unexpected code ': N' in extension"
230236
),
231-
]
237+
],
238+
experimentalFeatures: .valueGenerics
232239
)
233240

234241
assertParse(
@@ -242,7 +249,17 @@ final class ValueGenericsTests: ParserTestCase {
242249
DiagnosticSpec(
243250
message: "unexpected code ': N' in extension"
244251
),
245-
]
252+
],
253+
experimentalFeatures: .valueGenerics
254+
)
255+
}
256+
257+
func testNegativeInteger() {
258+
assertParse(
259+
"""
260+
let x: Generic<-321>
261+
""",
262+
experimentalFeatures: .valueGenerics
246263
)
247264
}
248265
}

0 commit comments

Comments
 (0)