Skip to content

Commit 7e9ea25

Browse files
authored
Merge pull request #2694 from dotty-staging/fix-parse-number
Parse Function arity without throwing exceptions
2 parents 3ad624f + 7eb3572 commit 7e9ea25

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,13 @@ object NameOps {
190190

191191
/** Parsed function arity for function with some specific prefix */
192192
private def functionArityFor(prefix: String): Int = {
193-
if (name.startsWith(prefix))
194-
try name.toString.substring(prefix.length).toInt
195-
catch { case _: NumberFormatException => -1 }
196-
else -1
193+
if (name.startsWith(prefix)) {
194+
val suffix = name.toString.substring(prefix.length)
195+
if (suffix.matches("\\d+"))
196+
suffix.toInt
197+
else
198+
-1
199+
} else -1
197200
}
198201

199202
/** The name of the generic runtime operation corresponding to an array operation */

0 commit comments

Comments
 (0)