diff options
90 files changed, 342 insertions, 200 deletions
@@ -1944,7 +1944,7 @@ TODO: <target name="dist.doc" depends="dist.base, docs.done"> <mkdir dir="${dist.dir}/doc/scala-devel-docs"/> - <copy toDir="${dist.dir}/doc/scala-devel-docs" overwrite="true"> + <copy toDir="${dist.dir}/doc/scala-devel-docs" overwrite="true" flatten="true"> <file file="${scala-xml-javadoc}"/> <file file="${scala-parser-combinators-javadoc}"/> </copy> @@ -2003,7 +2003,7 @@ TODO: <target name="dist.src" depends="dist.base"> <mkdir dir="${dist.dir}/src"/> - <copy toDir="${dist.dir}/src" overwrite="true"> + <copy toDir="${dist.dir}/src" overwrite="true" flatten="true"> <file file="${scala-xml-sources}"/> <file file="${scala-parser-combinators-sources}"/> </copy> diff --git a/src/compiler/scala/reflect/macros/compiler/Errors.scala b/src/compiler/scala/reflect/macros/compiler/Errors.scala index 9b56e417e2..45bb87fc47 100644 --- a/src/compiler/scala/reflect/macros/compiler/Errors.scala +++ b/src/compiler/scala/reflect/macros/compiler/Errors.scala @@ -44,14 +44,18 @@ trait Errors extends Traces { message + suffix } - private def abbreviateCoreAliases(s: String): String = List("WeakTypeTag", "Expr").foldLeft(s)((res, x) => res.replace("c.universe." + x, "c." + x)) + private def abbreviateCoreAliases(s: String): String = { + val coreAliases = List("WeakTypeTag", "Expr", "Tree") + coreAliases.foldLeft(s)((res, x) => res.replace("c.universe." + x, "c." + x)) + } - private def showMeth(pss: List[List[Symbol]], restpe: Type, abbreviate: Boolean) = { - var argsPart = (pss map (ps => ps map (_.defString) mkString ("(", ", ", ")"))).mkString - if (abbreviate) argsPart = abbreviateCoreAliases(argsPart) - var retPart = restpe.toString + private def showMeth(pss: List[List[Symbol]], restpe: Type, abbreviate: Boolean, untype: Boolean) = { + def preprocess(tpe: Type) = if (untype) untypeMetalevel(tpe) else tpe + var pssPart = (pss map (ps => ps map (p => p.defStringSeenAs(preprocess(p.info))) mkString ("(", ", ", ")"))).mkString + if (abbreviate) pssPart = abbreviateCoreAliases(pssPart) + var retPart = preprocess(restpe).toString if (abbreviate || macroDdef.tpt.tpe == null) retPart = abbreviateCoreAliases(retPart) - argsPart + ": " + retPart + pssPart + ": " + retPart } // not exactly an error generator, but very related @@ -86,8 +90,9 @@ trait Errors extends Traces { private def compatibilityError(message: String) = implRefError( "macro implementation has wrong shape:"+ - "\n required: " + showMeth(rparamss, rret, abbreviate = true) + - "\n found : " + showMeth(aparamss, aret, abbreviate = false) + + "\n required: " + showMeth(rparamss, rret, abbreviate = true, untype = false) + + "\n or : " + showMeth(rparamss, rret, abbreviate = true, untype = true) + + "\n found : " + showMeth(aparamss, aret, abbreviate = false, untype = false) + "\n" + message) def MacroImplNonTagImplicitParameters(params: List[Symbol]) = compatibilityError("macro implementations cannot have implicit parameters other than WeakTypeTag evidences") diff --git a/src/compiler/scala/reflect/macros/util/Helpers.scala b/src/compiler/scala/reflect/macros/util/Helpers.scala index f40c6bb7e6..dd23b0fc32 100644 --- a/src/compiler/scala/reflect/macros/util/Helpers.scala +++ b/src/compiler/scala/reflect/macros/util/Helpers.scala @@ -55,6 +55,13 @@ trait Helpers { case tp => typeRef(pre, MacroContextExprClass, List(tp)) } + /** Transforms c.Expr[T] types into c.Tree and leaves the rest unchanged. + */ + def untypeMetalevel(tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) { + case ExprClassOf(_) => typeRef(tp.prefix, TreesTreeType, Nil) + case tp => tp + } + /** Decreases metalevel of the type, i.e. transforms: * * c.Expr[T] to T * * Anything else to Any diff --git a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala index f7b194a6ca..8a4e565ced 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala @@ -113,7 +113,7 @@ trait Logic extends Debugging { // symbols are propositions abstract case class Sym(variable: Var, const: Const) extends Prop { - private[this] val id = Sym.nextSymId + private val id: Int = Sym.nextSymId override def toString = variable +"="+ const +"#"+ id } @@ -125,6 +125,7 @@ trait Logic extends Debugging { (uniques findEntryOrUpdate newSym) } private def nextSymId = {_symId += 1; _symId}; private var _symId = 0 + implicit val SymOrdering: Ordering[Sym] = Ordering.by(_.id) } def /\(props: Iterable[Prop]) = if (props.isEmpty) True else props.reduceLeft(And(_, _)) @@ -279,7 +280,7 @@ trait Logic extends Debugging { def eqFreePropToSolvable(p: Prop): Formula def cnfString(f: Formula): String - type Model = Map[Sym, Boolean] + type Model = collection.immutable.SortedMap[Sym, Boolean] val EmptyModel: Model val NoModel: Model diff --git a/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala b/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala index 6267585ea8..1902606d86 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala @@ -26,9 +26,12 @@ trait Solving extends Logic { type Formula = FormulaBuilder def formula(c: Clause*): Formula = ArrayBuffer(c: _*) - type Clause = Set[Lit] + type Clause = collection.Set[Lit] // a clause is a disjunction of distinct literals - def clause(l: Lit*): Clause = l.toSet + def clause(l: Lit*): Clause = ( + // neg/t7020.scala changes output 1% of the time, the non-determinism is quelled with this linked set + mutable.LinkedHashSet(l: _*) + ) type Lit def Lit(sym: Sym, pos: Boolean = true): Lit @@ -134,7 +137,7 @@ trait Solving extends Logic { def cnfString(f: Formula) = alignAcrossRows(f map (_.toList) toList, "\\/", " /\\\n") // adapted from http://lara.epfl.ch/w/sav10:simple_sat_solver (original by Hossein Hojjat) - val EmptyModel = Map.empty[Sym, Boolean] + val EmptyModel = collection.immutable.SortedMap.empty[Sym, Boolean] val NoModel: Model = null // returns all solutions, if any (TODO: better infinite recursion backstop -- detect fixpoint??) @@ -229,9 +232,8 @@ trait Solving extends Logic { } } - if (Statistics.canEnable) Statistics.stopTimer(patmatAnaDPLL, start) - - satisfiableWithModel + if (Statistics.canEnable) Statistics.stopTimer(patmatAnaDPLL, start) + satisfiableWithModel } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 4765c301dd..d1045757a5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -111,7 +111,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { * with synthetic content that carries the payload described in `MacroImplBinding`. * * For example, for a pair of macro definition and macro implementation: - * def impl(c: scala.reflect.macros.Context): c.Expr[Unit] = c.literalUnit; + * def impl(c: scala.reflect.macros.Context): c.Expr[Unit] = ??? * def foo: Unit = macro impl * * We will have the following annotation added on the macro definition `foo`: diff --git a/src/reflect/scala/reflect/macros/ExprUtils.scala b/src/reflect/scala/reflect/macros/ExprUtils.scala index af11bd6efc..76a8392b9c 100644 --- a/src/reflect/scala/reflect/macros/ExprUtils.scala +++ b/src/reflect/scala/reflect/macros/ExprUtils.scala @@ -12,41 +12,54 @@ trait ExprUtils { self: Context => /** Shorthand for `Literal(Constant(null))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalNull: Expr[Null] /** Shorthand for `Literal(Constant(()))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalUnit: Expr[Unit] /** Shorthand for `Literal(Constant(true))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalTrue: Expr[Boolean] /** Shorthand for `Literal(Constant(false))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalFalse: Expr[Boolean] /** Shorthand for `Literal(Constant(x: Boolean))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Boolean): Expr[Boolean] /** Shorthand for `Literal(Constant(x: Byte))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Byte): Expr[Byte] /** Shorthand for `Literal(Constant(x: Short))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Short): Expr[Short] /** Shorthand for `Literal(Constant(x: Int))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Int): Expr[Int] /** Shorthand for `Literal(Constant(x: Long))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Long): Expr[Long] /** Shorthand for `Literal(Constant(x: Float))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Float): Expr[Float] /** Shorthand for `Literal(Constant(x: Double))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Double): Expr[Double] /** Shorthand for `Literal(Constant(x: String))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: String): Expr[String] /** Shorthand for `Literal(Constant(x: Char))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Char): Expr[Char] } diff --git a/src/reflect/scala/reflect/macros/Parsers.scala b/src/reflect/scala/reflect/macros/Parsers.scala index 3b25309614..4232b05f8c 100644 --- a/src/reflect/scala/reflect/macros/Parsers.scala +++ b/src/reflect/scala/reflect/macros/Parsers.scala @@ -8,6 +8,7 @@ package macros * A slice of [[scala.reflect.macros.Context the Scala macros context]] that * exposes functions to parse strings with Scala code into trees. */ +@deprecated("Use quasiquotes instead", "2.11.0") trait Parsers { self: Context => @@ -15,9 +16,11 @@ trait Parsers { * Only works for expressions, i.e. parsing a package declaration will fail. * @throws [[scala.reflect.macros.ParseException]] */ + @deprecated("Use quasiquotes instead", "2.11.0") def parse(code: String): Tree } /** Indicates an error during [[scala.reflect.macros.Parsers#parse]]. */ + @deprecated("Use quasiquotes instead", "2.11.0") case class ParseException(pos: scala.reflect.api.Position, msg: String) extends Exception(msg) diff --git a/src/reflect/scala/reflect/macros/TreeBuilder.scala b/src/reflect/scala/reflect/macros/TreeBuilder.scala index 427b4f70d1..7f57274347 100644 --- a/src/reflect/scala/reflect/macros/TreeBuilder.scala +++ b/src/reflect/scala/reflect/macros/TreeBuilder.scala @@ -8,6 +8,7 @@ package macros * A helper available in [[scala.reflect.macros.Universe]] that defines shorthands for the * most common tree-creating functions. */ +@deprecated("Use quasiquotes instead", "2.11.0") abstract class TreeBuilder { val global: Universe @@ -17,6 +18,7 @@ abstract class TreeBuilder { * The type must be suitable for this. For example, it * must not be a TypeRef pointing to an abstract type variable. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedQualifier(tpe: Type): Tree /** Builds a reference to value whose type is given stable prefix. @@ -25,27 +27,35 @@ abstract class TreeBuilder { * termSym as the Ident's symbol. In that case, termSym must * not be NoSymbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree /** Builds a typed reference to given symbol with given stable prefix. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedRef(pre: Type, sym: Symbol): RefTree /** Builds a typed reference to given symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedRef(sym: Symbol): RefTree /** Builds an untyped reference to given symbol. Requires the symbol to be static. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkUnattributedRef(sym: Symbol): RefTree /** Builds an untyped reference to symbol with given name. Requires the symbol to be static. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkUnattributedRef(fullName: Name): RefTree /** Builds a typed This reference to given symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedThis(sym: Symbol): This /** Builds a typed Ident with an underlying symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedIdent(sym: Symbol): RefTree /** Builds a typed Select with an underlying symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedSelect(qual: Tree, sym: Symbol): RefTree /** A creator for method calls, e.g. fn[T1, T2, ...](v1, v2, ...) @@ -57,22 +67,31 @@ abstract class TreeBuilder { * @param args value arguments * @return the newly created trees. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(receiver: Symbol, methodName: Name, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(method: Symbol, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(method: Symbol, args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(target: Tree, args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(receiver: Symbol, methodName: Name, args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(receiver: Tree, method: Symbol, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkNullaryCall(method: Symbol, targs: List[Type]): Tree /** A tree that refers to the runtime reflexive universe, `scala.reflect.runtime.universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkRuntimeUniverseRef: Tree } diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala index d1d90f53c9..297bac2999 100644 --- a/src/reflect/scala/reflect/macros/Universe.scala +++ b/src/reflect/scala/reflect/macros/Universe.scala @@ -20,6 +20,7 @@ abstract class Universe extends scala.reflect.api.Universe { /** A factory that encapsulates common tree-building functions. * @group Macros */ + @deprecated("Use quasiquotes instead", "2.11.0") val treeBuild: TreeBuilder { val global: Universe.this.type } /** The API of reflection artifacts that support [[scala.reflect.macros.Attachments]]. diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 1e2dd6b7d3..8e822ca4f0 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -18,7 +18,7 @@ import internal.pickling.ByteCodecs import internal.pickling.UnPickler import scala.collection.mutable.{ HashMap, ListBuffer } import internal.Flags._ -import ReflectionUtils.{staticSingletonInstance, innerSingletonInstance, scalacShouldntLoadClass} +import ReflectionUtils._ import scala.language.existentials import scala.runtime.{ScalaRunTime, BoxesRunTime} @@ -777,33 +777,19 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni /** * The Scala owner of the Scala class corresponding to the Java class `jclazz` */ - private def sOwner(jclazz: jClass[_]): Symbol = - if (jclazz.isMemberClass) { - val jEnclosingClass = jclazz.getEnclosingClass - val sEnclosingClass = classToScala(jEnclosingClass) - followStatic(sEnclosingClass, jclazz.javaFlags) - } else if (jclazz.isLocalClass0) { - val jEnclosingMethod = jclazz.getEnclosingMethod - if (jEnclosingMethod != null) { - methodToScala(jEnclosingMethod) - } else { - val jEnclosingConstructor = jclazz.getEnclosingConstructor - constructorToScala(jEnclosingConstructor) - } - } else if (jclazz.isPrimitive || jclazz.isArray) { - ScalaPackageClass - } else if (jclazz.getPackage != null) { - val jPackage = jclazz.getPackage - packageToScala(jPackage).moduleClass - } else { - // @eb: a weird classloader might return a null package for something with a non-empty package name - // for example, http://groups.google.com/group/scala-internals/browse_thread/thread/7be09ff8f67a1e5c - // in that case we could invoke packageNameToScala(jPackageName) and, probably, be okay - // however, I think, it's better to blow up, since weirdness of the class loader might bite us elsewhere - // [martin] I think it's better to be forgiving here. Restoring packageNameToScala. - val jPackageName = jclazz.getName take jclazz.getName.lastIndexOf('.') - packageNameToScala(jPackageName).moduleClass - } + // @eb: a weird classloader might return a null package for something with a non-empty package name + // for example, http://groups.google.com/group/scala-internals/browse_thread/thread/7be09ff8f67a1e5c + // in that case we could invoke packageNameToScala(jPackageName) and, probably, be okay + // however, I think, it's better to blow up, since weirdness of the class loader might bite us elsewhere + // [martin] I think it's better to be forgiving here. Restoring packageNameToScala. + private def sOwner(jclazz: jClass[_]): Symbol = jclazz match { + case PrimitiveOrArray() => ScalaPackageClass + case EnclosedInMethod(jowner) => methodToScala(jowner) + case EnclosedInConstructor(jowner) => constructorToScala(jowner) + case EnclosedInClass(jowner) => followStatic(classToScala(jowner), jclazz.javaFlags) + case EnclosedInPackage(jowner) => packageToScala(jowner).moduleClass + case _ => packageNameToScala(jclazz.getName take jclazz.getName.lastIndexOf('.')).moduleClass + } /** * The Scala owner of the Scala symbol corresponding to the Java member `jmember` diff --git a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala index 710ec02acd..813c0e1386 100644 --- a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala +++ b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala @@ -84,4 +84,18 @@ private[scala] object ReflectionUtils { def scalacShouldntLoadClassfile(fileName: String) = isTraitImplementation(fileName) def scalacShouldntLoadClass(name: scala.reflect.internal.SymbolTable#Name) = scalacShouldntLoadClassfile(name + ".class") + + object PrimitiveOrArray { + def unapply(jclazz: jClass[_]) = jclazz.isPrimitive || jclazz.isArray + } + + class EnclosedIn[T](enclosure: jClass[_] => T) { + def unapply(jclazz: jClass[_]): Option[T] = if (enclosure(jclazz) != null) Some(enclosure(jclazz)) else None + } + + object EnclosedInMethod extends EnclosedIn(_.getEnclosingMethod) + object EnclosedInConstructor extends EnclosedIn(_.getEnclosingConstructor) + object EnclosedInClass extends EnclosedIn(_.getEnclosingClass) + object EnclosedInPackage extends EnclosedIn(_.getPackage) } + diff --git a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala index c6059ac402..30a3855d70 100644 --- a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala +++ b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala @@ -97,9 +97,7 @@ private[reflect] trait SymbolLoaders { self: SymbolTable => if (isCompilerUniverse) super.enter(sym) else { val existing = super.lookupEntry(sym.name) - // commented out to provide a hotfix for strange class files that javac sometimes emits - // see more details at: https://groups.google.com/forum/#!topic/scala-internals/hcnUFk75MgQ - // assert(existing == null || existing.sym.isMethod, s"pkgClass = $pkgClass, sym = $sym, existing = $existing") + assert(existing == null || existing.sym.isMethod, s"pkgClass = $pkgClass, sym = $sym, existing = $existing") super.enter(sym) } } diff --git a/test/files/run/reflection-sync-subtypes.check b/test/disabled/run/reflection-sync-subtypes.check index e69de29bb2..e69de29bb2 100644 --- a/test/files/run/reflection-sync-subtypes.check +++ b/test/disabled/run/reflection-sync-subtypes.check diff --git a/test/files/run/reflection-sync-subtypes.scala b/test/disabled/run/reflection-sync-subtypes.scala index 7f75a464ac..7f75a464ac 100644 --- a/test/files/run/reflection-sync-subtypes.scala +++ b/test/disabled/run/reflection-sync-subtypes.scala diff --git a/test/files/disabled/run/t4602.scala b/test/disabled/run/t4602.scala index 655c350497..655c350497 100644 --- a/test/files/disabled/run/t4602.scala +++ b/test/disabled/run/t4602.scala diff --git a/test/files/neg/macro-basic-mamdmi.check b/test/files/neg/macro-basic-mamdmi.check index 9328fbd51c..61df5131cc 100644 --- a/test/files/neg/macro-basic-mamdmi.check +++ b/test/files/neg/macro-basic-mamdmi.check @@ -1,4 +1,4 @@ -Impls_Macros_Test_1.scala:36: error: macro implementation not found: quux +Impls_Macros_Test_1.scala:33: error: macro implementation not found: quux (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) println(foo(2) + Macros.bar(2) * new Macros().quux(4)) ^ diff --git a/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala b/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala index f9e0ca5077..97780ef503 100644 --- a/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala +++ b/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala @@ -3,20 +3,17 @@ import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - val body = Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(1)))) - c.Expr[Int](body) + c.Expr[Int](q"$x + 1") } def bar(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - val body = Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(2)))) - c.Expr[Int](body) + c.Expr[Int](q"$x + 2") } def quux(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - val body = Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(3)))) - c.Expr[Int](body) + c.Expr[Int](q"$x + 3") } } diff --git a/test/files/neg/macro-bundle-object.check b/test/files/neg/macro-bundle-object.check index e122001427..8c19271b51 100644 --- a/test/files/neg/macro-bundle-object.check +++ b/test/files/neg/macro-bundle-object.check @@ -1,5 +1,6 @@ macro-bundle-object.scala:11: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : : Nothing number of parameter sections differ def foo = macro Bundle.impl diff --git a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala index 59acaede65..3983f590dc 100644 --- a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala +++ b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala @@ -15,7 +15,7 @@ object Complex { val recur = c.inferImplicitValue(trecur, silent = true) if (recur == EmptyTree) c.abort(c.enclosingPosition, s"couldn't synthesize $trecur") } - c.literalNull + c.Expr[Null](q"null") } implicit object ComplexString extends Complex[String] diff --git a/test/files/neg/macro-invalidimpl.check b/test/files/neg/macro-invalidimpl.check index aaf4f88fc2..e39cc8105b 100644 --- a/test/files/neg/macro-invalidimpl.check +++ b/test/files/neg/macro-invalidimpl.check @@ -32,12 +32,14 @@ match expected type ? ^ Macros_Test_2.scala:31: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Unit] + or : (c: scala.reflect.macros.Context): c.Tree found : (c: scala.reflect.macros.Context)(): c.Expr[Unit] number of parameter sections differ def foo1 = macro Impls6.fooEmpty ^ Macros_Test_2.scala:32: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(): c.Expr[Unit] + or : (c: scala.reflect.macros.Context)(): c.Tree found : (c: scala.reflect.macros.Context): c.Expr[Unit] number of parameter sections differ def bar1() = macro Impls6.fooNullary diff --git a/test/files/neg/macro-invalidimpl/Impls_1.scala b/test/files/neg/macro-invalidimpl/Impls_1.scala index cf78ecc65a..9f48ab7ad9 100644 --- a/test/files/neg/macro-invalidimpl/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl/Impls_1.scala @@ -22,8 +22,7 @@ object Impls5 { object Impls6 { def fooNullary(c: Context) = { import c.universe._ - val body = Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("it works")))) - c.Expr[Unit](body) + c.Expr[Unit](q"""Predef.println("it works")""") } def fooEmpty(c: Context)() = fooNullary(c) diff --git a/test/files/neg/macro-invalidret.check b/test/files/neg/macro-invalidret.check index 8c6ed4eb45..6cf62c292b 100644 --- a/test/files/neg/macro-invalidret.check +++ b/test/files/neg/macro-invalidret.check @@ -1,11 +1,13 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : (c: scala.reflect.macros.Context): Int type mismatch for return type: Int does not conform to c.Expr[Any] def foo1 = macro Impls.foo1 ^ Macros_Test_2.scala:3: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : (c: scala.reflect.macros.Context): reflect.runtime.universe.Literal type mismatch for return type: reflect.runtime.universe.Literal does not conform to c.Expr[Any] def foo2 = macro Impls.foo2 diff --git a/test/files/neg/macro-invalidshape/Macros_Test_2.scala b/test/files/neg/macro-invalidshape/Macros_Test_2.scala index cf37e14d8e..819844b9f1 100644 --- a/test/files/neg/macro-invalidshape/Macros_Test_2.scala +++ b/test/files/neg/macro-invalidshape/Macros_Test_2.scala @@ -3,7 +3,7 @@ object Macros { def foo2(x: Any) = macro Impls.foo(null)(null) def foo3(x: Any) = macro {2; Impls.foo} { - def impl(c: scala.reflect.macros.Context) = c.literalUnit + def impl(c: scala.reflect.macros.Context) = { import c.universe._; c.Expr[Unit](q"()") } def foo = macro impl foo } diff --git a/test/files/neg/macro-invalidsig-params-badtype.check b/test/files/neg/macro-invalidsig-params-badtype.check index 3cc1c9abf1..86aa08291f 100644 --- a/test/files/neg/macro-invalidsig-params-badtype.check +++ b/test/files/neg/macro-invalidsig-params-badtype.check @@ -1,5 +1,6 @@ Impls_Macros_1.scala:8: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.Context)(x: Int): Nothing type mismatch for parameter x: c.Expr[Int] does not conform to Int def foo(x: Int) = macro Impls.foo diff --git a/test/files/neg/macro-invalidsig.check b/test/files/neg/macro-invalidsig.check index cbdaf51081..732380d4b3 100644 --- a/test/files/neg/macro-invalidsig.check +++ b/test/files/neg/macro-invalidsig.check @@ -1,65 +1,76 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : (c: scala.reflect.macros.Context)(implicit evidence$2: Numeric[U]): c.universe.Literal macro implementations cannot have implicit parameters other than WeakTypeTag evidences def foo[U] = macro Impls1.foo[U] ^ Macros_Test_2.scala:6: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : : Nothing number of parameter sections differ def foo = macro Impls2.foo ^ Macros_Test_2.scala:10: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : (c: scala.reflect.api.Universe): Nothing type mismatch for parameter c: scala.reflect.macros.Context does not conform to scala.reflect.api.Universe def foo = macro Impls3.foo ^ Macros_Test_2.scala:14: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : (cs: scala.reflect.macros.Context*): Nothing types incompatible for parameter cs: corresponding is not a vararg parameter def foo = macro Impls4.foo ^ Macros_Test_2.scala:18: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Any]): c.Expr[Any] + or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.Context): Nothing number of parameter sections differ def foo(x: Any) = macro Impls5.foo ^ Macros_Test_2.scala:22: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Unit] + or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.Context)(implicit x: c.Expr[Int]): c.Expr[Unit] macro implementations cannot have implicit parameters other than WeakTypeTag evidences def foo[U](x: Int) = macro Impls6.foo[T, U] ^ Macros_Test_2.scala:26: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): Nothing parameter lists have different length, found extra parameter y: c.Expr[Int] def foo(x: Int) = macro Impls7.foo ^ Macros_Test_2.scala:30: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.Context)(x: c.universe.Symbol): Nothing type mismatch for parameter x: c.Expr[Int] does not conform to c.universe.Symbol def foo(x: Int) = macro Impls8.foo ^ Macros_Test_2.scala:34: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.Context)(x: c.Tree, y: c.Tree): c.Tree found : (c: scala.reflect.macros.Context)(xs: c.Expr[Int]*): Nothing parameter lists have different length, required extra parameter y: c.Expr[Int] def foo(x: Int, y: Int) = macro Impls9.foo ^ Macros_Test_2.scala:38: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.Context)(x: c.Tree, y: c.Tree): c.Tree found : (c: scala.reflect.macros.Context)(y: c.Expr[Int], x: c.Expr[Int]): Nothing parameter names differ: x != y def foo(x: Int, y: Int) = macro Impls10.foo ^ Macros_Test_2.scala:42: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] + or : (c: scala.reflect.macros.Context): c.Tree found : (c: scala.reflect.macros.Context)(U: c.universe.Type): Nothing number of parameter sections differ def foo[U] = macro Impls11.foo[U] diff --git a/test/files/neg/macro-invalidsig/Impls_1.scala b/test/files/neg/macro-invalidsig/Impls_1.scala index e7d6c18f8d..d16ed26386 100644 --- a/test/files/neg/macro-invalidsig/Impls_1.scala +++ b/test/files/neg/macro-invalidsig/Impls_1.scala @@ -2,10 +2,7 @@ import scala.reflect.runtime.universe._ import scala.reflect.macros.Context object Impls1 { - def foo[U: c.WeakTypeTag: Numeric](c: Context) = { - import c.universe._ - Literal(Constant(42)) - } + def foo[U: c.WeakTypeTag: Numeric](c: Context) = { import c.universe._; q"42" } } object Impls2 { @@ -28,12 +25,11 @@ object Impls6 { def foo[T, U: c.WeakTypeTag](c: Context)(implicit x: c.Expr[Int]) = { import c.{prefix => prefix} import c.universe._ - val body = Block(List( - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("invoking foo_targs...")))), - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("type of prefix is: " + prefix.staticType)))), - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("U is: " + implicitly[c.WeakTypeTag[U]].tpe))))), - Literal(Constant(()))) - c.Expr[Unit](body) + c.Expr[Unit](q""" + println("invoking foo_targs...") + println("type of prefix is: " + ${prefix.staticType.toString}) + println("U is: " + ${implicitly[c.WeakTypeTag[U]].tpe.toString}) + """) } } @@ -71,18 +67,20 @@ object Impls14 { object Impls15 { def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + import c.universe._ println(implicitly[c.WeakTypeTag[T]]) println(implicitly[c.WeakTypeTag[U]]) println(V) - c.literalUnit + c.Expr[Unit](q"()") } } object Impls16 { def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + import c.universe._ println(implicitly[c.WeakTypeTag[T]]) println(implicitly[c.WeakTypeTag[U]]) println(V) - c.literalUnit + c.Expr[Unit](q"()") } }
\ No newline at end of file diff --git a/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala b/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala index 6ee71a3628..74c163596a 100644 --- a/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.macros.{Context => Ctx} object Impls { - def foo[U <: String](c: Ctx) = c.literalUnit + def foo[U <: String](c: Ctx) = { import c.universe._; c.Expr[Unit](q"()") } } diff --git a/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala b/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala index 498bd4f18d..11b6a8c3b0 100644 --- a/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala @@ -3,7 +3,6 @@ import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { import c.universe._ - val body = Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("it works")))) - c.Expr[Unit](body) + c.Expr[Unit](q"""println("it works")""") } }
\ No newline at end of file diff --git a/test/files/neg/macro-invalidusage-presuper/Impls_1.scala b/test/files/neg/macro-invalidusage-presuper/Impls_1.scala index b39a037c47..c4b57233c9 100644 --- a/test/files/neg/macro-invalidusage-presuper/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-presuper/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.macros.Context object Impls { - def impl(c: Context) = c.literalUnit + def impl(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } }
\ No newline at end of file diff --git a/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala b/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala index 69ef57d18d..64a9299ee6 100644 --- a/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala +++ b/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala @@ -4,8 +4,7 @@ object Impls { def impl(c: Ctx)(tag: String, x: c.Expr[_]) = { import c.{prefix => prefix} import c.universe._ - val body = Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant(tag)), Literal(Constant(prefix.toString)), x.tree)) - c.Expr[Unit](body) + c.Expr[Unit](q"println($tag, ${prefix.toString}, $x)") } def fooBString(c: Ctx)(x: c.Expr[_]) = impl(c)("fooBString", x) diff --git a/test/files/neg/macro-quasiquotes.check b/test/files/neg/macro-quasiquotes.check index 96ef75dd32..d000bb5316 100644 --- a/test/files/neg/macro-quasiquotes.check +++ b/test/files/neg/macro-quasiquotes.check @@ -1,6 +1,7 @@ Macros_1.scala:14: error: macro implementation has wrong shape: required: (x: Impls.this.c.Expr[Int]): Impls.this.c.Expr[Any] - found : (x: Impls.this.c.universe.Block): Impls.this.c.universe.Tree + or : (x: Impls.this.c.Tree): Impls.this.c.Tree + found : (x: Impls.this.c.universe.Block): Impls.this.c.Tree type mismatch for parameter x: Impls.this.c.Expr[Int] does not conform to Impls.this.c.universe.Block def m3(x: Int) = macro Impls.impl3 ^ diff --git a/test/files/neg/macro-without-xmacros-a/Impls_1.scala b/test/files/neg/macro-without-xmacros-a/Impls_1.scala index c6677c4fde..868616aace 100644 --- a/test/files/neg/macro-without-xmacros-a/Impls_1.scala +++ b/test/files/neg/macro-without-xmacros-a/Impls_1.scala @@ -3,16 +3,16 @@ import scala.reflect.macros.{Context => Ctx} object Impls { def foo_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - c.Expr(Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(1))))) + c.Expr(q"$x + 1") } def bar_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - c.Expr(Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(2))))) + c.Expr(q"$x + 2") } def quux_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - c.Expr(Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(3))))) + c.Expr(q"$x + 3") } }
\ No newline at end of file diff --git a/test/files/neg/macro-without-xmacros-b/Impls_1.scala b/test/files/neg/macro-without-xmacros-b/Impls_1.scala index c6677c4fde..868616aace 100644 --- a/test/files/neg/macro-without-xmacros-b/Impls_1.scala +++ b/test/files/neg/macro-without-xmacros-b/Impls_1.scala @@ -3,16 +3,16 @@ import scala.reflect.macros.{Context => Ctx} object Impls { def foo_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - c.Expr(Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(1))))) + c.Expr(q"$x + 1") } def bar_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - c.Expr(Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(2))))) + c.Expr(q"$x + 2") } def quux_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { import c.universe._ - c.Expr(Apply(Select(x.tree, TermName("$plus")), List(Literal(Constant(3))))) + c.Expr(q"$x + 3") } }
\ No newline at end of file diff --git a/test/files/neg/t5689.check b/test/files/neg/t5689.check index ad9b79cdcb..8cf0534e77 100644 --- a/test/files/neg/t5689.check +++ b/test/files/neg/t5689.check @@ -1,5 +1,6 @@ t5689.scala:4: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(i: c.Expr[Double]): c.Expr[String] + or : (c: scala.reflect.macros.Context)(i: c.Tree): c.Tree found : (c: scala.reflect.macros.Context)(i: c.Expr[Double]): c.Expr[Int] type mismatch for return type: c.Expr[Int] does not conform to c.Expr[String] def returnsString(i: Double): String = macro returnsIntImpl diff --git a/test/files/neg/t6123-explaintypes-macros.check b/test/files/neg/t6123-explaintypes-macros.check index ebcb8069d5..43f8371326 100644 --- a/test/files/neg/t6123-explaintypes-macros.check +++ b/test/files/neg/t6123-explaintypes-macros.check @@ -2,6 +2,7 @@ c.universe.Expr[Any]* <: c.universe.Expr[String]*? false BadMac_2.scala:6: error: macro implementation has wrong shape: required: (c: scala.reflect.macros.Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] + or : (c: scala.reflect.macros.Context)(format: c.Tree, params: Tree*): c.Tree found : (c: scala.reflect.macros.Context)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] type mismatch for parameter params: c.Expr[Any]* does not conform to c.Expr[String]* def printf(format: String, params: Any*): Unit = macro printf_impl diff --git a/test/files/disabled/t7020.check b/test/files/neg/t7020.check index f9600ca7fc..76390b243d 100644 --- a/test/files/disabled/t7020.check +++ b/test/files/neg/t7020.check @@ -1,17 +1,17 @@ t7020.scala:3: warning: match may not be exhaustive. -It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(??, _), List(_, _) +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) List(5) match { ^ t7020.scala:10: warning: match may not be exhaustive. -It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(??, _), List(_, _) +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) List(5) match { ^ t7020.scala:17: warning: match may not be exhaustive. -It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(??, _), List(_, _) +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) List(5) match { ^ t7020.scala:24: warning: match may not be exhaustive. -It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(??, _), List(_, _) +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) List(5) match { ^ error: No warnings can be incurred under -Xfatal-warnings. diff --git a/test/files/disabled/t7020.flags b/test/files/neg/t7020.flags index e8fb65d50c..e8fb65d50c 100644 --- a/test/files/disabled/t7020.flags +++ b/test/files/neg/t7020.flags diff --git a/test/files/disabled/t7020.scala b/test/files/neg/t7020.scala index cc5421bab1..cc5421bab1 100644 --- a/test/files/disabled/t7020.scala +++ b/test/files/neg/t7020.scala diff --git a/test/files/neg/t7157/Impls_Macros_1.scala b/test/files/neg/t7157/Impls_Macros_1.scala index 09f423fbab..9069d26e6e 100644 --- a/test/files/neg/t7157/Impls_Macros_1.scala +++ b/test/files/neg/t7157/Impls_Macros_1.scala @@ -2,30 +2,30 @@ import scala.reflect.macros.Context import language.experimental.macros object Macros { - def impl1_0_0(c: Context)() = c.literalUnit - def impl1_1_1(c: Context)(x: c.Expr[Int]) = c.literalUnit - def impl1_2_2(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = c.literalUnit + def impl1_0_0(c: Context)() = { import c.universe._; c.Expr[Unit](q"()") } + def impl1_1_1(c: Context)(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } + def impl1_2_2(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } def m1_0_0() = macro impl1_0_0 def m1_1_1(x: Int) = macro impl1_1_1 def m1_2_2(x: Int, y: Int) = macro impl1_2_2 - def impl1_0_inf(c: Context)(x: c.Expr[Int]*) = c.literalUnit - def impl1_1_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int]*) = c.literalUnit - def impl1_2_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = c.literalUnit + def impl1_0_inf(c: Context)(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } + def impl1_1_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } + def impl1_2_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } def m1_0_inf(x: Int*) = macro impl1_0_inf def m1_1_inf(x: Int, y: Int*) = macro impl1_1_inf def m1_2_inf(x: Int, y: Int, z: Int*) = macro impl1_2_inf - def impl2_0_0(c: Context)()() = c.literalUnit - def impl2_1_1(c: Context)()(x: c.Expr[Int]) = c.literalUnit - def impl2_2_2(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]) = c.literalUnit + def impl2_0_0(c: Context)()() = { import c.universe._; c.Expr[Unit](q"()") } + def impl2_1_1(c: Context)()(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } + def impl2_2_2(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } def m2_0_0()() = macro impl2_0_0 def m2_1_1()(x: Int) = macro impl2_1_1 def m2_2_2()(x: Int, y: Int) = macro impl2_2_2 - def impl2_0_inf(c: Context)()(x: c.Expr[Int]*) = c.literalUnit - def impl2_1_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]*) = c.literalUnit - def impl2_2_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = c.literalUnit + def impl2_0_inf(c: Context)()(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } + def impl2_1_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } + def impl2_2_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } def m2_0_inf()(x: Int*) = macro impl2_0_inf def m2_1_inf()(x: Int, y: Int*) = macro impl2_1_inf def m2_2_inf()(x: Int, y: Int, z: Int*) = macro impl2_2_inf diff --git a/test/files/neg/t7519-b.check b/test/files/neg/t7519-b.check new file mode 100644 index 0000000000..08d819eeec --- /dev/null +++ b/test/files/neg/t7519-b.check @@ -0,0 +1,6 @@ +Use_2.scala:6: error: type mismatch; + found : String + required: Q + val x: Q = ex.Mac.mac("asdf") + ^ +one error found diff --git a/test/files/neg/t7519-b/Mac_1.scala b/test/files/neg/t7519-b/Mac_1.scala new file mode 100644 index 0000000000..55b583d24b --- /dev/null +++ b/test/files/neg/t7519-b/Mac_1.scala @@ -0,0 +1,14 @@ +// get expected error message without package declaration +package ex + +import scala.language.experimental.macros +import scala.reflect.macros._ + +object IW { + def foo(a: String): String = ??? +} +object Mac { + def mac(s: String): String = macro macImpl + def macImpl(c: Context)(s: c.Expr[String]): c.Expr[String] = + c.universe.reify(IW.foo(s.splice)) +} diff --git a/test/files/neg/t7519-b/Use_2.scala b/test/files/neg/t7519-b/Use_2.scala new file mode 100644 index 0000000000..413e40e25e --- /dev/null +++ b/test/files/neg/t7519-b/Use_2.scala @@ -0,0 +1,8 @@ +trait Q +trait K + +object Use { + implicit def cd[T](p: T)(implicit ev: T => K): Q = ??? + val x: Q = ex.Mac.mac("asdf") +} + diff --git a/test/files/pos/annotated-treecopy/Impls_Macros_1.scala b/test/files/pos/annotated-treecopy/Impls_Macros_1.scala index ecf8916c46..9b7af0c3b8 100644 --- a/test/files/pos/annotated-treecopy/Impls_Macros_1.scala +++ b/test/files/pos/annotated-treecopy/Impls_Macros_1.scala @@ -38,10 +38,10 @@ object Macros { val reifiedExpr = c.Expr[scala.reflect.runtime.universe.Expr[T => U]](reifiedTree) val template = c.universe.reify(new (T => U) with TypedFunction { - override def toString = c.literal(tp+" => "+ttag.tpe+" { "+b1.toString+" } ").splice // DEBUG + override def toString = c.Expr[String](q"""${tp+" => "+ttag.tpe+" { "+b1.toString+" } "}""").splice // DEBUG def tree = reifiedExpr.splice.tree - val typeIn = c.literal(tp.toString).splice - val typeOut = c.literal(ttag.tpe.toString).splice + val typeIn = c.Expr[String](q"${tp.toString}").splice + val typeOut = c.Expr[String](q"${ttag.tpe.toString}").splice def apply(_arg: T): U = c.Expr[U](b1)(ttag.asInstanceOf[c.WeakTypeTag[U]]).splice }) val untyped = c.resetLocalAttrs(template.tree) diff --git a/test/files/pos/t5692a/Macros_1.scala b/test/files/pos/t5692a/Macros_1.scala index 06b5a3de36..e530713bb0 100644 --- a/test/files/pos/t5692a/Macros_1.scala +++ b/test/files/pos/t5692a/Macros_1.scala @@ -1,6 +1,6 @@ import scala.reflect.macros.Context object Macros { - def impl[T](c: Context) = c.literalUnit + def impl[T](c: Context) = { import c.universe._; c.Expr[Unit](q"()") } def foo[T] = macro impl[T] }
\ No newline at end of file diff --git a/test/files/pos/t5692b/Macros_1.scala b/test/files/pos/t5692b/Macros_1.scala index b28d19f903..45c672cfce 100644 --- a/test/files/pos/t5692b/Macros_1.scala +++ b/test/files/pos/t5692b/Macros_1.scala @@ -1,6 +1,6 @@ import scala.reflect.macros.Context object Macros { - def impl[T, U](c: Context) = c.literalUnit + def impl[T, U](c: Context) = { import c.universe._; c.Expr[Unit](q"()") } def foo[T, U] = macro impl[T, U] }
\ No newline at end of file diff --git a/test/files/pos/t7461/Macros_1.scala b/test/files/pos/t7461/Macros_1.scala index 353dec66d7..8621650f77 100644 --- a/test/files/pos/t7461/Macros_1.scala +++ b/test/files/pos/t7461/Macros_1.scala @@ -6,7 +6,7 @@ object Macros { import c.universe._ val wut = c.typeCheck(Select(Literal(Constant(10)), newTermName("$minus")), silent = true) // println(showRaw(wut, printIds = true, printTypes = true)) - c.literalUnit + c.Expr[Unit](q"()") } def foo = macro impl diff --git a/test/files/pos/t7649.scala b/test/files/pos/t7649.scala index a1b02f63f1..ff3c626fca 100644 --- a/test/files/pos/t7649.scala +++ b/test/files/pos/t7649.scala @@ -4,7 +4,7 @@ object Test { reify { // The lookup of the implicit WeakTypeTag[Any] // was triggering an unpositioned tree. - c.Expr[Any](Literal(Constant(0))).splice + c.Expr[Any](q"0").splice } import scala.reflect.ClassTag diff --git a/test/files/run/macro-bundle-repl.check b/test/files/run/macro-bundle-repl.check index b9c809f037..c11c48dc55 100644 --- a/test/files/run/macro-bundle-repl.check +++ b/test/files/run/macro-bundle-repl.check @@ -7,13 +7,13 @@ import scala.language.experimental.macros scala> import scala.reflect.macros.Macro import scala.reflect.macros.Macro -scala> trait Bar extends Macro { def impl = c.literalUnit };def bar = macro Bar.impl +scala> trait Bar extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar = macro Bar.impl defined trait Bar defined term macro bar: Unit scala> bar -scala> trait Foo extends Macro { def impl = c.literalUnit } +scala> trait Foo extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } } defined trait Foo scala> def foo = macro Foo.impl diff --git a/test/files/run/macro-bundle-repl.scala b/test/files/run/macro-bundle-repl.scala index 50783c8cba..3171aaacc2 100644 --- a/test/files/run/macro-bundle-repl.scala +++ b/test/files/run/macro-bundle-repl.scala @@ -4,9 +4,9 @@ object Test extends ReplTest { def code = """ import scala.language.experimental.macros import scala.reflect.macros.Macro -trait Bar extends Macro { def impl = c.literalUnit };def bar = macro Bar.impl +trait Bar extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar = macro Bar.impl bar -trait Foo extends Macro { def impl = c.literalUnit } +trait Foo extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } } def foo = macro Foo.impl foo """ diff --git a/test/files/run/macro-bundle-static/Impls_Macros_1.scala b/test/files/run/macro-bundle-static/Impls_Macros_1.scala index 831dac6df5..e81fd0dbd6 100644 --- a/test/files/run/macro-bundle-static/Impls_Macros_1.scala +++ b/test/files/run/macro-bundle-static/Impls_Macros_1.scala @@ -4,8 +4,8 @@ import scala.language.experimental.macros object Enclosing { trait Impl extends Macro { - def mono = c.literalUnit - def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString) + def mono = { import c.universe._; c.Expr[Unit](q"()") } + def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString}") } def weird = macro mono } } @@ -18,8 +18,8 @@ object Macros { package pkg { object Enclosing { trait Impl extends Macro { - def mono = c.literalTrue - def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString + c.weakTypeOf[T].toString) + def mono = { import c.universe._; c.Expr[Boolean](q"true") } + def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString + c.weakTypeOf[T].toString}") } def weird = macro mono } } diff --git a/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala b/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala index 676935682e..8c7df2cdc5 100644 --- a/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala +++ b/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala @@ -2,8 +2,8 @@ import scala.reflect.macros.Context import scala.reflect.macros.Macro trait Impl extends Macro { - def mono = c.literalUnit - def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString) + def mono = { import c.universe._; c.Expr[Unit](q"()") } + def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString}") } def weird = macro mono } @@ -14,8 +14,8 @@ object Macros { package pkg { trait Impl extends Macro { - def mono = c.literalTrue - def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString + c.weakTypeOf[T].toString) + def mono = { import c.universe._; c.Expr[Boolean](q"true") } + def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString + c.weakTypeOf[T].toString}") } def weird = macro mono } diff --git a/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala index bc4a9fded7..53511ebc72 100644 --- a/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala +++ b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala @@ -15,7 +15,7 @@ object Complex { val recur = c.inferImplicitValue(trecur, silent = true) if (recur == EmptyTree) c.abort(c.enclosingPosition, s"couldn't synthesize $trecur") } - c.literalNull + c.Expr[Null](Literal(Constant(null))) } implicit object ComplexString extends Complex[String] diff --git a/test/files/run/macro-enclosures/Impls_Macros_1.scala b/test/files/run/macro-enclosures/Impls_Macros_1.scala index cd54028676..68f1920cdd 100644 --- a/test/files/run/macro-enclosures/Impls_Macros_1.scala +++ b/test/files/run/macro-enclosures/Impls_Macros_1.scala @@ -1,13 +1,16 @@ import scala.reflect.macros.Context object Macros { - def impl(c: Context) = c.universe.reify { - println("enclosingPackage = " + c.literal(c.enclosingPackage.toString).splice) - println("enclosingClass = " + c.literal(c.enclosingClass.toString).splice) - println("enclosingImpl = " + c.literal(c.enclosingImpl.toString).splice) - println("enclosingTemplate = " + c.literal(c.enclosingTemplate.toString).splice) - println("enclosingMethod = " + c.literal(c.enclosingMethod.toString).splice) - println("enclosingDef = " + c.literal(c.enclosingDef.toString).splice) + def impl(c: Context) = { + import c.universe._ + reify { + println("enclosingPackage = " + c.Expr[String](Literal(Constant(c.enclosingPackage.toString))).splice) + println("enclosingClass = " + c.Expr[String](Literal(Constant(c.enclosingClass.toString))).splice) + println("enclosingImpl = " + c.Expr[String](Literal(Constant(c.enclosingImpl.toString))).splice) + println("enclosingTemplate = " + c.Expr[String](Literal(Constant(c.enclosingTemplate.toString))).splice) + println("enclosingMethod = " + c.Expr[String](Literal(Constant(c.enclosingMethod.toString))).splice) + println("enclosingDef = " + c.Expr[String](Literal(Constant(c.enclosingDef.toString))).splice) + } } def foo = macro impl diff --git a/test/files/run/macro-expand-tparams-bounds/Impls_1.scala b/test/files/run/macro-expand-tparams-bounds/Impls_1.scala index f9103aaf8f..d63f034e9b 100644 --- a/test/files/run/macro-expand-tparams-bounds/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-bounds/Impls_1.scala @@ -1,12 +1,12 @@ import scala.reflect.macros.Context object Impls1 { - def foo[U <: String](c: Context): c.Expr[Unit] = c.literalUnit + def foo[U <: String](c: Context): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"()") } } class C class D extends C object Impls2 { - def foo[U <: C](c: Context): c.Expr[Unit] = c.literalUnit + def foo[U <: C](c: Context): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"()") } } diff --git a/test/files/run/macro-expand-tparams-prefix/Impls_1.scala b/test/files/run/macro-expand-tparams-prefix/Impls_1.scala index e92396d1b4..a98c4abe78 100644 --- a/test/files/run/macro-expand-tparams-prefix/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-prefix/Impls_1.scala @@ -5,8 +5,7 @@ object Impls1 { def foo[U: c.WeakTypeTag](c: Context)(x: c.Expr[U]) = { import c.universe._ val U = implicitly[c.WeakTypeTag[U]] - val body = Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant(U.toString)))) - c.Expr[Unit](body) + c.Expr[Unit](q"println(${U.toString})") } } @@ -16,18 +15,18 @@ object Impls2 { val T = implicitly[c.WeakTypeTag[T]] val U = implicitly[c.WeakTypeTag[U]] val body = Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant(T.toString + " " + U.toString)))) - c.Expr[Unit](body) + c.Expr[Unit](q"""println(${T.toString} + " " + ${U.toString})""") } } object Impls345 { def foo[T, U: c.WeakTypeTag, V](c: Context)(implicit T: c.WeakTypeTag[T], V: c.WeakTypeTag[V]): c.Expr[Unit] = { import c.universe._ - c.Expr(Block(List( - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant(T.toString)))), - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant(implicitly[c.WeakTypeTag[U]].toString)))), - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant(V.toString))))), - Literal(Constant(())))) + c.Expr(q""" + println(${T.toString}) + println(${implicitly[c.WeakTypeTag[U]].toString}) + println(${V.toString}) + """) } } diff --git a/test/files/run/macro-impl-default-params/Impls_Macros_1.scala b/test/files/run/macro-impl-default-params/Impls_Macros_1.scala index 95d746980e..043675ec00 100644 --- a/test/files/run/macro-impl-default-params/Impls_Macros_1.scala +++ b/test/files/run/macro-impl-default-params/Impls_Macros_1.scala @@ -6,13 +6,12 @@ object Impls { import c.{prefix => prefix} import c.universe._ val U = implicitly[c.WeakTypeTag[U]] - val body = Block(List( - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("invoking foo_targs...")))), - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("type of prefix is: " + prefix.staticType)))), - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("type of prefix tree is: " + prefix.tree.tpe)))), - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("U is: " + U.tpe))))), - Literal(Constant(()))) - c.Expr[Unit](body) + c.Expr[Unit](q""" + println("invoking foo_targs...") + println("type of prefix is: " + ${prefix.staticType.toString}) + println("type of prefix tree is: " + ${prefix.tree.tpe.toString}) + println("U is: " + ${U.tpe.toString}) + """) } } diff --git a/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala b/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala index 738c88bbc8..5f3bbac719 100644 --- a/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala +++ b/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala @@ -3,10 +3,7 @@ import scala.reflect.macros.{Context => Ctx} object Impls { def foo(unconventionalName: Ctx)(x: unconventionalName.Expr[Int]) = { import unconventionalName.universe._ - val body = Block(List( - Apply(Select(Ident(definitions.PredefModule), TermName("println")), List(Literal(Constant("invoking foo..."))))), - Literal(Constant(()))) - unconventionalName.Expr[Unit](body) + unconventionalName.Expr[Unit](q"""println("invoking foo...")""") } } diff --git a/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala b/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala index 9b8dafaa97..24eacb36de 100644 --- a/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala +++ b/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.macros.{Context => Ctx} object Impls { - def foo[U <: String](c: Ctx): c.Expr[Unit] = c.literalUnit + def foo[U <: String](c: Ctx): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"()") } } diff --git a/test/files/run/macro-openmacros/Impls_Macros_1.scala b/test/files/run/macro-openmacros/Impls_Macros_1.scala index 50a1782431..884d7f8825 100644 --- a/test/files/run/macro-openmacros/Impls_Macros_1.scala +++ b/test/files/run/macro-openmacros/Impls_Macros_1.scala @@ -14,9 +14,9 @@ object Macros { } import c.universe._ - val next = if (c.enclosingMacros.length < 3) c.Expr[Unit](Select(Ident(c.mirror.staticModule("Macros")), TermName("foo"))) else c.literalUnit + val next = if (c.enclosingMacros.length < 3) c.Expr[Unit](Select(Ident(c.mirror.staticModule("Macros")), TermName("foo"))) else c.Expr[Unit](Literal(Constant(()))) c.universe.reify { - println(c.literal(normalizePaths(c.enclosingMacros.toString)).splice) + println(c.Expr[String](Literal(Constant(normalizePaths(c.enclosingMacros.toString)))).splice) next.splice } } diff --git a/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala b/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala index 5330d0e32b..f454fc430a 100644 --- a/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala @@ -2,9 +2,9 @@ import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { + import c.universe._ val x1 = c.Expr[Int](c.resetAllAttrs(x.tree)) -// was: c.literal(x1.splice) - c.literal(c.eval(x1)) + c.Expr[Int](Literal(Constant(c.eval(x1)))) } } diff --git a/test/files/run/macro-settings/Impls_Macros_1.scala b/test/files/run/macro-settings/Impls_Macros_1.scala index 83d80a5bff..9257784cf2 100644 --- a/test/files/run/macro-settings/Impls_Macros_1.scala +++ b/test/files/run/macro-settings/Impls_Macros_1.scala @@ -1,8 +1,11 @@ import scala.reflect.macros.Context object Impls { - def impl(c: Context) = c.universe.reify { - println(c.literal(c.settings.toString).splice) + def impl(c: Context) = { + import c.universe._ + reify { + println(c.Expr[String](Literal(Constant(c.settings.toString))).splice) + } } } diff --git a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala index 8d7d3b5d3d..1b914ac797 100644 --- a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala @@ -11,7 +11,8 @@ object Macros { val fileName = fun.pos.source.file.file.getName val line = fun.pos.line val charOffset = fun.pos.point - c.universe.reify { SourceLocation1(outer.splice, c.literal(fileName).splice, c.literal(line).splice, c.literal(charOffset).splice) } + def literal[T](x: T) = c.Expr[T](Literal(Constant(x))) + c.universe.reify { SourceLocation1(outer.splice, literal(fileName).splice, literal(line).splice, literal(charOffset).splice) } } implicit def sourceLocation: SourceLocation1 = macro impl diff --git a/test/files/run/macro-sip19/Impls_Macros_1.scala b/test/files/run/macro-sip19/Impls_Macros_1.scala index 4c165ed1b8..95e19c4fd1 100644 --- a/test/files/run/macro-sip19/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19/Impls_Macros_1.scala @@ -7,7 +7,8 @@ object Macros { val fileName = fun.pos.source.file.file.getName val line = fun.pos.line val charOffset = fun.pos.point - c.universe.reify { SourceLocation(c.literal(fileName).splice, c.literal(line).splice, c.literal(charOffset).splice) } + def literal[T](x: T) = c.Expr[T](Literal(Constant(x))) + c.universe.reify { SourceLocation(literal(fileName).splice, literal(line).splice, literal(charOffset).splice) } } implicit def sourceLocation: SourceLocation = macro impl diff --git a/test/files/run/macro-system-properties.check b/test/files/run/macro-system-properties.check index ff96a34426..c61fe7f2cf 100644 --- a/test/files/run/macro-system-properties.check +++ b/test/files/run/macro-system-properties.check @@ -8,7 +8,7 @@ import reflect.macros.Context scala> object GrabContext { def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) // System.properties lets you stash true globals (unlike statics which are classloader scoped) - def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit } + def impl(c: Context)() = { import c.universe._; System.getProperties.put("lastContext", c); c.Expr[Unit](q"()") } def grab() = macro impl } defined object GrabContext diff --git a/test/files/run/macro-system-properties.scala b/test/files/run/macro-system-properties.scala index e182defc81..9dcd044dbd 100644 --- a/test/files/run/macro-system-properties.scala +++ b/test/files/run/macro-system-properties.scala @@ -7,7 +7,7 @@ object Test extends ReplTest { object GrabContext { def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) // System.properties lets you stash true globals (unlike statics which are classloader scoped) - def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit } + def impl(c: Context)() = { import c.universe._; System.getProperties.put("lastContext", c); c.Expr[Unit](q"()") } def grab() = macro impl } object Test { class C(implicit a: Any) { GrabContext.grab } } diff --git a/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala b/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala index dbeb7efbc0..cd37c269b5 100644 --- a/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala @@ -6,7 +6,7 @@ object Macros { val tree1 = Apply(Select(Literal(Constant(1)), TermName("$minus$greater")), List(Literal(Constant(2)))) val ttree1 = c.typeCheck(tree1, withImplicitViewsDisabled = false) - c.literal(ttree1.toString) + c.Expr[String](Literal(Constant(ttree1.toString))) } def foo_with_implicits_enabled = macro impl_with_implicits_enabled @@ -17,10 +17,10 @@ object Macros { try { val tree2 = Apply(Select(Literal(Constant(1)), TermName("$minus$greater")), List(Literal(Constant(2)))) val ttree2 = c.typeCheck(tree2, withImplicitViewsDisabled = true) - c.literal(ttree2.toString) + c.Expr[String](Literal(Constant(ttree2.toString))) } catch { case ex: Throwable => - c.literal(ex.toString) + c.Expr[String](Literal(Constant(ex.toString))) } } diff --git a/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala b/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala index ff535fea8d..2532cfd2b9 100644 --- a/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala @@ -7,7 +7,7 @@ object Macros { val ru = Select(Select(Select(Select(Ident(TermName("scala")), TermName("reflect")), TermName("runtime")), TermName("package")), TermName("universe")) val tree1 = Apply(Select(ru, TermName("reify")), List(Literal(Constant(2)))) val ttree1 = c.typeCheck(tree1, withMacrosDisabled = false) - c.literal(ttree1.toString) + c.Expr[String](Literal(Constant(ttree1.toString))) } def foo_with_macros_enabled = macro impl_with_macros_enabled @@ -23,7 +23,7 @@ object Macros { val tree2 = Apply(Select(Ident(ru), TermName("reify")), List(Literal(Constant(2)))) val ttree2 = c.typeCheck(tree2, withMacrosDisabled = true) - c.literal(ttree2.toString) + c.Expr[String](Literal(Constant(ttree2.toString))) } def foo_with_macros_disabled = macro impl_with_macros_disabled diff --git a/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala b/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala index a96e0c53b6..7b22793df9 100644 --- a/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala @@ -7,7 +7,7 @@ object Macros { val ru = Select(Select(Select(Select(Ident(TermName("scala")), TermName("reflect")), TermName("runtime")), TermName("package")), TermName("universe")) val tree1 = Apply(Select(ru, TermName("reify")), List(Apply(Select(Ident(TermName("scala")), TermName("Array")), List(Literal(Constant(2)))))) val ttree1 = c.typeCheck(tree1, withMacrosDisabled = false) - c.literal(ttree1.toString) + c.Expr[String](Literal(Constant(ttree1.toString))) } def foo_with_macros_enabled = macro impl_with_macros_enabled @@ -23,7 +23,7 @@ object Macros { val tree2 = Apply(Select(Ident(ru), TermName("reify")), List(Apply(Select(Ident(TermName("scala")), TermName("Array")), List(Literal(Constant(2)))))) val ttree2 = c.typeCheck(tree2, withMacrosDisabled = true) - c.literal(ttree2.toString) + c.Expr[String](Literal(Constant(ttree2.toString))) } def foo_with_macros_disabled = macro impl_with_macros_disabled diff --git a/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala b/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala index bcbd12817b..6695a297ea 100644 --- a/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala +++ b/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala @@ -2,14 +2,20 @@ import scala.reflect.runtime.universe._ import scala.reflect.macros.Context object Macros { - def cons_impl[A: c.WeakTypeTag](c: Context)(x: c.Expr[A], xs: c.Expr[List[A]]): c.Expr[List[A]] = c.universe.reify { - println("A = " + c.literal(implicitly[c.WeakTypeTag[A]].toString).splice) - x.splice :: xs.splice + def cons_impl[A: c.WeakTypeTag](c: Context)(x: c.Expr[A], xs: c.Expr[List[A]]): c.Expr[List[A]] = { + import c.universe._ + reify { + println("A = " + c.Expr[String](Literal(Constant(implicitly[c.WeakTypeTag[A]].toString))).splice) + x.splice :: xs.splice + } } - def nil_impl[B: c.WeakTypeTag](c: Context): c.Expr[List[B]] = c.universe.reify { - println("B = " + c.literal(implicitly[c.WeakTypeTag[B]].toString).splice) - Nil + def nil_impl[B: c.WeakTypeTag](c: Context): c.Expr[List[B]] = { + import c.universe._ + reify { + println("B = " + c.Expr[String](Literal(Constant(implicitly[c.WeakTypeTag[B]].toString))).splice) + Nil + } } def cons[A](x: A, xs: List[A]): List[A] = macro cons_impl[A] diff --git a/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala b/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala index 0244273b6f..85877b3f13 100644 --- a/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala +++ b/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala @@ -2,7 +2,10 @@ import scala.reflect.runtime.universe._ import scala.reflect.macros.Context object Macros { - def impl[T: c.WeakTypeTag](c: Context)(foo: c.Expr[T]): c.Expr[Unit] = c.universe.reify { println(c.literal(implicitly[c.WeakTypeTag[T]].toString).splice) } + def impl[T: c.WeakTypeTag](c: Context)(foo: c.Expr[T]): c.Expr[Unit] = { + import c.universe._ + reify { println(c.Expr[String](Literal(Constant(implicitly[c.WeakTypeTag[T]].toString))).splice) } + } def foo[T](foo: T) = macro impl[T] }
\ No newline at end of file diff --git a/test/files/run/reflection-fancy-java-classes.check b/test/files/run/reflection-fancy-java-classes.check new file mode 100644 index 0000000000..258208dd99 --- /dev/null +++ b/test/files/run/reflection-fancy-java-classes.check @@ -0,0 +1,12 @@ +===== JAVA POV ===== +class Foo_1$1 +getEnclosingClass = class Foo_1 +getEnclosingMethod = null +getEnclosingConstructor = null +isMemberClass = false +isLocalClass = false +isAnonymousClass = true + +===== SCALA POV ===== +class 1 +object Foo_1 diff --git a/test/files/run/reflection-fancy-java-classes/Foo_1.java b/test/files/run/reflection-fancy-java-classes/Foo_1.java new file mode 100644 index 0000000000..f6fd76124b --- /dev/null +++ b/test/files/run/reflection-fancy-java-classes/Foo_1.java @@ -0,0 +1,5 @@ +public class Foo_1 { + public static Bar bar = new Bar(); + private static class Bar { + } +}
\ No newline at end of file diff --git a/test/files/run/reflection-fancy-java-classes/Test_2.scala b/test/files/run/reflection-fancy-java-classes/Test_2.scala new file mode 100644 index 0000000000..271960ee79 --- /dev/null +++ b/test/files/run/reflection-fancy-java-classes/Test_2.scala @@ -0,0 +1,20 @@ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} + +object Test extends App { + println("===== JAVA POV =====") + val jfancy = Class.forName("Foo_1$1") + println(jfancy) + println("getEnclosingClass = " + jfancy.getEnclosingClass) + println("getEnclosingMethod = " + jfancy.getEnclosingMethod) + println("getEnclosingConstructor = " + jfancy.getEnclosingConstructor) + println("isMemberClass = " + jfancy.isMemberClass) + println("isLocalClass = " + jfancy.isLocalClass) + println("isAnonymousClass = " + jfancy.isAnonymousClass) + + println("") + println("===== SCALA POV =====") + val sfancy = cm.classSymbol(jfancy) + println(sfancy) + println(sfancy.owner) +}
\ No newline at end of file diff --git a/test/files/run/repl-term-macros.check b/test/files/run/repl-term-macros.check index 2a143a1777..63bafe401b 100644 --- a/test/files/run/repl-term-macros.check +++ b/test/files/run/repl-term-macros.check @@ -9,7 +9,7 @@ import language.experimental.macros scala> -scala> def impl1(c: Context) = c.literalUnit +scala> def impl1(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } impl1: (c: scala.reflect.macros.Context)c.Expr[Unit] scala> def foo1 = macro impl1 @@ -19,7 +19,7 @@ scala> foo1 scala> -scala> def impl2(c: Context)() = c.literalUnit +scala> def impl2(c: Context)() = { import c.universe._; c.Expr[Unit](q"()") } impl2: (c: scala.reflect.macros.Context)()c.Expr[Unit] scala> def foo2() = macro impl2 @@ -29,7 +29,7 @@ scala> foo2() scala> -scala> def impl3(c: Context)(x: c.Expr[Int])(y: c.Expr[Int]) = c.literalUnit +scala> def impl3(c: Context)(x: c.Expr[Int])(y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } impl3: (c: scala.reflect.macros.Context)(x: c.Expr[Int])(y: c.Expr[Int])c.Expr[Unit] scala> def foo3(x: Int)(y: Int) = macro impl3 diff --git a/test/files/run/repl-term-macros.scala b/test/files/run/repl-term-macros.scala index f826259be9..125e397b22 100644 --- a/test/files/run/repl-term-macros.scala +++ b/test/files/run/repl-term-macros.scala @@ -5,15 +5,15 @@ object Test extends ReplTest { import scala.reflect.macros.Context import language.experimental.macros -def impl1(c: Context) = c.literalUnit +def impl1(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } def foo1 = macro impl1 foo1 -def impl2(c: Context)() = c.literalUnit +def impl2(c: Context)() = { import c.universe._; c.Expr[Unit](q"()") } def foo2() = macro impl2 foo2() -def impl3(c: Context)(x: c.Expr[Int])(y: c.Expr[Int]) = c.literalUnit +def impl3(c: Context)(x: c.Expr[Int])(y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } def foo3(x: Int)(y: Int) = macro impl3 foo3(2)(3) """ diff --git a/test/files/run/t5894.scala b/test/files/run/t5894.scala index abeec32365..5deda34489 100644 --- a/test/files/run/t5894.scala +++ b/test/files/run/t5894.scala @@ -4,7 +4,7 @@ class Test object Test { def foo = macro fooImpl - def fooImpl(c: reflect.macros.Context) = c.literalUnit + def fooImpl(c: reflect.macros.Context) = { import c.universe._; c.Expr[Unit](q"()") } def main(args: Array[String]) { try { diff --git a/test/files/run/t5923a/Macros_1.scala b/test/files/run/t5923a/Macros_1.scala index 97076eb102..741379cf34 100644 --- a/test/files/run/t5923a/Macros_1.scala +++ b/test/files/run/t5923a/Macros_1.scala @@ -46,7 +46,7 @@ object Macros { if (sym.isParameter && !sym.isSkolem) TypeTag.Nothing.asInstanceOf[TypeTag[T]] else ttag0 } - reify(C[T](c.literal(weakTypeOf[T].toString).splice)) + reify(C[T](c.Expr[String](Literal(Constant(weakTypeOf[T].toString))).splice)) } } }
\ No newline at end of file diff --git a/test/files/run/t5940.scala b/test/files/run/t5940.scala index 147ff38256..9c8f702c68 100644 --- a/test/files/run/t5940.scala +++ b/test/files/run/t5940.scala @@ -7,12 +7,12 @@ object Test extends DirectTest { import scala.reflect.macros.Context object Impls { - def impl(c: Context) = c.literalUnit + def impl(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } } object Macros { //import Impls._ - def impl(c: Context) = c.literalUnit + def impl(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } def foo = macro impl } """ diff --git a/test/files/run/t6199-toolbox.scala b/test/files/run/t6199-toolbox.scala index 89015f5878..6ba5e50f66 100644 --- a/test/files/run/t6199-toolbox.scala +++ b/test/files/run/t6199-toolbox.scala @@ -4,5 +4,5 @@ import scala.tools.reflect.ToolBox object Test extends App { val tb = cm.mkToolBox() - println(tb.eval(Literal(Constant(())))) + println(tb.eval(q"()")) }
\ No newline at end of file diff --git a/test/files/run/t6240a/StepOne.java b/test/files/run/t6240a/StepOne.java index 7abd148d69..342d617c79 100644 --- a/test/files/run/t6240a/StepOne.java +++ b/test/files/run/t6240a/StepOne.java @@ -12,7 +12,7 @@ import java.net.MalformedURLException; public class StepOne { public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { - String[] launchPaths = System.getProperty("launch.classpath").split(":"); + String[] launchPaths = System.getProperty("launch.classpath").split(File.pathSeparator); // move away StepThree File tempDir = File.createTempFile("temp", Long.toString(System.nanoTime())); @@ -38,4 +38,4 @@ public class StepOne { Method main = stepTwo.getDeclaredMethod("main", String[].class); main.invoke(null, (Object)(new String[]{})); } -}
\ No newline at end of file +} diff --git a/test/files/run/t6240a/Test.scala b/test/files/run/t6240a/Test.scala index 6ae43c4809..05c3678cbe 100644 --- a/test/files/run/t6240a/Test.scala +++ b/test/files/run/t6240a/Test.scala @@ -11,6 +11,5 @@ object Test extends App { assert(new File(testClassesDir).exists, testClassesDir) val fullTestClassesClasspath = testClassesDir + prop("path.separator") + prop("java.class.path") val javaBinary = if (new File(prop("javacmd")).isAbsolute) prop("javacmd") else prop("java.home") + "/bin/" + prop("javacmd") - assert(new File(javaBinary).exists, javaBinary) List(javaBinary, "-cp", testClassesDir, "-Dlaunch.classpath=" + fullTestClassesClasspath, "StepOne").! }
\ No newline at end of file diff --git a/test/files/run/t6240b/StepOne.java b/test/files/run/t6240b/StepOne.java index 7abd148d69..342d617c79 100644 --- a/test/files/run/t6240b/StepOne.java +++ b/test/files/run/t6240b/StepOne.java @@ -12,7 +12,7 @@ import java.net.MalformedURLException; public class StepOne { public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { - String[] launchPaths = System.getProperty("launch.classpath").split(":"); + String[] launchPaths = System.getProperty("launch.classpath").split(File.pathSeparator); // move away StepThree File tempDir = File.createTempFile("temp", Long.toString(System.nanoTime())); @@ -38,4 +38,4 @@ public class StepOne { Method main = stepTwo.getDeclaredMethod("main", String[].class); main.invoke(null, (Object)(new String[]{})); } -}
\ No newline at end of file +} diff --git a/test/files/run/t6240b/Test.scala b/test/files/run/t6240b/Test.scala index 6ae43c4809..05c3678cbe 100644 --- a/test/files/run/t6240b/Test.scala +++ b/test/files/run/t6240b/Test.scala @@ -11,6 +11,5 @@ object Test extends App { assert(new File(testClassesDir).exists, testClassesDir) val fullTestClassesClasspath = testClassesDir + prop("path.separator") + prop("java.class.path") val javaBinary = if (new File(prop("javacmd")).isAbsolute) prop("javacmd") else prop("java.home") + "/bin/" + prop("javacmd") - assert(new File(javaBinary).exists, javaBinary) List(javaBinary, "-cp", testClassesDir, "-Dlaunch.classpath=" + fullTestClassesClasspath, "StepOne").! }
\ No newline at end of file diff --git a/test/files/run/t6381.check b/test/files/run/t6381.check index 5070b67e46..c9d4713aa8 100644 --- a/test/files/run/t6381.check +++ b/test/files/run/t6381.check @@ -4,8 +4,10 @@ Type :help for more information. scala> import language.experimental.macros import language.experimental.macros -scala> def pos_impl(c: reflect.macros.Context): c.Expr[String] = - c.literal(c.enclosingPosition.getClass.toString) +scala> def pos_impl(c: reflect.macros.Context): c.Expr[String] = { + import c.universe._ + c.Expr[String](Literal(Constant(c.enclosingPosition.getClass.toString))) +} pos_impl: (c: scala.reflect.macros.Context)c.Expr[String] scala> def pos = macro pos_impl diff --git a/test/files/run/t6381.scala b/test/files/run/t6381.scala index 859ec3cb30..4c2a40fe87 100644 --- a/test/files/run/t6381.scala +++ b/test/files/run/t6381.scala @@ -3,8 +3,10 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { def code = """ |import language.experimental.macros - |def pos_impl(c: reflect.macros.Context): c.Expr[String] = - | c.literal(c.enclosingPosition.getClass.toString) + |def pos_impl(c: reflect.macros.Context): c.Expr[String] = { + | import c.universe._ + | c.Expr[String](Literal(Constant(c.enclosingPosition.getClass.toString))) + |} |def pos = macro pos_impl |pos |""".stripMargin.trim diff --git a/test/files/run/t7008-scala-defined/Impls_Macros_2.scala b/test/files/run/t7008-scala-defined/Impls_Macros_2.scala index 94fd99018e..477829f200 100644 --- a/test/files/run/t7008-scala-defined/Impls_Macros_2.scala +++ b/test/files/run/t7008-scala-defined/Impls_Macros_2.scala @@ -3,9 +3,10 @@ import scala.reflect.macros.Context object Macros { def impl(c: Context) = { + import c.universe._ val decls = c.typeOf[ScalaClassWithCheckedExceptions_1[_]].declarations.toList val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) - c.universe.reify(println(c.literal(s).splice)) + reify(println(c.Expr[String](Literal(Constant(s))).splice)) } def foo = macro impl diff --git a/test/files/run/t7008/Impls_Macros_2.scala b/test/files/run/t7008/Impls_Macros_2.scala index 7a17314085..63c3f9d696 100644 --- a/test/files/run/t7008/Impls_Macros_2.scala +++ b/test/files/run/t7008/Impls_Macros_2.scala @@ -3,9 +3,10 @@ import scala.reflect.macros.Context object Macros { def impl(c: Context) = { + import c.universe._ val decls = c.typeOf[JavaClassWithCheckedExceptions_1[_]].declarations.toList val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) - c.universe.reify(println(c.literal(s).splice)) + reify(println(c.Expr[String](Literal(Constant(s))).splice)) } def foo = macro impl diff --git a/test/files/run/t7047/Impls_Macros_1.scala b/test/files/run/t7047/Impls_Macros_1.scala index 2992e3efe4..a5d55c3a42 100644 --- a/test/files/run/t7047/Impls_Macros_1.scala +++ b/test/files/run/t7047/Impls_Macros_1.scala @@ -12,7 +12,7 @@ object Macros { } catch { case _: Exception => } - c.literalNull + c.Expr[Null](Literal(Constant(null))) } def foo = macro impl diff --git a/test/files/run/t7375b/Macros_1.scala b/test/files/run/t7375b/Macros_1.scala index 70e79cc2b4..7a307805db 100644 --- a/test/files/run/t7375b/Macros_1.scala +++ b/test/files/run/t7375b/Macros_1.scala @@ -11,7 +11,7 @@ object Macros { def foo = macro impl def impl(c: Context) = { import c.universe._ - def test[T: c.TypeTag] = reify(println(c.literal(c.reifyRuntimeClass(c.typeOf[T]).toString).splice)).tree + def test[T: c.TypeTag] = reify(println(c.Expr[String](Literal(Constant(c.reifyRuntimeClass(c.typeOf[T]).toString))).splice)).tree def tests = Block(List(test[C1], test[C2], test[F1], test[F2]), Literal(Constant(()))) c.Expr[Unit](tests) } |