diff --git a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala index d49c08a75fe8..ad95bcd57429 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala @@ -7,6 +7,7 @@ import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.core.Phases.Phase import dotty.tools.dotc.core.tasty.TastyPrinter import dotty.tools.dotc.printing.DecompilerPrinter +import dotty.tools.dotc.tastyreflect.TastyImpl import dotty.tools.io.{File, Path} /** Phase that prints the trees in all loaded compilation units. @@ -36,15 +37,11 @@ class DecompilationPrinter extends Phase { private def printToOutput(out: PrintStream)(implicit ctx: Context): Unit = { val unit = ctx.compilationUnit - val pageWidth = ctx.settings.pageWidth.value - val printLines = ctx.settings.printLines.value - if (ctx.settings.printTasty.value) { new TastyPrinter(unit.pickled.head._2).printContents() } else { out.println(s"/** Decompiled from $unit */") - val printer = new DecompilerPrinter(ctx) - out.println(printer.toText(unit.tpdTree).mkString(pageWidth, printLines)) + out.print(TastyImpl.showSourceCode.showTree(unit.tpdTree)(ctx)) } } } diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index 37361ba2008d..65090bb5e5bc 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -5,13 +5,12 @@ import dotty.tools.dotc.Driver import dotty.tools.dotc.core.Contexts.Context import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory} import dotty.tools.repl.AbstractFileClassLoader -import dotty.tools.dotc.printing.DecompilerPrinter import scala.quoted.{Expr, Type} - import java.net.URLClassLoader -import Toolbox.{Settings, Run, Show} +import Toolbox.{Run, Settings, Show} +import dotty.tools.dotc.tastyreflect.TastyImpl class QuoteDriver extends Driver { import tpd._ @@ -42,10 +41,8 @@ class QuoteDriver extends Driver { def show(expr: Expr[_], settings: Settings[Show]): String = { def show(tree: Tree, ctx: Context): String = { - val printer = new DecompilerPrinter(ctx) - val pageWidth = ctx.settings.pageWidth.value(ctx) val tree1 = if (settings.rawTree) tree else (new TreeCleaner).transform(tree)(ctx) - printer.toText(tree1).mkString(pageWidth, false) + TastyImpl.showSourceCode.showTree(tree1)(ctx) } withTree(expr, show, settings) } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala b/compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala index 4c8e49ac3d32..51a20c91c0e3 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala @@ -31,6 +31,8 @@ class FlagSet(flags: Flags.FlagSet) extends scala.tasty.FlagSet { def isScala2X: Boolean = flags.is(Scala2x) def isDefaultParameterized: Boolean = flags.is(DefaultParameterized) def isStable: Boolean = flags.is(Stable) + def isParam: Boolean = flags.is(Param) + def isParamAccessor: Boolean = flags.is(ParamAccessor) override def toString: String = { val flags = List.newBuilder[String] @@ -60,6 +62,8 @@ class FlagSet(flags: Flags.FlagSet) extends scala.tasty.FlagSet { if (isScala2X) flags += "scala2x" if (isDefaultParameterized) flags += "defaultParameterized" if (isStable) flags += "stable" + if (isParam) flags += "param" + if (isParamAccessor) flags += "paramAccessor" flags.result().mkString("<", ",", ">") } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/FromSymbol.scala b/compiler/src/dotty/tools/dotc/tastyreflect/FromSymbol.scala index 38882c2c8e35..150149b38e0f 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/FromSymbol.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/FromSymbol.scala @@ -20,7 +20,9 @@ object FromSymbol { def packageDef(sym: Symbol)(implicit ctx: Context): PackageDefinition = PackageDefinitionImpl(sym) def classDef(cls: ClassSymbol)(implicit ctx: Context): tpd.Tree = { - val constr = tpd.DefDef(cls.unforcedDecls.find(_.isPrimaryConstructor).asTerm) + val constrSym = cls.unforcedDecls.find(_.isPrimaryConstructor) + if (!constrSym.exists) return tpd.EmptyTree + val constr = tpd.DefDef(constrSym.asTerm) val body = cls.unforcedDecls.filter(!_.isPrimaryConstructor).map(s => definition(s)) val superArgs = Nil // TODO tpd.ClassDef(cls, constr, body, superArgs) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala index eff0e56fa831..296b59f96c4c 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala @@ -11,9 +11,9 @@ import dotty.tools.dotc.reporting.Reporter import dotty.tools.dotc.reporting.diagnostic.MessageContainer import dotty.tools.dotc.util.SourcePosition -import scala.quoted +import scala.{quoted, tasty} import scala.reflect.ClassTag -import scala.tasty.util.{Show, ShowExtractors} +import scala.tasty.util.{Show, ShowExtractors, ShowSourceCode} object TastyImpl extends scala.tasty.Tasty { @@ -33,8 +33,7 @@ object TastyImpl extends scala.tasty.Tasty { def showExtractors: Show[this.type] = new ShowExtractors(this) - // TODO - // def showSourceCode: Show[this.type] = ??? + def showSourceCode: Show[this.type] = new ShowSourceCode(this) // ===== Contexts ================================================= @@ -129,10 +128,18 @@ object TastyImpl extends scala.tasty.Tasty { type Definition = tpd.Tree + object Definition extends DefinitionExtractor { + def unapply(x: Definition)(implicit ctx: Context): Boolean = + x.isInstanceOf[Trees.MemberDef[_]] + } + def DefinitionDeco(x: Definition): AbstractDefinition = new AbstractDefinition { def owner(implicit ctx: Context): Definition = FromSymbol.definition(x.symbol.owner) + def flags(implicit ctx: Contexts.Context): FlagSet = + new FlagSet(x.symbol.flags) + def mods(implicit ctx: Context): List[Modifier] = { val privateWithin = x.symbol.privateWithin val isProtected = x.symbol.is(core.Flags.Protected) diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index 243d6f2ded00..927221597344 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -38,7 +38,8 @@ class FromTastyTests extends ParallelTesting { "t3612.scala", ), recompilationBlacklist = Set( - "simpleCaseObject" + "simpleCaseObject", + "annot-bootstrap.scala", ) ).checkCompile() } diff --git a/library/src/scala/tasty/FlagSet.scala b/library/src/scala/tasty/FlagSet.scala index 22cc2d245937..571a0ffa564b 100644 --- a/library/src/scala/tasty/FlagSet.scala +++ b/library/src/scala/tasty/FlagSet.scala @@ -27,4 +27,6 @@ trait FlagSet { def isScala2X: Boolean // Imported from Scala2.x def isDefaultParameterized: Boolean // Method with default parameters def isStable: Boolean // Method that is assumed to be stable + def isParam: Boolean + def isParamAccessor: Boolean } diff --git a/library/src/scala/tasty/Tasty.scala b/library/src/scala/tasty/Tasty.scala index 164bebfac77c..bd3f1b4a0ee4 100644 --- a/library/src/scala/tasty/Tasty.scala +++ b/library/src/scala/tasty/Tasty.scala @@ -23,8 +23,7 @@ abstract class Tasty { tasty => def showExtractors: Show[tasty.type] - // TODO - // def showSourceCode: Show[tasty.type] + def showSourceCode: Show[tasty.type] // ===== Contexts ================================================= @@ -108,9 +107,15 @@ abstract class Tasty { tasty => type Definition <: Statement + val Definition: DefinitionExtractor + abstract class DefinitionExtractor { + def unapply(x: Definition)(implicit ctx: Context): Boolean + } + implicit def definitionClassTag: ClassTag[Definition] trait AbstractDefinition { + def flags(implicit ctx: Context): FlagSet def mods(implicit ctx: Context): List[Modifier] def owner(implicit ctx: Context): Definition def localContext(implicit ctx: Context): Context diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala new file mode 100644 index 000000000000..4e8d72b9ba71 --- /dev/null +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -0,0 +1,759 @@ +package scala.tasty +package util + +class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) { + import tasty._ + + def showTree(tree: Tree)(implicit ctx: Context): String = + (new Buffer).printTree(tree).result() + + def showTypeOrBoundsTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): String = + (new Buffer).printTypeOrBoundsTree(tpt).result() + + def showTypeOrBounds(tpe: TypeOrBounds)(implicit ctx: Context): String = + (new Buffer).printTypeOrBound(tpe).result() + + def showConstant(const: Constant)(implicit ctx: Context): String = + (new Buffer).printConstant(const).result() + + private class Buffer(implicit ctx: Context) { + + private[this] val sb: StringBuilder = new StringBuilder + + private[this] var indent: Int = 0 + def indented(printIndented: => Unit): Unit = { + indent += 1 + printIndented + indent -= 1 + } + + def result(): String = sb.result() + + def lineBreak(): String = "\n" + (" " * indent) + + def printTree(tree: Tree): Buffer = tree match { + case tree @ PackageClause(Term.Ident(name), stats) => + val stats1 = stats.collect { + case stat@Definition() if !(stat.flags.isObject && stat.flags.isLazy) => stat + case stat@Import(_, _) => stat + } + + if (name == "") { + printTrees(stats1, lineBreak()) + } else { + this += "package " += name += " {" + indented { + this += lineBreak() + printTrees(stats1, lineBreak()) + } + this += lineBreak() += "}" += lineBreak() + } + + case Import(expr, selectors) => + this += "import " + printTree(expr) + this += "." + printImportSelectors(selectors) + + case cdef @ ClassDef(name, DefDef(_, targs, argss, _, _), parents, self, stats) => + val flags = cdef.flags + if (flags.isFinal && !flags.isObject) this += "final " + if (flags.isCase) this += "case " + + if (flags.isObject) this += "object " += name.stripSuffix("$") + else this += "class " += name + + if (!flags.isObject) { + printTargsDefs(targs) + val it = argss.iterator + while (it.hasNext) + printArgsDefs(it.next()) + } + + val parents1 = parents.filter { + case Term.Apply(Term.Select(Term.New(tpt), _, _), _) => !Types.JavaLangObject.unapply(tpt.tpe) + case TypeTree.TypeSelect(Term.Select(Term.Ident("_root_"), "scala", _), "Product") => false + case _ => true + } + if (parents1.nonEmpty) { + sb.append(" extends") + parents1.foreach { + case parent@Term.Apply(Term.TypeApply(Term.Select(Term.New(tpt), _, _), targs), args) => + this += " " + printTypeTree(tpt) + this += "[" + printTypeTrees(targs, ", ") + this += "]" + if (args.nonEmpty) { + this += "(" + printTrees(args, ", ") + this += ")" + } + + case parent@Term.Apply(Term.Select(Term.New(tpt), _, _), args) => + this += " " + printTypeTree(tpt) + if (args.nonEmpty) { + this += "(" + printTrees(args, ", ") + this += ")" + } + + case parent@TypeTree() => + sb.append(" ") + printTypeTree(parent) + } + } + + val stats1 = stats.collect { + case stat@Definition() if !stat.flags.isParam && !stat.flags.isParamAccessor => stat + case stat@Import(_, _) => stat + case stat@Term() => stat + } + if (stats1.nonEmpty) { + this += " {" + indented { + this += lineBreak() + printTrees(stats1, lineBreak()) + } + this += lineBreak() += "}" + } + this + + case tdef@TypeDef(name, rhs) => + this += "type " + printTargDef(tdef) + + case vdef@ValDef(name, tpt, rhs) => + val flags = vdef.flags + if (flags.isOverride) this += "override " + + if (flags.isLazy) this += "lazy " + if (vdef.flags.isMutable) this += "var " + else this += "val " + + this += name += ": " + printTypeTree(tpt) + rhs match { + case Some(tree) => + this += " = " + printTree(tree) + case None => + this + } + + case ddef@DefDef(name, targs, argss, tpt, rhs) => + val flags = ddef.flags + if (flags.isOverride) sb.append("override ") + + this += "def " += name + printTargsDefs(targs) + val it = argss.iterator + while (it.hasNext) + printArgsDefs(it.next()) + this += ": " + printTypeTree(tpt) + rhs match { + case Some(tree) => + this += " = " + printTree(tree) + case None => + } + this + + case tree@Term.Ident(name) => + printType(tree.tpe) + + case Term.Select(qual, name, sig) => + printTree(qual) + if (name != "") + this += "." += name + this + + case Term.Literal(const) => + printConstant(const) + + case Term.This(id) => + this += "this" // TODO add id + + case Term.New(tpt) => + this += "new " + printTypeTree(tpt) + + case Term.NamedArg(name, arg) => + this += name += " = " + printTree(arg) + + case SpecialOp("throw", expr :: Nil) => + this += "throw " + printTree(expr) + + case Term.Apply(fn, args) => + printTree(fn) + this += "(" + printTrees(args, ", ") + this += ")" + + case Term.TypeApply(fn, args) => + printTree(fn) + this += "[" + printTypeTrees(args, ", ") + this += "]" + + case Term.Super(qual, tptOpt) => + printTree(qual) + this += ".super" + // TODO use tptOpt? + + case Term.Typed(term, tpt) => + tpt.tpe match { + case Types.Repeated(_) => + printTree(term) + case _ => + this += "(" + printTree(term) + this += ": " + printTypeTree(tpt) + this += ")" + } + + case Term.Assign(lhs, rhs) => + printTree(lhs) + this += " = " + printTree(rhs) + + case Term.Block(stats, expr) => + expr match { + case Term.Lambda(_, _) => + // Decompile lambda from { def annon$(...) = ...; closure(annon$, ...)} + val DefDef(_, _, args :: Nil, _, Some(rhs)) :: Nil = stats + this += "(" + printArgsDefs(args) + this += " => " + printTree(rhs) + this += ")" + + case Term.Apply(Term.Ident("while$"), _) => + val DefDef("while$", _, _, _, Some(Term.If(cond, Term.Block(body :: Nil, _), _))) = stats.head + this += "while (" + printTree(cond) + this += ") " + printTree(body) + + case Term.Apply(Term.Ident("doWhile$"), _) => + val DefDef("doWhile$", _, _, _, Some(Term.Block(List(body), Term.If(cond, _, _)))) = stats.head + this += "do " + printTree(body) + this += " while (" + printTree(cond) + this += ")" + + case _ => + this += "{" + indented { + if (!stats.isEmpty) { + this += lineBreak() + printTrees(stats, lineBreak()) + } + this += lineBreak() + printTree(expr) + } + this += lineBreak() += "}" + } + + case Term.Inlined(call, bindings, expansion) => + sb.append("{ // inlined") + indented { + if (!bindings.isEmpty) { + this += lineBreak() + printTrees(bindings, lineBreak()) + } + this += lineBreak() + printTree(expansion) + } + this += lineBreak() += "}" + + case Term.Lambda(meth, tpt) => + // Printed in Term.Block branch + this + + case Term.If(cond, thenp, elsep) => + this += "if (" + printTree(cond) + this += ") " + printTree(thenp) + this+= " else " + printTree(elsep) + + case Term.Match(selector, cases) => + printTree(selector) + this += " match {" + indented { + this += lineBreak() + printCases(cases, lineBreak()) + } + this += lineBreak() += "}" + + case Term.Try(body, cases, finallyOpt) => + this += "try " + printTree(body) + if (cases.nonEmpty) { + this += " catch " + printCases(cases, lineBreak()) + } + finallyOpt match { + case Some(t) => + this += " finally " + printTree(t) + case None => + this + } + + case Term.Return(expr) => + this += "}" + printTree(expr) + + case Term.Repeated(elems) => + printTrees(elems, ", ") + + case _ => + throw new MatchError(tree.show) + + } + + def printTrees(trees: List[Tree], sep: String): Buffer = { + def printSeparated(list: List[Tree]): Unit = list match { + case Nil => + case x :: Nil => printTree(x) + case x :: xs => + printTree(x) + this += sep + printSeparated(xs) + } + printSeparated(trees) + this + } + + def printImportSelectors(selectors: List[ImportSelector]): Buffer = { + def printSeparated(list: List[ImportSelector]): Unit = list match { + case Nil => + case x :: Nil => printImportSelector(x) + case x :: xs => + printImportSelector(x) + this += ", " + printSeparated(xs) + } + this += "{" + printSeparated(selectors) + this += "}" + } + + def printCases(cases: List[CaseDef], sep: String): Buffer = { + def printSeparated(list: List[CaseDef]): Unit = list match { + case Nil => + case x :: Nil => printCase(x) + case x :: xs => + printCase(x) + this += sep + printSeparated(xs) + } + printSeparated(cases) + this + } + + def printPatterns(cases: List[Pattern], sep: String): Buffer = { + def printSeparated(list: List[Pattern]): Unit = list match { + case Nil => + case x :: Nil => printPattern(x) + case x :: xs => + printPattern(x) + this += sep + printSeparated(xs) + } + printSeparated(cases) + this + } + + def printTypeTrees(typesTrees: List[TypeTree], sep: String): Buffer = { + def printSeparated(list: List[TypeTree]): Unit = list match { + case Nil => + case x :: Nil => printTypeTree(x) + case x :: xs => + printTypeTree(x) + this += sep + printSeparated(xs) + } + printSeparated(typesTrees) + this + } + + def printTypesOrBounds(types: List[TypeOrBounds], sep: String): Buffer = { + def printSeparated(list: List[TypeOrBounds]): Unit = list match { + case Nil => + case x :: Nil => printTypeOrBound(x) + case x :: xs => + printTypeOrBound(x) + this += sep + printSeparated(xs) + } + printSeparated(types) + this + } + + def printTargsDefs(targs: List[TypeDef]): Unit = { + if (!targs.isEmpty) { + def printSeparated(list: List[TypeDef]): Unit = list match { + case Nil => + case x :: Nil => printTargDef(x) + case x :: xs => + printTargDef(x) + this += ", " + printSeparated(xs) + } + + this += "[" + printSeparated(targs) + this += "]" + } + } + + def printTargDef(arg: TypeDef): Buffer = { + val TypeDef(name, rhs) = arg + this += name + rhs match { + case TypeBoundsTree(lo, hi) => + lo match { + case TypeTree.Synthetic() => this + case _ => + this += " >: " + printTypeTree(lo) + } + hi match { + case TypeTree.Synthetic() => this + case _ => + this += " <: " + printTypeTree(hi) + } + case tpt@TypeTree() => + this += " = " + printTypeTree(tpt) + } + } + + def printArgsDefs(args: List[ValDef]): Unit = { + this += "(" + args match { + case Nil => + case arg :: _ => + if (arg.flags.isErased) this += "erased " + if (arg.flags.isImplicit) this += "implicit " + } + + def printSeparated(list: List[ValDef]): Unit = list match { + case Nil => + case x :: Nil => printArgDef(x) + case x :: xs => + printArgDef(x) + this += ", " + printSeparated(xs) + } + + printSeparated(args) + this += ")" + } + + def printArgDef(arg: ValDef): Unit = { + val ValDef(name, tpt, rhs) = arg + this += name += ": " + printTypeTree(tpt) + } + + def printCase(caseDef: CaseDef): Buffer = { + val CaseDef(pat, guard, body) = caseDef + this += "case " + printPattern(pat) + guard match { + case Some(t) => + this += " if " + printTree(t) + case None => + } + this += " =>" + indented { + this += lineBreak() + printTree(body) + } + this + } + + def printPattern(pattern: Pattern): Buffer = pattern match { + case Pattern.Value(v) => + v match { + case Term.Ident("_") => this += "_" + case _ => printTree(v) + } + + case Pattern.Bind(name, Pattern.Value(Term.Ident("_"))) => + this += name + + case Pattern.Bind(name, Pattern.TypeTest(tpt)) => + this += name += ": " + printTypeTree(tpt) + + case Pattern.Bind(name, pattern) => + this += name += "@ " + printPattern(pattern) + + case Pattern.Unapply(fun, implicits, patterns) => + printTree(fun) + this += "(" + printPatterns(patterns, ", ") + this += ")" + + case Pattern.Alternative(trees) => + printPatterns(trees, " | ") + + case Pattern.TypeTest(tpt) => + this + + } + + def printConstant(const: Constant): Buffer = const match { + case Constant.Unit() => this += "()" + case Constant.Null() => this += "null" + case Constant.Boolean(v) => this += v.toString + case Constant.Byte(v) => this += v + case Constant.Short(v) => this += v + case Constant.Int(v) => this += v + case Constant.Long(v) => this += v += "L" + case Constant.Float(v) => this += v + case Constant.Double(v) => this += v + case Constant.Char(v) => this += '\'' += v.toString += '\'' // TODO escape char + case Constant.String(v) => this += '"' += v.toString += '"' // TODO escape string + } + + def printTypeOrBoundsTree(tpt: TypeOrBoundsTree): Buffer = tpt match { + case TypeBoundsTree(lo, hi) => + this += " >: " + printTypeTree(lo) + this += " <: " + printTypeTree(hi) + case tpt@Type() => + printType(tpt) + } + + def printTypeTree(tree: TypeTree): Buffer = tree match { + case TypeTree.Synthetic() => + printType(tree.tpe) + + case TypeTree.TypeIdent(name) => + printType(tree.tpe) + + case TypeTree.TypeSelect(qual, name) => + (qual: Any) match { + case qual @ TypeTree.TypeIdent(_) => printTypeTree(qual) // FIXME: qual is of type Tree buy we are getting a TypeTree qualifier + case _ => printTree(qual) + } + this += "." += name + + case TypeTree.Singleton(ref) => + printTree(ref) + + case TypeTree.Refined(tpt, refinements) => + printTypeTree(tpt) + this += " {" + indented { + this += lineBreak() + printTrees(refinements, "; ") + } + this += lineBreak() += "}" + + case TypeTree.Applied(tpt, args) => + printTypeTree(tpt) + this += "[" + printTypeTrees(args, ", ") + this += "]" + + case TypeTree.Annotated(tpt, annots) => + printTypeTree(tpt) + // TODO print annots + + case TypeTree.And(left, right) => + printTypeTree(left) + this += " & " + printTypeTree(right) + + case TypeTree.Or(left, right) => + printTypeTree(left) + this += " | " + printTypeTree(right) + + case TypeTree.ByName(result) => + this += "=> " + printTypeTree(result) + + case _ => + throw new MatchError(tree.show) + + } + + def printTypeOrBound(tpe: TypeOrBounds): Buffer = tpe match { + case tpe@TypeBounds(lo, hi) => + this += " >: " + printType(lo) + this += " <: " + printType(hi) + case tpe@Type() => printType(tpe) + } + + def printType(tpe: Type): Buffer = tpe match { + case Type.ConstantType(const) => + printConstant(const) + + case Type.SymRef(sym, prefix) => + prefix match { + case Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => + case prefix@Type.SymRef(ClassDef(_, _, _, _, _), _) => + printType(prefix) + this += "#" + case prefix@Type() => + printType(prefix) + this += "." + case prefix@NoPrefix() => + } + printDefinitionName(sym) + + case Type.TermRef(name, prefix) => + prefix match { + case prefix@Type() => + printType(prefix) + if (name != "package") + this += "." += name + this + case NoPrefix() => + this += name + } + + case Type.TypeRef(name, prefix) => + prefix match { + case NoPrefix() => + case prefix@Type() => + printType(prefix) + this += "." + } + this += name.stripSuffix("$") + + case Type.Refinement(parent, name, info) => + printType(parent) + // TODO add refinements + + case Type.AppliedType(tp, args) => + printType(tp) + this += "[" + printTypesOrBounds(args, ", ") + this += "]" + + case Type.AnnotatedType(tp, annot) => + printType(tp) + + case Type.AndType(left, right) => + printType(left) + this += " & " + printType(right) + + case Type.OrType(left, right) => + printType(left) + this += " | " + printType(right) + + case Type.ByNameType(tp) => + this += " => " + printType(tp) + + case Type.ThisType(tp) => + printType(tp) + + case _ => + throw new MatchError(tpe.show) + } + + def printImportSelector(sel: ImportSelector): Buffer = sel match { + case SimpleSelector(Id(name)) => this += name + case OmitSelector(Id(name)) => this += name += " => _" + case RenameSelector(Id(name), Id(newName)) => this += name += " => " += newName + } + + def printDefinitionName(sym: Definition): Buffer = sym match { + case ValDef(name, _, _) => this += name + case DefDef(name, _, _, _, _) => this += name + case ClassDef(name, _, _, _, _) => this += name.stripSuffix("$") + case TypeDef(name, _) => this += name + case PackageDef(name, _) => this += name + } + + def +=(x: Boolean): this.type = { sb.append(x); this } + def +=(x: Byte): this.type = { sb.append(x); this } + def +=(x: Short): this.type = { sb.append(x); this } + def +=(x: Int): this.type = { sb.append(x); this } + def +=(x: Long): this.type = { sb.append(x); this } + def +=(x: Float): this.type = { sb.append(x); this } + def +=(x: Double): this.type = { sb.append(x); this } + def +=(x: Char): this.type = { sb.append(x); this } + def +=(x: String): this.type = { sb.append(x); this } + + } + + + private object SpecialOp { + def unapply(arg: Term)(implicit ctx: Context): Option[(String, List[Term])] = arg match { + case arg@Term.Apply(fn, args) => + fn.tpe match { + case Type.SymRef(DefDef(op, _, _, _, _), Type.ThisType(Type.SymRef(PackageDef("", _), NoPrefix()))) => + Some((op, args)) + case _ => None + } + case _ => None + } + } + + // TODO Provide some of these in scala.tasty.Tasty.scala and implement them using checks on symbols for performance + private object Types { + + object JavaLangObject { + def unapply(tpe: Type)(implicit ctx: Context): Boolean = tpe match { + case Type.TypeRef("Object", Type.SymRef(PackageDef("lang", _), Type.ThisType(Type.SymRef(PackageDef("java", _), NoPrefix())))) => true + case _ => false + } + } + + object Repeated { + def unapply(tpe: Type)(implicit ctx: Context): Option[Type] = tpe match { + case Type.AppliedType(Type.TypeRef("", ScalaPackage()), (tp@Type()) :: Nil) => Some(tp) + case _ => None + } + } + + object ScalaPackage { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match { + case Type.SymRef(PackageDef("scala", _), Type.ThisType(RootPackage())) => true + case _ => false + } + } + + object RootPackage { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match { + case Type.SymRef(PackageDef("", _), NoPrefix()) => true + case _ => false + } + } + + object EmptyPackage { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match { + case Type.SymRef(PackageDef("", _), NoPrefix() | Type.ThisType(RootPackage())) => true + case _ => false + } + } + } + + +} diff --git a/project/scripts/cmdTests b/project/scripts/cmdTests index a7ad58c9272a..1f78f076c7d9 100755 --- a/project/scripts/cmdTests +++ b/project/scripts/cmdTests @@ -38,7 +38,7 @@ grep -qe "$EXPECTED_OUTPUT" "$tmp" # check that `sbt dotc -decompile` runs echo "testing sbt dotc -decompile" "$SBT" ";dotc -decompile -color:never -classpath $OUT $MAIN" > "$tmp" -grep -qe "def main(args: Array\[String\]): Unit =" "$tmp" +grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp" echo "testing sbt dotr with no -classpath" clear_out "$OUT" @@ -48,11 +48,11 @@ grep -qe "$EXPECTED_OUTPUT" "$tmp" echo "testing loading tasty from .tasty file in jar" clear_out "$OUT" "$SBT" ";dotc -d $OUT/out.jar -Yemit-tasty $SOURCE; dotc -decompile -classpath $OUT/out.jar -color:never $MAIN" > "$tmp" -grep -qe "def main(args: Array\[String\]): Unit =" "$tmp" +grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp" echo "testing scala.quoted.Expr.run from sbt dotr" "$SBT" ";dotty-compiler/compile ;dotc -classpath $COMPILER_CP tests/run-with-compiler/quote-run.scala; dotr -with-compiler Test" > "$tmp" -grep -qe "val a: Int = 3" "$tmp" +grep -qe "val a: scala.Int = 3" "$tmp" # setup for `dotc`/`dotr` script tests diff --git a/tests/pos/classWithCompObj.decompiled b/tests/pos/classWithCompObj.decompiled index 819bd7c90943..1cfb9b6b679d 100644 --- a/tests/pos/classWithCompObj.decompiled +++ b/tests/pos/classWithCompObj.decompiled @@ -1,3 +1,3 @@ /** Decompiled from out/posTestFromTasty/pos/classWithCompObj/Foo.class */ -class Foo() {} -object Foo {} \ No newline at end of file +class Foo() +object Foo \ No newline at end of file diff --git a/tests/pos/conforms.decompiled b/tests/pos/conforms.decompiled new file mode 100644 index 000000000000..667ea563055a --- /dev/null +++ b/tests/pos/conforms.decompiled @@ -0,0 +1,4 @@ +/** Decompiled from out/posTestFromTasty/pos/conforms/Test.class */ +object Test { + def f[A, B](x: A)(implicit e: scala.Predef.<:<[A, B]): B = e.apply(x) +} \ No newline at end of file diff --git a/tests/pos/i4526-2.decompiled b/tests/pos/i4526-2.decompiled index b53220574bf5..93bd7a2d83c4 100644 --- a/tests/pos/i4526-2.decompiled +++ b/tests/pos/i4526-2.decompiled @@ -1,2 +1,2 @@ /** Decompiled from out/posTestFromTasty/pos/i4526-2/Foo.class */ -class Foo(x: Int, y: Int) {} +class Foo(x: scala.Int, y: scala.Int) diff --git a/tests/pos/lambda.decompiled b/tests/pos/lambda.decompiled index d8f61efaa99a..ddcdfd5fe5f4 100644 --- a/tests/pos/lambda.decompiled +++ b/tests/pos/lambda.decompiled @@ -2,11 +2,10 @@ package foo { class Foo() { { - (x: Int) => - { - 2 - } + ((x: scala.Int) => { + 2 + }) } - val a: Int => Int = (x: Int) => x.*(x) + val a: scala.Function1[scala.Int, scala.Int] = ((x: scala.Int) => x.*(x)) } -} \ No newline at end of file +} diff --git a/tests/pos/methodTypes.decompiled b/tests/pos/methodTypes.decompiled index da19e193f895..5b1032d93114 100644 --- a/tests/pos/methodTypes.decompiled +++ b/tests/pos/methodTypes.decompiled @@ -1,6 +1,6 @@ /** Decompiled from out/posTestFromTasty/pos/methodTypes/Foo.class */ class Foo() { - val x: Int = 1 - def y: Int = 2 - def z(): Int = 3 -} \ No newline at end of file + val x: scala.Int = 1 + def y: scala.Int = 2 + def z(): scala.Int = 3 +} diff --git a/tests/pos/simple-repeated-args.decompiled b/tests/pos/simple-repeated-args.decompiled new file mode 100644 index 000000000000..546471729713 --- /dev/null +++ b/tests/pos/simple-repeated-args.decompiled @@ -0,0 +1,4 @@ +/** Decompiled from out/posTestFromTasty/pos/simple-repeated-args/Foo.class */ +class Foo() { + scala.List.apply[scala.Any](1, "2", '3') +} diff --git a/tests/pos/simple-repeated-args.scala b/tests/pos/simple-repeated-args.scala new file mode 100644 index 000000000000..2f7b104b7a80 --- /dev/null +++ b/tests/pos/simple-repeated-args.scala @@ -0,0 +1,3 @@ +class Foo { + List(1, "2", '3') +} diff --git a/tests/pos/simpleCaseObject.decompiled b/tests/pos/simpleCaseObject.decompiled index 66dac789c7b2..e6f5a5d4ea94 100644 --- a/tests/pos/simpleCaseObject.decompiled +++ b/tests/pos/simpleCaseObject.decompiled @@ -1,16 +1,14 @@ /** Decompiled from out/posTestFromTasty/pos/simpleCaseObject/foo/Foo.class */ package foo { case object Foo { - override def hashCode(): Int = 1045991777 - override def toString(): String = "Foo" - override def canEqual(that: Any): Boolean = - that.isInstanceOf[foo.Foo @unchecked] - override def productArity: Int = 0 - override def productPrefix: String = "Foo" - override def productElement(n: Int): Any = - n match - { - case _ => throw new IndexOutOfBoundsException(n.toString()) - } + override def hashCode(): scala.Int = 1045991777 + override def toString(): java.lang.String = "Foo" + override def canEqual(that: scala.Any): scala.Boolean = that.isInstanceOf[foo.Foo] + override def productArity: scala.Int = 0 + override def productPrefix: java.lang.String = "Foo" + override def productElement(n: scala.Int): scala.Any = n match { + case _ => + throw new java.lang.IndexOutOfBoundsException(n.toString()) + } } -} \ No newline at end of file +} diff --git a/tests/pos/simpleClass-2.decompiled b/tests/pos/simpleClass-2.decompiled index b8f785f36508..577cb882fa08 100644 --- a/tests/pos/simpleClass-2.decompiled +++ b/tests/pos/simpleClass-2.decompiled @@ -1,8 +1,8 @@ /** Decompiled from out/posTestFromTasty/pos/simpleClass-2/foo/A.class */ package foo { - class A() extends foo.B() {} + class A() extends foo.B } /** Decompiled from out/posTestFromTasty/pos/simpleClass-2/foo/B.class */ package foo { - class B() {} + class B() } \ No newline at end of file diff --git a/tests/pos/simpleClass.decompiled b/tests/pos/simpleClass.decompiled index 794c0baff401..eaf7c5f6d686 100644 --- a/tests/pos/simpleClass.decompiled +++ b/tests/pos/simpleClass.decompiled @@ -1,8 +1,8 @@ /** Decompiled from out/posTestFromTasty/pos/simpleClass/foo/A.class */ package foo { - class A() {} + class A() } /** Decompiled from out/posTestFromTasty/pos/simpleClass/foo/B.class */ package foo { - class B() extends foo.A() {} + class B() extends foo.A } \ No newline at end of file diff --git a/tests/pos/simpleDoWhile.decompiled b/tests/pos/simpleDoWhile.decompiled index e8f316aec6db..3e763ba2dc44 100644 --- a/tests/pos/simpleDoWhile.decompiled +++ b/tests/pos/simpleDoWhile.decompiled @@ -1,12 +1,9 @@ /** Decompiled from out/posTestFromTasty/pos/simpleDoWhile/Foo.class */ class Foo() { - def foo: Unit = - { - var i: Int = 1 - do - { - i = 0 - } - while (i.!=(0)) - } + def foo: scala.Unit = { + var i: scala.Int = 1 + do { + i = 0 + } while (i.!=(0)) + } } \ No newline at end of file diff --git a/tests/pos/simpleWhile.decompiled b/tests/pos/simpleWhile.decompiled index 1fec54f3fd45..269c17ab1aa3 100644 --- a/tests/pos/simpleWhile.decompiled +++ b/tests/pos/simpleWhile.decompiled @@ -1,11 +1,9 @@ /** Decompiled from out/posTestFromTasty/pos/simpleWhile/Foo.class */ class Foo() { - def foo: Unit = - { - var i: Int = 1 - while (i.!=(0)) - { - i = 0 - } + def foo: scala.Unit = { + var i: scala.Int = 1 + while (i.!=(0)) { + i = 0 } + } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3823-b.check b/tests/run-with-compiler/i3823-b.check index ff7845fd9de5..44e4b1777f34 100644 --- a/tests/run-with-compiler/i3823-b.check +++ b/tests/run-with-compiler/i3823-b.check @@ -1,4 +1,4 @@ { - val z: Int = 2 + val z: scala.Int = 2 () } diff --git a/tests/run-with-compiler/i3823-c.check b/tests/run-with-compiler/i3823-c.check index ff7845fd9de5..44e4b1777f34 100644 --- a/tests/run-with-compiler/i3823-c.check +++ b/tests/run-with-compiler/i3823-c.check @@ -1,4 +1,4 @@ { - val z: Int = 2 + val z: scala.Int = 2 () } diff --git a/tests/run-with-compiler/i3823.check b/tests/run-with-compiler/i3823.check index ff7845fd9de5..44e4b1777f34 100644 --- a/tests/run-with-compiler/i3823.check +++ b/tests/run-with-compiler/i3823.check @@ -1,4 +1,4 @@ { - val z: Int = 2 + val z: scala.Int = 2 () } diff --git a/tests/run-with-compiler/i3847-b.check b/tests/run-with-compiler/i3847-b.check index 61f2184f31f4..dd95b594c682 100644 --- a/tests/run-with-compiler/i3847-b.check +++ b/tests/run-with-compiler/i3847-b.check @@ -1,3 +1,3 @@ { - new Array[List[Int]](1) + new scala.Array[scala.List[scala.Int]][collection.immutable.List[scala.Int]](1) } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847.check b/tests/run-with-compiler/i3847.check index 9a4f9f8817e5..7928d7310eb3 100644 --- a/tests/run-with-compiler/i3847.check +++ b/tests/run-with-compiler/i3847.check @@ -1 +1 @@ -dotty.runtime.Arrays.newGenericArray[Int](3)(reflect.ClassTag.Int) \ No newline at end of file +dotty.runtime.Arrays.newGenericArray[scala.Int](3)(scala.reflect.ClassTag.Int) \ No newline at end of file diff --git a/tests/run-with-compiler/i3876-b.check b/tests/run-with-compiler/i3876-b.check index 2a3f8f91f175..7746fc33aaf4 100644 --- a/tests/run-with-compiler/i3876-b.check +++ b/tests/run-with-compiler/i3876-b.check @@ -1,6 +1,6 @@ 6 { - val x$1: Int = 3 - def f(x: Int): Int = x.+(x) + val x$1: scala.Int = 3 + def f(x: scala.Int): scala.Int = x.+(x) f(x$1) } diff --git a/tests/run-with-compiler/i3876-c.check b/tests/run-with-compiler/i3876-c.check index 23220a84d93a..e298ecc3f648 100644 --- a/tests/run-with-compiler/i3876-c.check +++ b/tests/run-with-compiler/i3876-c.check @@ -1,11 +1,8 @@ 6 { - val x$1: Int = 3 - val f: - Function1[Int, Int] - { - def apply(x: Int): Int - } - = (x: Int) => x.+(x) - (f: (x: Int) => Int).apply(x$1) + val x$1: scala.Int = 3 + val f: scala.Function1[scala.Int, scala.Int] { + def apply(x: scala.Int): scala.Int + } = ((x: scala.Int) => x.+(x)) + (f: scala.Function1[scala.Int, scala.Int]).apply(x$1) } diff --git a/tests/run-with-compiler/i3876-d.check b/tests/run-with-compiler/i3876-d.check index 15c559cd0246..28e005e932dc 100644 --- a/tests/run-with-compiler/i3876-d.check +++ b/tests/run-with-compiler/i3876-d.check @@ -1,8 +1,7 @@ 6 { - val x$1: Int = 3 - /* inlined from Test*/ - { - x$1.+(x$1) - } + val x$1: scala.Int = 3 + { // inlined + x$1.+(x$1) + } } diff --git a/tests/run-with-compiler/i3876.check b/tests/run-with-compiler/i3876.check index 643927062fa2..746b7f8778a7 100644 --- a/tests/run-with-compiler/i3876.check +++ b/tests/run-with-compiler/i3876.check @@ -1,5 +1,5 @@ 6 { - val x$1: Int = 3 + val x$1: scala.Int = 3 x$1.+(x$1) } diff --git a/tests/run-with-compiler/i3947.check b/tests/run-with-compiler/i3947.check index 12e71232cc86..e9858aef278e 100644 --- a/tests/run-with-compiler/i3947.check +++ b/tests/run-with-compiler/i3947.check @@ -1,12 +1,12 @@ -classOf[Object].getCanonicalName() +scala.Predef.classOf[lang.Object].getCanonicalName() java.lang.Object -classOf[Object].getCanonicalName() +scala.Predef.classOf[lang.Object].getCanonicalName() java.lang.Object -classOf[Object].getCanonicalName() +scala.Predef.classOf[lang.Object].getCanonicalName() java.lang.Object -classOf[Object].getCanonicalName() +scala.Predef.classOf[lang.Object].getCanonicalName() java.lang.Object diff --git a/tests/run-with-compiler/i3947b.check b/tests/run-with-compiler/i3947b.check index dd712b7023e2..ecebc25acde9 100644 --- a/tests/run-with-compiler/i3947b.check +++ b/tests/run-with-compiler/i3947b.check @@ -1,9 +1,9 @@ -classOf[Boolean].getCanonicalName() +scala.Predef.classOf[scala.Boolean].getCanonicalName() boolean -classOf[Byte].getCanonicalName() +scala.Predef.classOf[scala.Byte].getCanonicalName() byte -classOf[Char].getCanonicalName() +scala.Predef.classOf[scala.Char].getCanonicalName() char diff --git a/tests/run-with-compiler/i3947b2.check b/tests/run-with-compiler/i3947b2.check index 2b18c14d8b71..7c5e630bb5a2 100644 --- a/tests/run-with-compiler/i3947b2.check +++ b/tests/run-with-compiler/i3947b2.check @@ -1,9 +1,9 @@ -classOf[Short].getCanonicalName() +scala.Predef.classOf[scala.Short].getCanonicalName() short -classOf[Int].getCanonicalName() +scala.Predef.classOf[scala.Int].getCanonicalName() int -classOf[Long].getCanonicalName() +scala.Predef.classOf[scala.Long].getCanonicalName() long diff --git a/tests/run-with-compiler/i3947b3.check b/tests/run-with-compiler/i3947b3.check index 074ba0e0693d..d2d1b24c0edf 100644 --- a/tests/run-with-compiler/i3947b3.check +++ b/tests/run-with-compiler/i3947b3.check @@ -1,9 +1,9 @@ -classOf[Float].getCanonicalName() +scala.Predef.classOf[scala.Float].getCanonicalName() float -classOf[Double].getCanonicalName() +scala.Predef.classOf[scala.Double].getCanonicalName() double -classOf[Unit].getCanonicalName() +scala.Predef.classOf[scala.Unit].getCanonicalName() void diff --git a/tests/run-with-compiler/i3947c.check b/tests/run-with-compiler/i3947c.check index dc02862f409a..ab30e827c9ab 100644 --- a/tests/run-with-compiler/i3947c.check +++ b/tests/run-with-compiler/i3947c.check @@ -1,9 +1,9 @@ -classOf[scala.runtime.Null$].getCanonicalName() +scala.Predef.classOf[runtime.Null].getCanonicalName() scala.runtime.Null$ -classOf[scala.runtime.Nothing$].getCanonicalName() +scala.Predef.classOf[runtime.Nothing].getCanonicalName() scala.runtime.Nothing$ -classOf[String].getCanonicalName() +scala.Predef.classOf[lang.String].getCanonicalName() java.lang.String diff --git a/tests/run-with-compiler/i3947d.check b/tests/run-with-compiler/i3947d.check index c54f219fedfc..996b43603ef0 100644 --- a/tests/run-with-compiler/i3947d.check +++ b/tests/run-with-compiler/i3947d.check @@ -1,9 +1,9 @@ -classOf[Foo].getCanonicalName() +scala.Predef.classOf[Foo].getCanonicalName() Foo -classOf[Foo#Bar].getCanonicalName() +scala.Predef.classOf[Foo#Bar].getCanonicalName() Foo.Bar -classOf[Foo.Baz].getCanonicalName() +scala.Predef.classOf[Foo.Baz].getCanonicalName() Foo.Baz diff --git a/tests/run-with-compiler/i3947d2.check b/tests/run-with-compiler/i3947d2.check index e0caebc39549..10d70e743b15 100644 --- a/tests/run-with-compiler/i3947d2.check +++ b/tests/run-with-compiler/i3947d2.check @@ -1,9 +1,9 @@ -classOf[foo.Foo].getCanonicalName() +scala.Predef.classOf[foo.Foo].getCanonicalName() foo.Foo -classOf[foo.Foo#Bar].getCanonicalName() +scala.Predef.classOf[foo.Foo#Bar].getCanonicalName() foo.Foo.Bar -classOf[foo.Foo.Baz].getCanonicalName() +scala.Predef.classOf[foo.Foo.Baz].getCanonicalName() foo.Foo.Baz diff --git a/tests/run-with-compiler/i3947e.check b/tests/run-with-compiler/i3947e.check index 0d25c46e9bee..4483ce80170b 100644 --- a/tests/run-with-compiler/i3947e.check +++ b/tests/run-with-compiler/i3947e.check @@ -1,9 +1,9 @@ -classOf[Object].getCanonicalName() +scala.Predef.classOf[lang.Object].getCanonicalName() java.lang.Object -classOf[Array[Foo]].getCanonicalName() +scala.Predef.classOf[scala.Array[Foo]].getCanonicalName() Foo[] -classOf[Array[Array[Foo]]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Array[Foo]]].getCanonicalName() Foo[][] diff --git a/tests/run-with-compiler/i3947f.check b/tests/run-with-compiler/i3947f.check index 0b6edad23cb1..c1a2d2ab89fb 100644 --- a/tests/run-with-compiler/i3947f.check +++ b/tests/run-with-compiler/i3947f.check @@ -1,12 +1,12 @@ -classOf[Array[Object]].getCanonicalName() +scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName() java.lang.Object[] -classOf[Array[Object]].getCanonicalName() +scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName() java.lang.Object[] -classOf[Array[Object]].getCanonicalName() +scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName() java.lang.Object[] -classOf[Array[Object]].getCanonicalName() +scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName() java.lang.Object[] diff --git a/tests/run-with-compiler/i3947g.check b/tests/run-with-compiler/i3947g.check index cf538c37ae20..675a4d803573 100644 --- a/tests/run-with-compiler/i3947g.check +++ b/tests/run-with-compiler/i3947g.check @@ -1,12 +1,12 @@ -classOf[Array[Boolean]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Boolean]].getCanonicalName() boolean[] -classOf[Array[Byte]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Byte]].getCanonicalName() byte[] -classOf[Array[Char]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Char]].getCanonicalName() char[] -classOf[Array[Short]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Short]].getCanonicalName() short[] diff --git a/tests/run-with-compiler/i3947i.check b/tests/run-with-compiler/i3947i.check index 141776ab3163..112ef331cf08 100644 --- a/tests/run-with-compiler/i3947i.check +++ b/tests/run-with-compiler/i3947i.check @@ -1,12 +1,12 @@ -classOf[Array[Int]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Int]].getCanonicalName() int[] -classOf[Array[Long]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Long]].getCanonicalName() long[] -classOf[Array[Float]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Float]].getCanonicalName() float[] -classOf[Array[Double]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Double]].getCanonicalName() double[] diff --git a/tests/run-with-compiler/i3947j.check b/tests/run-with-compiler/i3947j.check index ce0048ef7906..2ef0b42eedf6 100644 --- a/tests/run-with-compiler/i3947j.check +++ b/tests/run-with-compiler/i3947j.check @@ -1,6 +1,6 @@ -classOf[Array[Array[Int]]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Array[scala.Int]]].getCanonicalName() int[][] -classOf[Array[Array[Array[Int]]]].getCanonicalName() +scala.Predef.classOf[scala.Array[scala.Array[scala.Array[scala.Int]]]].getCanonicalName() int[][][] diff --git a/tests/run-with-compiler/i4044b.check b/tests/run-with-compiler/i4044b.check index 43c71a999c56..6a3bd355f3bd 100644 --- a/tests/run-with-compiler/i4044b.check +++ b/tests/run-with-compiler/i4044b.check @@ -1,5 +1,5 @@ { - var x: Int = 4 + var x: scala.Int = 4 x = 3 x } diff --git a/tests/run-with-compiler/i4044d.check b/tests/run-with-compiler/i4044d.check index 16281b787396..42fb04df02ea 100644 --- a/tests/run-with-compiler/i4044d.check +++ b/tests/run-with-compiler/i4044d.check @@ -1,5 +1,5 @@ evaluating inner quote { - val b: Int = 3 + val b: scala.Int = 3 b.+(3) } diff --git a/tests/run-with-compiler/i4044e.check b/tests/run-with-compiler/i4044e.check index af61855f9eed..d45b75cd3207 100644 --- a/tests/run-with-compiler/i4044e.check +++ b/tests/run-with-compiler/i4044e.check @@ -1 +1 @@ -3.+(5).asInstanceOf[Int] +3.+(5).asInstanceOf[scala.Int] diff --git a/tests/run-with-compiler/i4044f.check b/tests/run-with-compiler/i4044f.check index 409bb72596a0..8d22fe5ed937 100644 --- a/tests/run-with-compiler/i4044f.check +++ b/tests/run-with-compiler/i4044f.check @@ -1,5 +1,5 @@ { - val e1: Int = 3 - val f1: Int = 5 + val e1: scala.Int = 3 + val f1: scala.Int = 5 e1.+(2).+(f1) } diff --git a/tests/run-with-compiler/i4350.check b/tests/run-with-compiler/i4350.check index 235eefbcd950..7d5fd0304324 100644 --- a/tests/run-with-compiler/i4350.check +++ b/tests/run-with-compiler/i4350.check @@ -1,6 +1,6 @@ { - null.asInstanceOf[Object] + null.asInstanceOf[lang.Object] } { - null.asInstanceOf[String] + null.asInstanceOf[scala.Predef.String] } diff --git a/tests/run-with-compiler/quote-nested-1.check b/tests/run-with-compiler/quote-nested-1.check index 1ab350bb1762..57676d4de920 100644 --- a/tests/run-with-compiler/quote-nested-1.check +++ b/tests/run-with-compiler/quote-nested-1.check @@ -1 +1 @@ -'(3) +scala.quoted.Expr.apply[scala.Int](3) diff --git a/tests/run-with-compiler/quote-nested-2.check b/tests/run-with-compiler/quote-nested-2.check index 90df317c6cb6..c99111fc4c77 100644 --- a/tests/run-with-compiler/quote-nested-2.check +++ b/tests/run-with-compiler/quote-nested-2.check @@ -1,4 +1,4 @@ { - val a: quoted.Expr[Int] = '(4) + val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4) a } diff --git a/tests/run-with-compiler/quote-nested-3.check b/tests/run-with-compiler/quote-nested-3.check index 4b5686d7ba3f..1dc1b00982a4 100644 --- a/tests/run-with-compiler/quote-nested-3.check +++ b/tests/run-with-compiler/quote-nested-3.check @@ -1,7 +1,7 @@ { - type T = String - val x: String = "foo" + type T = scala.Predef.String + val x: java.lang.String = "foo" val z: T = x () - x: String + (x: java.lang.String) } diff --git a/tests/run-with-compiler/quote-nested-4.check b/tests/run-with-compiler/quote-nested-4.check index 5d37730e8890..39c62c260cb5 100644 --- a/tests/run-with-compiler/quote-nested-4.check +++ b/tests/run-with-compiler/quote-nested-4.check @@ -1,4 +1,4 @@ { - val t: quoted.Type[String] = '[String] - t: quoted.Type[String] + val t: scala.quoted.Type[scala.Predef.String] = scala.quoted.Type.apply[scala.Predef.String] + (t: scala.quoted.Type[scala.Predef.String]) } diff --git a/tests/run-with-compiler/quote-nested-5.check b/tests/run-with-compiler/quote-nested-5.check index 90df317c6cb6..c99111fc4c77 100644 --- a/tests/run-with-compiler/quote-nested-5.check +++ b/tests/run-with-compiler/quote-nested-5.check @@ -1,4 +1,4 @@ { - val a: quoted.Expr[Int] = '(4) + val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4) a } diff --git a/tests/run-with-compiler/quote-owners-2.check b/tests/run-with-compiler/quote-owners-2.check index fee34077c6f9..27d92e1afd31 100644 --- a/tests/run-with-compiler/quote-owners-2.check +++ b/tests/run-with-compiler/quote-owners-2.check @@ -1,14 +1,12 @@ 3 { - def ff: Int = - { - val a: List[Int] = - { - type T = List[Int] - val b: T = Nil.::[Int](3) - b: List[Int] - } - a.head: Int + def ff: scala.Int = { + val a: immutable.List[scala.Int] = { + type T = immutable.List[scala.Int] + val b: T = scala.Nil.::[scala.Int](3) + (b: collection.immutable.List[scala.Int]) } - ff: Int + (a.head: scala.Int) + } + (ff: scala.Int) } diff --git a/tests/run-with-compiler/quote-owners.check b/tests/run-with-compiler/quote-owners.check index 8b1f473d369a..db594bbb1c80 100644 --- a/tests/run-with-compiler/quote-owners.check +++ b/tests/run-with-compiler/quote-owners.check @@ -1,9 +1,8 @@ 9 { - def ff: Int = - { - val a: Int = 9 - a.+(0) - } - ff: Int + def ff: scala.Int = { + val a: scala.Int = 9 + a.+(0) + } + (ff: scala.Int) } diff --git a/tests/run-with-compiler/quote-run-2.check b/tests/run-with-compiler/quote-run-2.check index da6a30e8e4d9..5b53f923996d 100644 --- a/tests/run-with-compiler/quote-run-2.check +++ b/tests/run-with-compiler/quote-run-2.check @@ -1,12 +1,10 @@ 1.0 5.0 { - val y: Double = 5.0.*(5.0) + val y: scala.Double = 5.0.*(5.0) y } -5.0.*( - { - val y: Double = 5.0.*(5.0) - y - } -) +5.0.*({ + val y: scala.Double = 5.0.*(5.0) + y +}) diff --git a/tests/run-with-compiler/quote-run-staged-interpreter.check b/tests/run-with-compiler/quote-run-staged-interpreter.check index f65ddd9f2efa..1b61c558fac9 100644 --- a/tests/run-with-compiler/quote-run-staged-interpreter.check +++ b/tests/run-with-compiler/quote-run-staged-interpreter.check @@ -1,4 +1,4 @@ -(x: Int) => 2.+(x).+(4) +((x: scala.Int) => 2.+(x).+(4)) 6 8 9 @@ -7,7 +7,7 @@ 9 --- { - val y: Int = 3 + val y: scala.Int = 3 2.+(y).+(4) } 9 diff --git a/tests/run-with-compiler/quote-run-with-settings.check b/tests/run-with-compiler/quote-run-with-settings.check index c87c7bf36f6e..b1473444c7ad 100644 --- a/tests/run-with-compiler/quote-run-with-settings.check +++ b/tests/run-with-compiler/quote-run-with-settings.check @@ -1,6 +1,6 @@ { - val a: Int = 3 - println("foo") + val a: scala.Int = 3 + scala.Predef.println("foo") 2.+(a) } foo diff --git a/tests/run-with-compiler/quote-run.check b/tests/run-with-compiler/quote-run.check index fce767bf8172..599ce67327ab 100644 --- a/tests/run-with-compiler/quote-run.check +++ b/tests/run-with-compiler/quote-run.check @@ -3,7 +3,7 @@ foo foo 5 { - val a: Int = 3 - println("foo") + val a: scala.Int = 3 + scala.Predef.println("foo") 2.+(a) } diff --git a/tests/run-with-compiler/quote-show-blocks-raw.check b/tests/run-with-compiler/quote-show-blocks-raw.check index d5000f92059b..a5811ff76160 100644 --- a/tests/run-with-compiler/quote-show-blocks-raw.check +++ b/tests/run-with-compiler/quote-show-blocks-raw.check @@ -1,13 +1,13 @@ { - println(1) + scala.Predef.println(1) { - println(2) + scala.Predef.println(2) { - println(3) + scala.Predef.println(3) { - println(4) + scala.Predef.println(4) { - println(5) + scala.Predef.println(5) () } } @@ -20,13 +20,13 @@ { { () - println(5) + scala.Predef.println(5) } - println(4) + scala.Predef.println(4) } - println(3) + scala.Predef.println(3) } - println(2) + scala.Predef.println(2) } - println(1) + scala.Predef.println(1) } diff --git a/tests/run-with-compiler/quote-show-blocks.check b/tests/run-with-compiler/quote-show-blocks.check index e3dc2c1ff20d..69829918b4fd 100644 --- a/tests/run-with-compiler/quote-show-blocks.check +++ b/tests/run-with-compiler/quote-show-blocks.check @@ -1,15 +1,15 @@ { - println(1) - println(2) - println(3) - println(4) - println(5) + scala.Predef.println(1) + scala.Predef.println(2) + scala.Predef.println(3) + scala.Predef.println(4) + scala.Predef.println(5) () } { - println(5) - println(4) - println(3) - println(2) - println(1) + scala.Predef.println(5) + scala.Predef.println(4) + scala.Predef.println(3) + scala.Predef.println(2) + scala.Predef.println(1) } diff --git a/tests/run-with-compiler/quote-two-captured-ref.check b/tests/run-with-compiler/quote-two-captured-ref.check index 62c016a6094c..8dd4fa869306 100644 --- a/tests/run-with-compiler/quote-two-captured-ref.check +++ b/tests/run-with-compiler/quote-two-captured-ref.check @@ -1,5 +1,5 @@ 1 { - val x: Int = 1 - println(x.+(x)) + val x: scala.Int = 1 + scala.Predef.println(x.+(x)) } diff --git a/tests/run-with-compiler/quote-type-tags.check b/tests/run-with-compiler/quote-type-tags.check index 240429f8eb10..79fc1da53ebc 100644 --- a/tests/run-with-compiler/quote-type-tags.check +++ b/tests/run-with-compiler/quote-type-tags.check @@ -1,10 +1,10 @@ -().asInstanceOf[Unit] -true.asInstanceOf[Boolean] -0.toByte.asInstanceOf[Byte] -'a'.asInstanceOf[Char] -1.toShort.asInstanceOf[Short] -2.asInstanceOf[Int] -3L.asInstanceOf[Long] -4.0.asInstanceOf[Float] -5.0.asInstanceOf[Double] -5.0.asInstanceOf[Boolean] +().asInstanceOf[scala.Unit] +true.asInstanceOf[scala.Boolean] +0.toByte.asInstanceOf[scala.Byte] +'a'.asInstanceOf[scala.Char] +1.toShort.asInstanceOf[scala.Short] +2.asInstanceOf[scala.Int] +3L.asInstanceOf[scala.Long] +4.0.asInstanceOf[scala.Float] +5.0.asInstanceOf[scala.Double] +5.0.asInstanceOf[scala.Boolean] diff --git a/tests/run/puzzle.decompiled b/tests/run/puzzle.decompiled index 2f8c2d50577f..a5184ddf0b16 100644 --- a/tests/run/puzzle.decompiled +++ b/tests/run/puzzle.decompiled @@ -1,12 +1,11 @@ /** Decompiled from out/runTestFromTasty/run/puzzle/Test.class */ object Test { - def main(args: Array[String]): Unit = - { - println(if false then 5.0 else 53.0) - val x: Double = if false then 5.0 else 53.0 - println(x) - val z: Long = 1L - val y: Float = Long.long2float(z) - () - } -} \ No newline at end of file + def main(args: scala.Array[scala.Predef.String]): scala.Unit = { + scala.Predef.println(if (false) 5.0 else 53.0) + val x: scala.Double = if (false) 5.0 else 53.0 + scala.Predef.println(x) + val z: scala.Long = 1L + val y: scala.Float = scala.Long.long2float(z) + () + } +} diff --git a/tests/run/quote-impure-by-name.check b/tests/run/quote-impure-by-name.check index 76c0cd1704c7..6616ccfa5430 100644 --- a/tests/run/quote-impure-by-name.check +++ b/tests/run/quote-impure-by-name.check @@ -1 +1 @@ -1 + {Index.zero[String("bar"), scala.Tuple2[String("baz"), scala.Unit]]} +1 + {Index.zero["bar", scala.Tuple2["baz", scala.Unit]]} diff --git a/tests/run/tasty-extractors-constants-2.check b/tests/run/tasty-extractors-constants-2.check index 00657feabf5c..7a500dd62e53 100644 --- a/tests/run/tasty-extractors-constants-2.check +++ b/tests/run/tasty-extractors-constants-2.check @@ -1,17 +1,17 @@ { - val y: Double = 3.0.*(3.0) + val y: scala.Double = 3.0.*(3.0) y } 9.0 { - val y: Double = 4.0.*(4.0) + val y: scala.Double = 4.0.*(4.0) y } 16.0 { - val y: Double = 5.0.*(5.0) + val y: scala.Double = 5.0.*(5.0) y } 25.0