Skip to content

Commit a796b67

Browse files
committed
Add capture checking to CommandLineParser
1 parent b20db6e commit a796b67

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

library/src/scala/util/CommandLineParser.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package scala.util
22

3+
import language.experimental.captureChecking
4+
35
/** A utility object to support command line parsing for @main methods */
46
object CommandLineParser {
57

@@ -12,7 +14,7 @@ object CommandLineParser {
1214
/** Parse command line argument `s`, which has index `n`, as a value of type `T`
1315
* @throws ParseError if argument cannot be converted to type `T`.
1416
*/
15-
def parseString[T](str: String, n: Int)(using fs: FromString[T]): T = {
17+
def parseString[T](str: String, n: Int)(using fs: FromString[T]^): T = {
1618
try fs.fromString(str)
1719
catch {
1820
case ex: IllegalArgumentException => throw ParseError(n, ex.toString)
@@ -22,14 +24,14 @@ object CommandLineParser {
2224
/** Parse `n`'th argument in `args` (counting from 0) as a value of type `T`
2325
* @throws ParseError if argument does not exist or cannot be converted to type `T`.
2426
*/
25-
def parseArgument[T](args: Array[String], n: Int)(using fs: FromString[T]): T =
27+
def parseArgument[T](args: Array[String], n: Int)(using fs: FromString[T]^): T =
2628
if n < args.length then parseString(args(n), n)
2729
else throw ParseError(n, "more arguments expected")
2830

2931
/** Parse all arguments from `n`'th one (counting from 0) as a list of values of type `T`
3032
* @throws ParseError if some of the arguments cannot be converted to type `T`.
3133
*/
32-
def parseRemainingArguments[T](args: Array[String], n: Int)(using fs: FromString[T]): List[T] =
34+
def parseRemainingArguments[T](args: Array[String], n: Int)(using fs: FromString[T]^): List[T] =
3335
if n < args.length then parseString(args(n), n) :: parseRemainingArguments(args, n + 1)
3436
else Nil
3537

0 commit comments

Comments
 (0)