diff --git a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala index c41a27281c5f..51533640a3bb 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala @@ -24,7 +24,7 @@ class DecompilationPrinter extends Phase { var os: OutputStream = null var ps: PrintStream = null try { - os = File(outputDir + ".decompiled").outputStream() + os = File(outputDir + ".decompiled").outputStream(append = true) ps = new PrintStream(os) printToOutput(ps) } finally { diff --git a/compiler/src/dotty/tools/dotc/decompiler/Main.scala b/compiler/src/dotty/tools/dotc/decompiler/Main.scala index e3b0376b0912..c91afc45fb34 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/Main.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/Main.scala @@ -1,5 +1,7 @@ package dotty.tools.dotc.decompiler +import java.nio.file.{Files, Paths} + import dotty.tools.dotc import dotty.tools.dotc.core.Contexts._ @@ -10,6 +12,9 @@ import dotty.tools.dotc.core.Contexts._ object Main extends dotc.Driver { override protected def newCompiler(implicit ctx: Context): dotc.Compiler = { assert(ctx.settings.fromTasty.value) + val outputDir = ctx.settings.outputDir.value + if (outputDir != ".") + Files.deleteIfExists(Paths.get(outputDir + ".decompiled")) new TASTYDecompiler } diff --git a/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala b/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala index 1fefd15d32ad..7b3b9635192e 100644 --- a/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala +++ b/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala @@ -66,11 +66,10 @@ class ReadTastyTreesFromClasses extends FrontEnd { clsd.infoOrCompleter match { case info: ClassfileLoader => info.load(clsd) // sets cls.treeOrProvider and cls.moduleClass.treeProvider as a side-effect - def moduleClass = clsd.owner.info.member(className.moduleClassName).symbol - compilationUnit(clsd.classSymbol).orElse(compilationUnit(moduleClass)) case _ => - alreadyLoaded() } + def moduleClass = clsd.owner.info.member(className.moduleClassName).symbol + compilationUnit(clsd.classSymbol).orElse(compilationUnit(moduleClass)) case _ => cannotUnpickle(s"no class file was found") } diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index 40d89815c17e..38d9c006f7ab 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -29,9 +29,7 @@ class FromTastyTests extends ParallelTesting { val (step1, step2, step3) = compileTastyInDir("tests/pos", defaultOptions, blacklist = Set( "macro-deprecate-dont-touch-backquotedidents.scala", - - // Compiles wrong class - "simpleClass.scala", + "t247.scala", // Wrong number of arguments "i3130b.scala", @@ -84,6 +82,7 @@ class FromTastyTests extends ParallelTesting { blacklist = Set( "t7223.scala", + "t5428.scala", // Missing position "Course-2002-13.scala", diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 47f23f957d31..7eba42f4b582 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -433,7 +433,7 @@ trait ParallelTesting extends RunnerOrchestration { self => def hasTastyFileToClassName(f: JFile): String = targetDir.toPath.relativize(f.toPath).toString.dropRight(".hasTasty".length).replace('/', '.') - val classes = flattenFiles(targetDir).filter(isHasTastyFile).map(hasTastyFileToClassName) + val classes = flattenFiles(targetDir).filter(isHasTastyFile).map(hasTastyFileToClassName).sorted val reporter = TestReporter.reporter(realStdout, logLevel = diff --git a/tests/pos/simpleClass-2.decompiled b/tests/pos/simpleClass-2.decompiled new file mode 100644 index 000000000000..78291f123ca2 --- /dev/null +++ b/tests/pos/simpleClass-2.decompiled @@ -0,0 +1,14 @@ +================================================================================ +out/posTestFromTasty/pos/simpleClass-2/foo/A.class +-------------------------------------------------------------------------------- +package foo { + class A() extends foo.B() {} +} +-------------------------------------------------------------------------------- +================================================================================ +out/posTestFromTasty/pos/simpleClass-2/foo/B.class +-------------------------------------------------------------------------------- +package foo { + class B() extends Object() {} +} +-------------------------------------------------------------------------------- \ No newline at end of file diff --git a/tests/pos/simpleClass-2.scala b/tests/pos/simpleClass-2.scala new file mode 100644 index 000000000000..e81982c4cecc --- /dev/null +++ b/tests/pos/simpleClass-2.scala @@ -0,0 +1,6 @@ +package foo + +class B + +class A extends B + diff --git a/tests/pos/simpleClass.decompiled b/tests/pos/simpleClass.decompiled index 44fba6e33f55..f671605a89c7 100644 --- a/tests/pos/simpleClass.decompiled +++ b/tests/pos/simpleClass.decompiled @@ -4,4 +4,11 @@ out/posTestFromTasty/pos/simpleClass/foo/A.class package foo { class A() extends Object() {} } +-------------------------------------------------------------------------------- +================================================================================ +out/posTestFromTasty/pos/simpleClass/foo/B.class +-------------------------------------------------------------------------------- +package foo { + class B() extends foo.A() {} +} -------------------------------------------------------------------------------- \ No newline at end of file