Skip to content

Commit 08a42b2

Browse files
committed
Fix typos and improve namings
1 parent 3e3ce5b commit 08a42b2

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

tests/pos/main-method-scheme-class-based.scala

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ trait MainAnnotation extends StaticAnnotation:
1919
type ArgumentParser[T]
2020

2121
/** The required result type of the main function */
22-
type ResultType
22+
type MainResultType
2323

2424
/** A new command with arguments from `args` */
2525
def command(args: Array[String]): Command
2626

2727
/** A class representing a command to run */
2828
abstract class Command:
2929

30-
/** The getter for the next simple argument */
30+
/** The getter for the next argument of type `T` */
3131
def argGetter[T](argName: String, fromString: ArgumentParser[T], defaultValue: Option[T] = None): () => T
3232

33-
/** The getter for a final varargs argument */
34-
def argsGetter[T](argName: String, fromString: ArgumentParser[T]): () => List[T]
33+
/** The getter for a final varargs argument of type `T*` */
34+
def argsGetter[T](argName: String, fromString: ArgumentParser[T]): () => Seq[T]
3535

36-
/** Run function `f()` if all arguments are valid,
36+
/** Run `program` if all arguments are valid,
3737
* or print usage information and/or error messages.
3838
*/
39-
def run(f: => ResultType, progName: String, docComment: String): Unit
39+
def run(program: => MainResultType, progName: String, docComment: String): Unit
4040
end Command
4141
end MainAnnotation
4242

@@ -45,7 +45,7 @@ end MainAnnotation
4545
class main extends MainAnnotation:
4646

4747
type ArgumentParser[T] = util.FromString[T]
48-
type ResultType = Any
48+
type MainResultType = Any
4949

5050
def command(args: Array[String]): Command = new Command:
5151

@@ -54,29 +54,29 @@ class main extends MainAnnotation:
5454
* "*" if it is a vararg
5555
* "" otherwise
5656
*/
57-
var argInfos = new mutable.ListBuffer[(String, String)]
57+
private var argInfos = new mutable.ListBuffer[(String, String)]
5858

5959
/** A buffer for all errors */
60-
var errors = new mutable.ListBuffer[String]
60+
private var errors = new mutable.ListBuffer[String]
6161

6262
/** Issue an error, and return an uncallable getter */
63-
def error(msg: String): () => Nothing =
63+
private def error(msg: String): () => Nothing =
6464
errors += msg
6565
() => assertFail("trying to get invalid argument")
6666

6767
/** The next argument index */
68-
var argIdx: Int = 0
68+
private var argIdx: Int = 0
6969

70-
def argAt(idx: Int): Option[String] =
70+
private def argAt(idx: Int): Option[String] =
7171
if idx < args.length then Some(args(idx)) else None
7272

73-
def nextPositionalArg(): Option[String] =
73+
private def nextPositionalArg(): Option[String] =
7474
while argIdx < args.length && args(argIdx).startsWith("--") do argIdx += 2
7575
val result = argAt(argIdx)
7676
argIdx += 1
7777
result
7878

79-
def convert[T](argName: String, arg: String, p: ArgumentParser[T]): () => T =
79+
private def convert[T](argName: String, arg: String, p: ArgumentParser[T]): () => T =
8080
p.fromStringOption(arg) match
8181
case Some(t) => () => t
8282
case None => error(s"invalid argument for $argName: $arg")
@@ -91,15 +91,15 @@ class main extends MainAnnotation:
9191
case Some(t) => () => t
9292
case None => error(s"missing argument for $argName")
9393

94-
def argsGetter[T](argName: String, fromString: ArgumentParser[T]): () => List[T] =
94+
def argsGetter[T](argName: String, p: ArgumentParser[T]): () => Seq[T] =
9595
argInfos += ((argName, "*"))
96-
def recur(): List[() => T] = nextPositionalArg() match
97-
case Some(arg) => convert(arg, argName, fromString) :: recur()
96+
def remainingArgGetters(): List[() => T] = nextPositionalArg() match
97+
case Some(arg) => convert(arg, argName, p) :: remainingArgGetters()
9898
case None => Nil
99-
val fns = recur()
100-
() => fns.map(_())
99+
val getters = remainingArgGetters()
100+
() => getters.map(_())
101101

102-
def run(f: => ResultType, progName: String, docComment: String): Unit =
102+
def run(f: => MainResultType, progName: String, docComment: String): Unit =
103103
def usage(): Unit =
104104
println(s"Usage: $progName ${argInfos.map(_ + _).mkString(" ")}")
105105

tests/pos/main-method-scheme.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ end main
109109
object myProgram:
110110

111111
/** Adds two numbers */
112-
@_main def add(num: Int, inc: Int = 1) =
112+
@main def add(num: Int, inc: Int = 1) =
113113
println(s"$num + $inc = ${num + inc}")
114114

115115
end myProgram

0 commit comments

Comments
 (0)