Skip to content

Commit 6c0df68

Browse files
Merge pull request #10003 from dotty-staging/fix-from-tasty-inputs
Only allow jar and tasty as input for -from-tasty
2 parents 94d36b4 + e88b0f9 commit 6c0df68

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ class Driver {
9090
// Resolve classpath and class names of tasty files
9191
val (classPaths, classNames) = fileNames0.flatMap { name =>
9292
val path = Paths.get(name)
93-
if !name.endsWith(".jar") && !name.endsWith(".tasty") then // is class name
94-
("", name) :: Nil // TODO remove this case. We cannot rely on an expected tasty file beeing loaded.
95-
else if !Files.exists(path) then
93+
if !Files.exists(path) then
9694
report.error(s"File does not exist: $name")
9795
Nil
9896
else if name.endsWith(".jar") then
9997
new dotty.tools.io.Jar(File(name)).toList.collect {
10098
case e if e.getName.endsWith(".tasty") && !fromTastyIgnoreList(e.getName) =>
10199
(name, e.getName.stripSuffix(".tasty").replace("/", "."))
102100
}
103-
else
104-
assert(name.endsWith(".tasty"))
101+
else if name.endsWith(".tasty") then
105102
TastyFileUtil.getClassName(path) match
106103
case Some(res) => res :: Nil
107104
case _ =>
108105
report.error(s"Could not load classname from: $name")
109106
Nil
107+
else
108+
report.error(s"File extension is not `tasty` or `jar`: $name")
109+
Nil
110110
}.unzip
111111
val ctx1 = ctx0.fresh
112112
val classPaths1 = classPaths.distinct.filter(_ != "")

project/scripts/bootstrapCmdTests

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ clear_out "$OUT"
3434
# check that `scalac -from-tasty` compiles and `scala` runs it
3535
echo "testing ./bin/scalac -from-tasty and scala -classpath"
3636
clear_out "$OUT1"
37-
./bin/scalac -from-tasty -classpath "$OUT" -d "$OUT1" "$MAIN"
37+
./bin/scalac -from-tasty -d "$OUT1" "$OUT/$TASTY"
3838
./bin/scala -classpath "$OUT1" "$MAIN" > "$tmp"
3939
test "$EXPECTED_OUTPUT" = "$(cat "$tmp")"
4040

project/scripts/cmdTests

+3-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ grep -qe "$EXPECTED_OUTPUT" "$tmp"
1010
# check that `sbt scalac` compiles and `sbt scala` runs it
1111
echo "testing sbt scalac -from-tasty and scala -classpath"
1212
clear_out "$OUT"
13-
"$SBT" ";scalac $SOURCE -d $OUT ;scalac -from-tasty -classpath $OUT -d $OUT1 $MAIN ;scala -classpath $OUT1 $MAIN" > "$tmp"
13+
"$SBT" ";scalac $SOURCE -d $OUT ;scalac -from-tasty -d $OUT1 $OUT/$TASTY ;scala -classpath $OUT1 $MAIN" > "$tmp"
1414
grep -qe "$EXPECTED_OUTPUT" "$tmp"
1515

1616
echo "testing sbt scalac -from-tasty from a jar and scala -classpath"
@@ -19,12 +19,8 @@ clear_out "$OUT"
1919
grep -qe "$EXPECTED_OUTPUT" "$tmp"
2020

2121
# check that `sbt scalac -decompile` runs
22-
echo "testing sbt scalac -decompile"
23-
"$SBT" ";scalac -decompile -color:never -classpath $OUT $MAIN" > "$tmp"
24-
grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp"
25-
2622
echo "testing sbt scalac -decompile from file"
27-
"$SBT" ";scalac -decompile -color:never -classpath $OUT $OUT/$TASTY" > "$tmp"
23+
"$SBT" ";scalac -decompile -color:never $OUT/$TASTY" > "$tmp"
2824
grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp"
2925

3026
echo "testing sbt scala with no -classpath"
@@ -34,7 +30,7 @@ grep -qe "$EXPECTED_OUTPUT" "$tmp"
3430

3531
echo "testing loading tasty from .tasty file in jar"
3632
clear_out "$OUT"
37-
"$SBT" ";scalac -d $OUT/out.jar $SOURCE; scalac -decompile -classpath $OUT/out.jar -color:never $MAIN" > "$tmp"
33+
"$SBT" ";scalac -d $OUT/out.jar $SOURCE; scalac -decompile -color:never $OUT/out.jar" > "$tmp"
3834
grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp"
3935

4036
echo "testing sbt scalac with suspension"

0 commit comments

Comments
 (0)