Skip to content

Fix from tasty with multiple classes #4062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/decompiler/Main.scala
Original file line number Diff line number Diff line change
@@ -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._

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/test/dotty/tools/dotc/FromTastyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -84,6 +82,7 @@ class FromTastyTests extends ParallelTesting {
blacklist = Set(

"t7223.scala",
"t5428.scala",

// Missing position
"Course-2002-13.scala",
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/simpleClass-2.decompiled
Original file line number Diff line number Diff line change
@@ -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() {}
}
--------------------------------------------------------------------------------
6 changes: 6 additions & 0 deletions tests/pos/simpleClass-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package foo

class B

class A extends B

7 changes: 7 additions & 0 deletions tests/pos/simpleClass.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
--------------------------------------------------------------------------------