From b69d3d25e2335e216c2c0546866ffdc9ab892a8c Mon Sep 17 00:00:00 2001 From: Phil Date: Sun, 3 Oct 2021 15:54:16 -0600 Subject: [PATCH] relax requirements for recognizing of a valid scala hashbang line, fix for #13670 --- compiler/src/dotty/tools/MainGenericRunner.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/MainGenericRunner.scala b/compiler/src/dotty/tools/MainGenericRunner.scala index dfc56a8c11d2..2e634645fddc 100644 --- a/compiler/src/dotty/tools/MainGenericRunner.scala +++ b/compiler/src/dotty/tools/MainGenericRunner.scala @@ -146,7 +146,8 @@ object MainGenericRunner { process(tail, settings.withScalaArgs(o)) case arg :: tail => val line = Try(Source.fromFile(arg).getLines.toList).toOption.flatMap(_.headOption) - if arg.endsWith(".scala") || arg.endsWith(".sc") || (line.nonEmpty && raw"#!.*scala".r.matches(line.get)) then + lazy val hasScalaHashbang = { val s = line.getOrElse("") ; s.startsWith("#!") && s.contains("scala") } + if arg.endsWith(".scala") || arg.endsWith(".sc") || hasScalaHashbang then settings .withExecuteMode(ExecuteMode.Script) .withTargetScript(arg)