Skip to content

Commit ddbb6d0

Browse files
Add function to check name validity
1 parent 36988bb commit ddbb6d0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

library/src/scala/main.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ final class main(maxLineLength: Int) extends MainAnnotation:
154154
argIdx += 1
155155
result
156156

157+
private def nameIsValid(name: String): Boolean =
158+
name.length > 0 // TODO add more checks for illegal characters
159+
157160
private def shortNameIsValid(shortName: Char): Boolean =
158161
// If you change this, remember to update the error message when an invalid short name is given
159162
('A' <= shortName && shortName <= 'Z') || ('a' <= shortName && shortName <= 'z')
@@ -264,7 +267,11 @@ final class main(maxLineLength: Int) extends MainAnnotation:
264267
(indices ++: indicesShort).filter(_ >= 0)
265268

266269
private def getAlternativeNames(paramInfos: ParameterInfos[_]): Seq[String] =
267-
paramInfos.annotations.collect{ case annot: Name => annot.name }.filter(_.length > 0)
270+
val (valid, invalid) =
271+
paramInfos.annotations.collect{ case annot: Name => annot.name }.partition(nameIsValid)
272+
if invalid.nonEmpty then
273+
throw IllegalArgumentException(s"invalid names ${invalid.mkString(", ")} for parameter ${paramInfos.name}")
274+
valid
268275

269276
private def getShortNames(paramInfos: ParameterInfos[_]): Seq[Char] =
270277
val (valid, invalid) =

0 commit comments

Comments
 (0)