Skip to content

Commit 7eb3572

Browse files
committed
Parse Function arity without throwing exceptions
Using NumberFormatException in the normal control flow of the program makes it harder to debug the compiler by stopping on all instances of RuntimeException.
1 parent fa9f8b2 commit 7eb3572

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)