Skip to content

Commit c7ac32a

Browse files
Merge pull request #4062 from dotty-staging/fix-from-tasty-with-multiple-classes
Fix from tasty with multiple classes
2 parents 3ddc262 + 976ba4b commit c7ac32a

File tree

8 files changed

+38
-8
lines changed

8 files changed

+38
-8
lines changed

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DecompilationPrinter extends Phase {
2424
var os: OutputStream = null
2525
var ps: PrintStream = null
2626
try {
27-
os = File(outputDir + ".decompiled").outputStream()
27+
os = File(outputDir + ".decompiled").outputStream(append = true)
2828
ps = new PrintStream(os)
2929
printToOutput(ps)
3030
} finally {

compiler/src/dotty/tools/dotc/decompiler/Main.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dotty.tools.dotc.decompiler
22

3+
import java.nio.file.{Files, Paths}
4+
35
import dotty.tools.dotc
46
import dotty.tools.dotc.core.Contexts._
57

@@ -10,6 +12,9 @@ import dotty.tools.dotc.core.Contexts._
1012
object Main extends dotc.Driver {
1113
override protected def newCompiler(implicit ctx: Context): dotc.Compiler = {
1214
assert(ctx.settings.fromTasty.value)
15+
val outputDir = ctx.settings.outputDir.value
16+
if (outputDir != ".")
17+
Files.deleteIfExists(Paths.get(outputDir + ".decompiled"))
1318
new TASTYDecompiler
1419
}
1520

compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ class ReadTastyTreesFromClasses extends FrontEnd {
6666
clsd.infoOrCompleter match {
6767
case info: ClassfileLoader =>
6868
info.load(clsd) // sets cls.treeOrProvider and cls.moduleClass.treeProvider as a side-effect
69-
def moduleClass = clsd.owner.info.member(className.moduleClassName).symbol
70-
compilationUnit(clsd.classSymbol).orElse(compilationUnit(moduleClass))
7169
case _ =>
72-
alreadyLoaded()
7370
}
71+
def moduleClass = clsd.owner.info.member(className.moduleClassName).symbol
72+
compilationUnit(clsd.classSymbol).orElse(compilationUnit(moduleClass))
7473
case _ =>
7574
cannotUnpickle(s"no class file was found")
7675
}

compiler/test/dotty/tools/dotc/FromTastyTests.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class FromTastyTests extends ParallelTesting {
2929
val (step1, step2, step3) = compileTastyInDir("tests/pos", defaultOptions,
3030
blacklist = Set(
3131
"macro-deprecate-dont-touch-backquotedidents.scala",
32-
33-
// Compiles wrong class
34-
"simpleClass.scala",
32+
"t247.scala",
3533

3634
// Wrong number of arguments
3735
"i3130b.scala",
@@ -84,6 +82,7 @@ class FromTastyTests extends ParallelTesting {
8482
blacklist = Set(
8583

8684
"t7223.scala",
85+
"t5428.scala",
8786

8887
// Missing position
8988
"Course-2002-13.scala",

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
433433

434434
def hasTastyFileToClassName(f: JFile): String =
435435
targetDir.toPath.relativize(f.toPath).toString.dropRight(".hasTasty".length).replace('/', '.')
436-
val classes = flattenFiles(targetDir).filter(isHasTastyFile).map(hasTastyFileToClassName)
436+
val classes = flattenFiles(targetDir).filter(isHasTastyFile).map(hasTastyFileToClassName).sorted
437437

438438
val reporter =
439439
TestReporter.reporter(realStdout, logLevel =

tests/pos/simpleClass-2.decompiled

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
================================================================================
2+
out/posTestFromTasty/pos/simpleClass-2/foo/A.class
3+
--------------------------------------------------------------------------------
4+
package foo {
5+
class A() extends foo.B() {}
6+
}
7+
--------------------------------------------------------------------------------
8+
================================================================================
9+
out/posTestFromTasty/pos/simpleClass-2/foo/B.class
10+
--------------------------------------------------------------------------------
11+
package foo {
12+
class B() extends Object() {}
13+
}
14+
--------------------------------------------------------------------------------

tests/pos/simpleClass-2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package foo
2+
3+
class B
4+
5+
class A extends B
6+

tests/pos/simpleClass.decompiled

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ out/posTestFromTasty/pos/simpleClass/foo/A.class
44
package foo {
55
class A() extends Object() {}
66
}
7+
--------------------------------------------------------------------------------
8+
================================================================================
9+
out/posTestFromTasty/pos/simpleClass/foo/B.class
10+
--------------------------------------------------------------------------------
11+
package foo {
12+
class B() extends foo.A() {}
13+
}
714
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)