From e6912050bf6132cbe6338ce1d6786703757575ce Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Mon, 23 Jul 2012 18:16:01 +0200 Subject: SI-2038 make pt fully-defined when typing Typed dropExistential turns existentials in the expected type (pt) that's passed to `typed` into `BoundedWildcardType`s, but those should not end up in trees when typing a `Typed` node, we didn't check for the type being fully defined (`isFullyDefined`) (and thus did not make it fully defined by turning these BWTs into existentials again using `makeFullyDefined`) --- test/files/pos/t2038.scala | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test/files/pos/t2038.scala (limited to 'test/files') diff --git a/test/files/pos/t2038.scala b/test/files/pos/t2038.scala new file mode 100644 index 0000000000..17b1a702dd --- /dev/null +++ b/test/files/pos/t2038.scala @@ -0,0 +1,5 @@ +class Test { + List(Some(classOf[java.lang.Integer]), Some(classOf[Int])).map { + case Some(f: Class[_]) => f.cast(???) + } +} \ No newline at end of file -- cgit v1.2.3 From 6eb55d4b7ab804ba581157ed39df42ded885a12e Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 24 Jul 2012 16:54:07 -0700 Subject: Fix SI-4560, NoSuchMethodErrors involving self types. Following this commit are reversions of three prior commits which introduced difficulties of their own, plus extra tests for this issue and SI-4601, all of which I pinched from jrudolph. Maybe there was a good reason for some of the complicated code related to this ticket. I took the naive position that if we avoided generating a method call to a particular receiver if the receiver has no such method, we would encounter fewer NoSuchMethodErrors. I would believe one can construct a scenario which this doesn't handle correctly, but it's hard to believe this isn't a big improvement. Review by @jrudolph, @odersky. --- .../scala/tools/nsc/backend/icode/GenICode.scala | 20 ++++++++++++---- test/files/run/t4560b.check | 2 ++ test/files/run/t4560b.scala | 28 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 test/files/run/t4560b.check create mode 100644 test/files/run/t4560b.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 982267097b..c46b650949 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -73,6 +73,14 @@ abstract class GenICode extends SubComponent { ctx1 } + /** If the selector type has a member with the right name, + * it is the host class; otherwise the symbol's owner. + */ + def findHostClass(selector: Type, sym: Symbol) = selector member sym.name match { + case NoSymbol => log(s"Rejecting $selector as host class for $sym") ; sym.owner + case _ => selector.typeSymbol + } + /////////////////// Code generation /////////////////////// def gen(tree: Tree, ctx: Context): Context = tree match { @@ -949,13 +957,14 @@ abstract class GenICode extends SubComponent { */ fun match { case Select(qual, _) => - val qualSym = qual.tpe.typeSymbol + val qualSym = findHostClass(qual.tpe, sym) + if (qualSym == ArrayClass) cm setTargetTypeKind toTypeKind(qual.tpe) else cm setHostClass qualSym - debuglog( + log( if (qualSym == ArrayClass) "Stored target type kind " + toTypeKind(qual.tpe) + " for " + sym.fullName - else "Set more precise host class for " + sym.fullName + " host: " + qualSym + else s"Set more precise host class for ${sym.fullName} hostClass: $qualSym" ) case _ => } @@ -1005,13 +1014,14 @@ abstract class GenICode extends SubComponent { case Select(qualifier, selector) => val sym = tree.symbol generatedType = toTypeKind(sym.info) - val hostClass = qualifier.tpe.typeSymbol.orElse(sym.owner) + val hostClass = findHostClass(qualifier.tpe, sym) + log(s"Host class of $sym with qual $qualifier (${qualifier.tpe}) is $hostClass") if (sym.isModule) { genLoadModule(ctx, tree) } else if (sym.isStaticMember) { - ctx.bb.emit(LOAD_FIELD(sym, true) setHostClass hostClass, tree.pos) + ctx.bb.emit(LOAD_FIELD(sym, true) setHostClass hostClass, tree.pos) ctx } else { diff --git a/test/files/run/t4560b.check b/test/files/run/t4560b.check new file mode 100644 index 0000000000..7ee6e19b28 --- /dev/null +++ b/test/files/run/t4560b.check @@ -0,0 +1,2 @@ +23 +SUCCESS diff --git a/test/files/run/t4560b.scala b/test/files/run/t4560b.scala new file mode 100644 index 0000000000..97fe00ce37 --- /dev/null +++ b/test/files/run/t4560b.scala @@ -0,0 +1,28 @@ +object Outer { + class Tester + private[Outer] trait B4 { _: Tester => + protected val FREQ = 23 + def fail() = { + println(FREQ) + } + } + object C4 extends Tester with B4 +} + +object Outer2 { + abstract class A5 + private[Outer2] trait C5 { + def impl() { println("SUCCESS") } + } + trait B5 extends C5 { self: A5 => + def fail() { impl() } + } + object Test5 extends A5 with B5 with C5 +} + +object Test { + def main(args: Array[String]): Unit = { + Outer.C4.fail() + Outer2.Test5.fail() + } +} -- cgit v1.2.3 From cf709c2dd23b7f1f659e52bcb8beb098c5d02d50 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Sun, 22 Jul 2012 11:46:02 +0200 Subject: SI-4560 - improved test Added all the known cases of failing self-types. Added tests for symbol access (SI-4601) as well which should now be fixed for all of the same cases as well. --- test/files/run/t4560.check | 8 ++++-- test/files/run/t4560.scala | 65 +++++++++++++++++++++++++++++++------------- test/pending/run/t4560.scala | 9 ------ 3 files changed, 52 insertions(+), 30 deletions(-) delete mode 100644 test/pending/run/t4560.scala (limited to 'test/files') diff --git a/test/files/run/t4560.check b/test/files/run/t4560.check index fd3c81a4d7..f8cb0833ae 100644 --- a/test/files/run/t4560.check +++ b/test/files/run/t4560.check @@ -1,2 +1,6 @@ -5 -5 +'Test +Success 1 +'Test +Success 2 +'Test +Success 3 diff --git a/test/files/run/t4560.scala b/test/files/run/t4560.scala index 1392077e46..9979199067 100644 --- a/test/files/run/t4560.scala +++ b/test/files/run/t4560.scala @@ -1,39 +1,66 @@ -object Pimper { - implicit def pimp(i: Int) = new { - def test: String = i.toString - } -} +// SI-4560 (and SI-4601): Reflection caches are expected in the wrong classfiles +// with various differing constellations of self-types. This leads to runtime exceptions +// when the reflection caches are accessed. This tests both reflection cache accesses +// for structural type method invocations (`y.f()`) (SI-4560) and accesses to symbols which are +// handled similarly (SI-4601) -trait A +// TEST 1 +// self-type is other trait -trait B { - self: A => +trait Aa +trait Ab - def test { - import Pimper.pimp +trait B { + self: Aa with Ab => - println(5.test) + def y = new { def f() = println("Success 1") } + def fail() = { + println('Test) + y.f() } } +object Test1 extends Aa with Ab with B + +// TEST 2 +// self-type is class + class A2 trait B2 { self: A2 => - def test { - import Pimper.pimp + def y = new { def f() = println("Success 2") } + def fail() = { + println('Test) + y.f() + } +} + +object Test2 extends A2 with B2 + +// TEST 3 +// self-type is singleton type + +trait B3 { + this: Test3.type => - println(5.test) + def y = new { def f() = println("Success 3") } + def fail() = { + println('Test) + y.f() } } -object Test extends A with B { +object Test3 extends B3 { + def test { fail() } +} + +object Test { def main(args: Array[String]) { - test - Test2.test + Test1.fail() + Test2.fail() + Test3.fail() } } -object Test2 extends A2 with B2 - diff --git a/test/pending/run/t4560.scala b/test/pending/run/t4560.scala deleted file mode 100644 index fe62136319..0000000000 --- a/test/pending/run/t4560.scala +++ /dev/null @@ -1,9 +0,0 @@ -trait B { - this: Test.type => - - def y = new { def f() = () } - def fail() = y.f() -} -object Test extends B { - def main(args: Array[String]): Unit = fail() -} \ No newline at end of file -- cgit v1.2.3 From ae28472bc727b25040da4b1428fcb14137d01102 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Wed, 25 Jul 2012 17:16:11 +0200 Subject: SI-5958 This deserves a stable type `this` (or the self variable) passed as an actual argument to a method should receive a singleton type when computing the method's resultType this is necessary if the method's type depends on that argument --- src/reflect/scala/reflect/internal/TreeGen.scala | 2 ++ test/files/pos/t5958.scala | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/files/pos/t5958.scala (limited to 'test/files') diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala index c3a6fce164..285700f9ff 100644 --- a/src/reflect/scala/reflect/internal/TreeGen.scala +++ b/src/reflect/scala/reflect/internal/TreeGen.scala @@ -143,6 +143,8 @@ abstract class TreeGen extends makro.TreeBuilder { /** Computes stable type for a tree if possible */ def stableTypeFor(tree: Tree): Option[Type] = tree match { + case This(_) if tree.symbol != null && !tree.symbol.isError => + Some(ThisType(tree.symbol)) case Ident(_) if tree.symbol.isStable => Some(singleType(tree.symbol.owner.thisType, tree.symbol)) case Select(qual, _) if ((tree.symbol ne null) && (qual.tpe ne null)) && // turned assert into guard for #4064 diff --git a/test/files/pos/t5958.scala b/test/files/pos/t5958.scala new file mode 100644 index 0000000000..3b910f3633 --- /dev/null +++ b/test/files/pos/t5958.scala @@ -0,0 +1,15 @@ +class Test { + def newComponent(u: Universe): u.Component = ??? + + class Universe { self => + class Component + + newComponent(this): this.Component // error, but should be fine since this is a stable reference + newComponent(self): self.Component // error, but should be fine since this is a stable reference + newComponent(self): this.Component // error, but should be fine since this is a stable reference + newComponent(this): self.Component // error, but should be fine since this is a stable reference + + val u = this + newComponent(u): u.Component // ok + } +} \ No newline at end of file -- cgit v1.2.3 From 9e04e2365a7210f7e671137d8f70e475688b0885 Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Thu, 26 Jul 2012 11:40:13 +0200 Subject: Instrument all classes in `instrumented` package. Extend instrumenting infrastructure to instrument classes in `instrumented` package. This is useful because very often you need to put your classes into non-empty package. E.g. inliner doesn't work properly with empty package at the moment so in order to test any behaviour we need to put classes in some other package that is instrumented. Added testing code for that to instrumentation test-case. Review by @phaller. --- .../scala/tools/partest/javaagent/ASMTransformer.java | 4 +++- test/files/instrumented/InstrumentationTest.check | 4 ++++ test/files/instrumented/InstrumentationTest.scala | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'test/files') diff --git a/src/partest/scala/tools/partest/javaagent/ASMTransformer.java b/src/partest/scala/tools/partest/javaagent/ASMTransformer.java index 643c683002..09cd485d6b 100644 --- a/src/partest/scala/tools/partest/javaagent/ASMTransformer.java +++ b/src/partest/scala/tools/partest/javaagent/ASMTransformer.java @@ -21,7 +21,9 @@ public class ASMTransformer implements ClassFileTransformer { // we instrument all classes from empty package (!className.contains("/") || // we instrument all classes from scala package - className.startsWith("scala/")); + className.startsWith("scala/") || + // we instrument all classes from `instrumented` package + className.startsWith("instrumented/")); } public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) { diff --git a/test/files/instrumented/InstrumentationTest.check b/test/files/instrumented/InstrumentationTest.check index 3652df270a..f0f447560a 100644 --- a/test/files/instrumented/InstrumentationTest.check +++ b/test/files/instrumented/InstrumentationTest.check @@ -1,4 +1,8 @@ true Method call statistics: + 1 Foo1.()V + 1 Foo1.someMethod()I + 1 instrumented/Foo2.()V + 1 instrumented/Foo2.someMethod()I 1 scala/Predef$.println(Ljava/lang/Object;)V 1 scala/runtime/BoxesRunTime.boxToBoolean(Z)Ljava/lang/Boolean; diff --git a/test/files/instrumented/InstrumentationTest.scala b/test/files/instrumented/InstrumentationTest.scala index ec5314c624..0e53f80857 100644 --- a/test/files/instrumented/InstrumentationTest.scala +++ b/test/files/instrumented/InstrumentationTest.scala @@ -1,11 +1,27 @@ import scala.tools.partest.instrumented.Instrumentation._ +/** We check if classes put in empty package are properly instrumented */ +class Foo1 { + def someMethod = 0 +} + +/** We check if classes put in `instrumented` package are properly instrumented */ +package instrumented { + class Foo2 { + def someMethod = 0 + } +} + /** Tests if instrumentation itself works correctly */ object Test { def main(args: Array[String]) { // force predef initialization before profiling Predef startProfiling() + val foo1 = new Foo1 + foo1.someMethod + val foo2 = new instrumented.Foo2 + foo2.someMethod // should box the boolean println(true) stopProfiling() -- cgit v1.2.3 From f2c1736b94c96a6e6950801ee053b30e872985a4 Mon Sep 17 00:00:00 2001 From: Miguel Garcia Date: Thu, 26 Jul 2012 20:35:21 +0200 Subject: SI-6142: warn @inline-methods ending up not inlined (rightfully or not) --- .../backend/icode/analysis/TypeFlowAnalysis.scala | 11 ++++++---- .../scala/tools/nsc/backend/opt/Inliners.scala | 25 +++++++++++++++++++++- test/files/neg/t3234.check | 2 ++ test/files/neg/t3234.flags | 1 + test/files/neg/t3234.scala | 19 ++++++++++++++++ test/files/pos/t3234.flags | 1 - test/files/pos/t3234.scala | 19 ---------------- 7 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 test/files/neg/t3234.check create mode 100644 test/files/neg/t3234.flags create mode 100644 test/files/neg/t3234.scala delete mode 100644 test/files/pos/t3234.flags delete mode 100644 test/files/pos/t3234.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala index 7a5615ac26..962c47f443 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala @@ -470,6 +470,8 @@ abstract class TypeFlowAnalysis { val isOnWatchlist = mutable.Set.empty[Instruction] + val warnIfInlineFails = mutable.Set.empty[opcodes.CALL_METHOD] // cache for a given IMethod (ie cleared on Inliner.analyzeMethod). + /* Each time CallerCalleeInfo.isSafeToInline determines a concrete callee is unsafe to inline in the current caller, the fact is recorded in this TFA instance for the purpose of avoiding devoting processing to that callsite next time. The condition of "being unsafe to inline in the current caller" sticks across inlinings and TFA re-inits @@ -510,6 +512,7 @@ abstract class TypeFlowAnalysis { // initially populate the watchlist with all callsites standing a chance of being inlined isOnWatchlist.clear() relevantBBs.clear() + warnIfInlineFails.clear() /* TODO Do we want to perform inlining in non-finally exception handlers? * Seems counterproductive (the larger the method the less likely it will be JITed. * It's not that putting on radar only `linearizer linearizeAt (m, m.startBlock)` makes for much shorter inlining times (a minor speedup nonetheless) @@ -533,11 +536,11 @@ abstract class TypeFlowAnalysis { private def putOnRadar(blocks: Traversable[BasicBlock]) { for(bb <- blocks) { - val preCands = bb.toList collect { - case cm : opcodes.CALL_METHOD - if isPreCandidate(cm) /* && !isReceiverKnown(cm) */ - => cm + val calls = bb.toList collect { case cm : opcodes.CALL_METHOD => cm } + for(c <- calls; if(inliner.hasInline(c.method))) { + warnIfInlineFails += c } + val preCands = calls filter isPreCandidate isOnWatchlist ++= preCands } relevantBBs ++= blocks diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index 44acfed411..cce18d436f 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -129,11 +129,15 @@ abstract class Inliners extends SubComponent { override def apply(c: IClass) { queue += c } override def run() { + knownLacksInline.clear() + knownHasInline.clear() try { super.run() for(c <- queue) { inliner analyzeClass c } } finally { inliner.clearCaches() + knownLacksInline.clear() + knownHasInline.clear() } } } @@ -157,7 +161,21 @@ abstract class Inliners extends SubComponent { } } - def hasInline(sym: Symbol) = sym hasAnnotation ScalaInlineClass + val knownLacksInline = mutable.Set.empty[Symbol] // cache to avoid multiple inliner.hasInline() calls. + val knownHasInline = mutable.Set.empty[Symbol] // as above. Motivated by the need to warn on "inliner failures". + + def hasInline(sym: Symbol) = { + if (knownLacksInline(sym)) false + else if(knownHasInline(sym)) true + else { + val b = (sym hasAnnotation ScalaInlineClass) + if(b) { knownHasInline += sym } + else { knownLacksInline += sym } + + b + } + } + def hasNoInline(sym: Symbol) = sym hasAnnotation ScalaNoInlineClass /** @@ -536,6 +554,10 @@ abstract class Inliners extends SubComponent { } while (retry && count < MAX_INLINE_RETRY) + for(inlFail <- tfa.warnIfInlineFails) { + warn(inlFail.pos, "At the end of the day, could not inline @inline-marked method " + inlFail.method.originalName.decode) + } + m.normalize if (sizeBeforeInlining > 0) { val instrAfterInlining = m.code.instructionCount @@ -731,6 +753,7 @@ abstract class Inliners extends SubComponent { tfa.remainingCALLs.remove(instr) // this bookkpeeping is done here and not in MTFAGrowable.reinit due to (1st) convenience and (2nd) necessity. tfa.isOnWatchlist.remove(instr) // ditto + tfa.warnIfInlineFails.remove(instr) val targetPos = instr.pos log("Inlining " + inc.m + " in " + caller.m + " at pos: " + posToStr(targetPos)) diff --git a/test/files/neg/t3234.check b/test/files/neg/t3234.check new file mode 100644 index 0000000000..477b021e5e --- /dev/null +++ b/test/files/neg/t3234.check @@ -0,0 +1,2 @@ +error: there were 1 inliner warnings; re-run with -Yinline-warnings for details +one error found diff --git a/test/files/neg/t3234.flags b/test/files/neg/t3234.flags new file mode 100644 index 0000000000..c9cefdc4b9 --- /dev/null +++ b/test/files/neg/t3234.flags @@ -0,0 +1 @@ +-Yinline -Xfatal-warnings \ No newline at end of file diff --git a/test/files/neg/t3234.scala b/test/files/neg/t3234.scala new file mode 100644 index 0000000000..443d0467f0 --- /dev/null +++ b/test/files/neg/t3234.scala @@ -0,0 +1,19 @@ +trait Trait1 { + // need more work before this one works + // @inline + def foo2(n: Int) = n*n +} + +trait Trait2 { + @inline def foo3(n: Int) = 1 +} + +class Base extends Trait1 { + @inline def foo(n: Int) = n +} + +object Test extends Base with Trait2 { + def main(args: Array[String]) = { + println(foo(42) + foo2(11) + foo3(2)) + } +} \ No newline at end of file diff --git a/test/files/pos/t3234.flags b/test/files/pos/t3234.flags deleted file mode 100644 index c9cefdc4b9..0000000000 --- a/test/files/pos/t3234.flags +++ /dev/null @@ -1 +0,0 @@ --Yinline -Xfatal-warnings \ No newline at end of file diff --git a/test/files/pos/t3234.scala b/test/files/pos/t3234.scala deleted file mode 100644 index 443d0467f0..0000000000 --- a/test/files/pos/t3234.scala +++ /dev/null @@ -1,19 +0,0 @@ -trait Trait1 { - // need more work before this one works - // @inline - def foo2(n: Int) = n*n -} - -trait Trait2 { - @inline def foo3(n: Int) = 1 -} - -class Base extends Trait1 { - @inline def foo(n: Int) = n -} - -object Test extends Base with Trait2 { - def main(args: Array[String]) = { - println(foo(42) + foo2(11) + foo3(2)) - } -} \ No newline at end of file -- cgit v1.2.3 From b964bac5e295df92d304e97657d01481d63f2d62 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 26 Jul 2012 16:01:27 +0200 Subject: Raw string interpolator Adds a raw string interpolator raw"..." which does not do any escape sequence processing. --- src/library/scala/StringContext.scala | 24 ++++++++++++++++++++---- test/files/run/rawstrings.check | 1 + test/files/run/rawstrings.scala | 3 +++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 test/files/run/rawstrings.check create mode 100644 test/files/run/rawstrings.scala (limited to 'test/files') diff --git a/src/library/scala/StringContext.scala b/src/library/scala/StringContext.scala index f11dfb72ae..7d37fa4aa1 100644 --- a/src/library/scala/StringContext.scala +++ b/src/library/scala/StringContext.scala @@ -26,7 +26,7 @@ case class StringContext(parts: String*) { * @param `args` The arguments to be checked. * @throws An `IllegalArgumentException` if this is not the case. */ - def checkLengths(args: Any*): Unit = + def checkLengths(args: Seq[Any]): Unit = if (parts.length != args.length + 1) throw new IllegalArgumentException("wrong number of arguments for interpolated string") @@ -42,11 +42,27 @@ case class StringContext(parts: String*) { * @throws A `StringContext.InvalidEscapeException` if if a `parts` string contains a backslash (`\`) character * that does not start a valid escape sequence. */ - def s(args: Any*): String = { - checkLengths(args: _*) + def s(args: Any*): String = standardInterpolator(treatEscapes, args) + + /** The raw string interpolator. + * + * It inserts its arguments between corresponding parts of the string context. + * As opposed to the simple string interpolator `s`, this one does not treat + * standard escape sequences as defined in the Scala specification. + * @param `args` The arguments to be inserted into the resulting string. + * @throws An `IllegalArgumentException` + * if the number of `parts` in the enclosing `StringContext` does not exceed + * the number of arguments `arg` by exactly 1. + * @throws A `StringContext.InvalidEscapeException` if if a `parts` string contains a backslash (`\`) character + * that does not start a valid escape sequence. + */ + def raw(args: Any*): String = standardInterpolator(identity, args) + + def standardInterpolator(process: String => String, args: Seq[Any]): String = { + checkLengths(args) val pi = parts.iterator val ai = args.iterator - val bldr = new java.lang.StringBuilder(treatEscapes(pi.next())) + val bldr = new java.lang.StringBuilder(process(pi.next())) while (ai.hasNext) { bldr append ai.next bldr append treatEscapes(pi.next()) diff --git a/test/files/run/rawstrings.check b/test/files/run/rawstrings.check new file mode 100644 index 0000000000..36e63594df --- /dev/null +++ b/test/files/run/rawstrings.check @@ -0,0 +1 @@ +[\n\t'"$] diff --git a/test/files/run/rawstrings.scala b/test/files/run/rawstrings.scala new file mode 100644 index 0000000000..9df64f6625 --- /dev/null +++ b/test/files/run/rawstrings.scala @@ -0,0 +1,3 @@ +object Test extends App { + println(raw"[\n\t'${'"'}$$]") +} -- cgit v1.2.3 From ed915c54cc8b3575ed3245c5793bfb051b5e98c1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 28 Jul 2012 18:13:59 +0200 Subject: Closed 6029 ... ... in a less nice way than I would like. Essentially, we mask type errors at later stages that arise from comparing existentials and skolems because we know that they are not tracked correctly through all tree transformations. Never mind that all these types are going erased anyway shortly afterwards. It does not smell nice. But as I write in the comment, maybe the best way out is to avoid skolems altogether. Such a change by far exceeds the scope of this pull request however. --- .../scala/tools/nsc/typechecker/Typers.scala | 64 ++++++++++++++-------- test/files/pos/t6029.scala | 3 + 2 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 test/files/pos/t6029.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 269ab9611a..b1c3249e35 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1194,30 +1194,46 @@ trait Typers extends Modes with Adaptations with Tags { } val found = tree.tpe - val req = pt - if (!found.isErroneous && !req.isErroneous) { - if (!context.reportErrors && isPastTyper && req.skolemsExceptMethodTypeParams.nonEmpty) { - // Ignore type errors raised in later phases that are due to mismatching types with existential skolems - // We have lift crashing in 2.9 with an adapt failure in the pattern matcher. - // Here's my hypothsis why this happens. The pattern matcher defines a variable of type - // - // val x: T = expr - // - // where T is the type of expr, but T contains existential skolems ts. - // In that case, this value definition does not typecheck. - // The value definition - // - // val x: T forSome { ts } = expr - // - // would typecheck. Or one can simply leave out the type of the `val`: - // - // val x = expr - context.unit.warning(tree.pos, "recovering from existential Skolem type error in tree \n" + tree + "\nwith type " + tree.tpe + "\n expected type = " + pt + "\n context = " + context.tree) - adapt(tree, mode, deriveTypeWithWildcards(pt.skolemsExceptMethodTypeParams)(pt)) - } else { - // create an actual error - AdaptTypeError(tree, found, req) + if (!found.isErroneous && !pt.isErroneous) { + if (!context.reportErrors && isPastTyper) { + val (bound, req) = pt match { + case ExistentialType(qs, tpe) => (qs, tpe) + case _ => (Nil, pt) + } + val boundOrSkolems = bound ++ pt.skolemsExceptMethodTypeParams + if (boundOrSkolems.nonEmpty) { + // Ignore type errors raised in later phases that are due to mismatching types with existential skolems + // We have lift crashing in 2.9 with an adapt failure in the pattern matcher. + // Here's my hypothsis why this happens. The pattern matcher defines a variable of type + // + // val x: T = expr + // + // where T is the type of expr, but T contains existential skolems ts. + // In that case, this value definition does not typecheck. + // The value definition + // + // val x: T forSome { ts } = expr + // + // would typecheck. Or one can simply leave out the type of the `val`: + // + // val x = expr + // + // SI-6029 shows another case where we also fail (in uncurry), but this time the expected + // type is an existential type. + // + // The reason for both failures have to do with the way we (don't) transform + // skolem types along with the trees that contain them. We'd need a + // radically different approach to do it. But before investing a lot of time to + // to do this (I have already sunk 3 full days with in the end futile attempts + // to consistently transform skolems and fix 6029), I'd like to + // investigate ways to avoid skolems completely. + // + log("recovering from existential or skolem type error in tree \n" + tree + "\nwith type " + tree.tpe + "\n expected type = " + pt + "\n context = " + context.tree) + return adapt(tree, mode, deriveTypeWithWildcards(boundOrSkolems)(pt)) + } } + // create an actual error + AdaptTypeError(tree, found, pt) } setError(tree) } @@ -4531,7 +4547,7 @@ trait Typers extends Modes with Adaptations with Tags { assert(errorContainer == null, "Cannot set ambiguous error twice for identifier") errorContainer = tree } - + val fingerPrint: Long = name.fingerPrint var defSym: Symbol = tree.symbol // the directly found symbol diff --git a/test/files/pos/t6029.scala b/test/files/pos/t6029.scala new file mode 100644 index 0000000000..8f1bbb4ebf --- /dev/null +++ b/test/files/pos/t6029.scala @@ -0,0 +1,3 @@ +final case class V[A](x: A) extends AnyVal { + def flatMap[B](f: A => V[B]) = if (true) this else f(x) +} -- cgit v1.2.3 From 95d53235834ab650ded6768958697d2901fd4dd3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 28 Jul 2012 18:35:49 +0200 Subject: Closes SI-5882 I have added a restriction that value classes may not contain inner classes or objects. This makes sense as the "outer" field of any such classes or objects would be ephemeral, with surprising results. SIP-15 has been changed accordingly. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 7 ++++++- test/files/neg/t5882.check | 15 +++++++++++++++ test/files/neg/t5882.scala | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/files/neg/t5882.check create mode 100644 test/files/neg/t5882.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 269ab9611a..393cbadc6a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1385,6 +1385,11 @@ trait Typers extends Modes with Adaptations with Tags { unit.error(clazz.pos, "value class needs to have exactly one public val parameter") } } + body foreach { + case md: ModuleDef => unit.error(md.pos, "value class may not have nested module definitions") + case cd: ClassDef => unit.error(cd.pos, "value class may not have nested class definitions") + case _ => + } for (tparam <- clazz.typeParams) if (tparam hasAnnotation definitions.SpecializedClass) unit.error(tparam.pos, "type parameter of value class may not be specialized") @@ -4531,7 +4536,7 @@ trait Typers extends Modes with Adaptations with Tags { assert(errorContainer == null, "Cannot set ambiguous error twice for identifier") errorContainer = tree } - + val fingerPrint: Long = name.fingerPrint var defSym: Symbol = tree.symbol // the directly found symbol diff --git a/test/files/neg/t5882.check b/test/files/neg/t5882.check new file mode 100644 index 0000000000..df01c7bc0a --- /dev/null +++ b/test/files/neg/t5882.check @@ -0,0 +1,15 @@ +t5882.scala:2: warning: case classes without a parameter list have been deprecated; +use either case objects or case classes with `()' as parameter list. + case class Scope + ^ +t5882.scala:2: error: value class may not have nested class definitions + case class Scope + ^ +t5882.scala:3: error: value class may not have nested class definitions + class Foo + ^ +t5882.scala:4: error: value class may not have nested module definitions + object Bar + ^ +one warning found +three errors found diff --git a/test/files/neg/t5882.scala b/test/files/neg/t5882.scala new file mode 100644 index 0000000000..1233eb636f --- /dev/null +++ b/test/files/neg/t5882.scala @@ -0,0 +1,5 @@ +class NodeOps(val n: Any) extends AnyVal { + case class Scope + class Foo + object Bar +} -- cgit v1.2.3 From daf0953c1f5d76b468a75911f3f22162d631415c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 29 Jul 2012 14:10:36 +0200 Subject: Closes SI-5878 We need to impose an additional rule on value classes: They may not unbox directly or indirectly to themselves. --- .../scala/tools/nsc/transform/ExtensionMethods.scala | 13 +++++++++++-- test/files/neg/t5878.check | 13 +++++++++++++ test/files/neg/t5878.scala | 6 ++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/t5878.check create mode 100644 test/files/neg/t5878.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala index 5f66cadbc9..e937589f54 100644 --- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala +++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala @@ -78,13 +78,13 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { } /** This method removes the `$this` argument from the parameter list a method. - * + * * A method may be a `PolyType`, in which case we tear out the `$this` and the class * type params from its nested `MethodType`. * It may be a `MethodType`, either with a curried parameter list in which the first argument * is a `$this` - we just return the rest of the list. * This means that the corresponding symbol was generated during `extmethods`. - * + * * It may also be a `MethodType` in which the `$this` does not appear in a curried parameter list. * The curried lists disappear during `uncurry`, and the methods may be duplicated afterwards, * for instance, during `specialize`. @@ -105,6 +105,14 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { private val extensionDefs = mutable.Map[Symbol, mutable.ListBuffer[Tree]]() + def checkNonCyclic(pos: Position, seen: Set[Symbol], clazz: Symbol): Unit = + if (seen contains clazz) + unit.error(pos, "value class may not unbox to itself") + else { + val unboxed = erasure.underlyingOfValueClass(clazz).typeSymbol + if (unboxed.isDerivedValueClass) checkNonCyclic(pos, seen + clazz, unboxed) + } + def extensionMethInfo(extensionMeth: Symbol, origInfo: Type, clazz: Symbol): Type = { var newTypeParams = cloneSymbolsAtOwner(clazz.typeParams, extensionMeth) val thisParamType = appliedType(clazz.typeConstructor, newTypeParams map (_.tpeHK)) @@ -129,6 +137,7 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { tree match { case Template(_, _, _) => if (currentOwner.isDerivedValueClass) { + checkNonCyclic(currentOwner.pos, Set(), currentOwner) extensionDefs(currentOwner.companionModule) = new mutable.ListBuffer[Tree] currentOwner.primaryConstructor.makeNotPrivate(NoSymbol) super.transform(tree) diff --git a/test/files/neg/t5878.check b/test/files/neg/t5878.check new file mode 100644 index 0000000000..50dba0d272 --- /dev/null +++ b/test/files/neg/t5878.check @@ -0,0 +1,13 @@ +t5878.scala:1: error: value class may not unbox to itself +case class Foo(x: Bar) extends AnyVal + ^ +t5878.scala:2: error: value class may not unbox to itself +case class Bar(x: Foo) extends AnyVal + ^ +t5878.scala:4: error: value class may not unbox to itself +class Foo1(val x: Bar1) extends AnyVal + ^ +t5878.scala:5: error: value class may not unbox to itself +class Bar1(val x: Foo1) extends AnyVal + ^ +four errors found diff --git a/test/files/neg/t5878.scala b/test/files/neg/t5878.scala new file mode 100644 index 0000000000..b4e33627ef --- /dev/null +++ b/test/files/neg/t5878.scala @@ -0,0 +1,6 @@ +case class Foo(x: Bar) extends AnyVal +case class Bar(x: Foo) extends AnyVal + +class Foo1(val x: Bar1) extends AnyVal +class Bar1(val x: Foo1) extends AnyVal + -- cgit v1.2.3 From aad84ecba3eda180197bfbbb45a02393358c4c46 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 29 Jul 2012 16:23:20 +0200 Subject: SI-5799 Secondary constructors in value classes not allowed I changed the SIP and added a test. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 8 ++++++-- test/files/neg/t5799.check | 4 ++++ test/files/neg/t5799.scala | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/t5799.check create mode 100644 test/files/neg/t5799.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 393cbadc6a..130b03ebec 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1386,8 +1386,12 @@ trait Typers extends Modes with Adaptations with Tags { } } body foreach { - case md: ModuleDef => unit.error(md.pos, "value class may not have nested module definitions") - case cd: ClassDef => unit.error(cd.pos, "value class may not have nested class definitions") + case md: ModuleDef => + unit.error(md.pos, "value class may not have nested module definitions") + case cd: ClassDef => + unit.error(cd.pos, "value class may not have nested class definitions") + case md: DefDef if md.symbol.isConstructor && !md.symbol.isPrimaryConstructor => + unit.error(md.pos, "value class may not have secondary constructors") case _ => } for (tparam <- clazz.typeParams) diff --git a/test/files/neg/t5799.check b/test/files/neg/t5799.check new file mode 100644 index 0000000000..10e2658d56 --- /dev/null +++ b/test/files/neg/t5799.check @@ -0,0 +1,4 @@ +t5799.scala:2: error: value class may not have secondary constructors + def this(s: String) = this(s.toDouble) + ^ +one error found diff --git a/test/files/neg/t5799.scala b/test/files/neg/t5799.scala new file mode 100644 index 0000000000..9bd6ab7dd1 --- /dev/null +++ b/test/files/neg/t5799.scala @@ -0,0 +1,8 @@ +class Foo(val bar: Double) extends AnyVal { + def this(s: String) = this(s.toDouble) +} +object Test { + def main(args: Array[String]): Unit = + new Foo("") + } + -- cgit v1.2.3 From 0152dbe969520914ce1730c4a81597bc362c9c5b Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 15 May 2012 09:40:23 +0200 Subject: Fixed SI-5603. Early definitions now get transparent positions. This includes a fix for a minor problem described in #594 - ensureNonOverlapping still focuses on default position when outside of early defs. Review by @dragos, @odersky. --- src/compiler/scala/tools/nsc/ast/Trees.scala | 13 +++--- .../tools/nsc/interactive/RangePositions.scala | 48 ++++++++++------------ src/reflect/scala/reflect/internal/Positions.scala | 14 ++++--- test/files/run/t5603.check | 29 +++++++++++++ test/files/run/t5603.scala | 42 +++++++++++++++++++ 5 files changed, 107 insertions(+), 39 deletions(-) create mode 100644 test/files/run/t5603.check create mode 100644 test/files/run/t5603.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 1d29e33c50..9a6d32be01 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -95,11 +95,12 @@ trait Trees extends reflect.internal.Trees { self: Global => val (edefs, rest) = body span treeInfo.isEarlyDef val (evdefs, etdefs) = edefs partition treeInfo.isEarlyValDef val gvdefs = evdefs map { - case vdef @ ValDef(_, _, tpt, _) => copyValDef(vdef)( - // !!! I know "atPos in case" wasn't intentionally planted to - // add an air of mystery to this file, but it is the sort of - // comment which only its author could love. - tpt = atPos(vdef.pos.focus)(TypeTree() setOriginal tpt setPos tpt.pos.focus), // atPos in case + case vdef @ ValDef(_, _, tpt, _) => + copyValDef(vdef)( + // atPos for the new tpt is necessary, since the original tpt might have no position + // (when missing type annotation for ValDef for example), so even though setOriginal modifies the + // position of TypeTree, it would still be NoPosition. That's what the author meant. + tpt = atPos(vdef.pos.focus)(TypeTree() setOriginal tpt setPos tpt.pos.focus), rhs = EmptyTree ) } @@ -125,7 +126,7 @@ trait Trees extends reflect.internal.Trees { self: Global => DefDef(constrMods, nme.CONSTRUCTOR, List(), vparamss1, TypeTree(), Block(lvdefs ::: List(superCall), Literal(Constant()))))) } } - constrs foreach (ensureNonOverlapping(_, parents ::: gvdefs)) + constrs foreach (ensureNonOverlapping(_, parents ::: gvdefs, focus=false)) // Field definitions for the class - remove defaults. val fieldDefs = vparamss.flatten map (vd => copyValDef(vd)(mods = vd.mods &~ DEFAULTPARAM, rhs = EmptyTree)) diff --git a/src/compiler/scala/tools/nsc/interactive/RangePositions.scala b/src/compiler/scala/tools/nsc/interactive/RangePositions.scala index 06828f3a3a..b702d2787c 100644 --- a/src/compiler/scala/tools/nsc/interactive/RangePositions.scala +++ b/src/compiler/scala/tools/nsc/interactive/RangePositions.scala @@ -41,11 +41,11 @@ self: scala.tools.nsc.Global => /** A position that wraps a set of trees. * The point of the wrapping position is the point of the default position. * If some of the trees are ranges, returns a range position enclosing all ranges - * Otherwise returns default position. + * Otherwise returns default position that is either focused or not. */ - override def wrappingPos(default: Position, trees: List[Tree]): Position = { + override def wrappingPos(default: Position, trees: List[Tree], focus: Boolean): Position = { val ranged = trees filter (_.pos.isRange) - if (ranged.isEmpty) default.focus + if (ranged.isEmpty) if (focus) default.focus else default else new RangePosition(default.source, (ranged map (_.pos.start)).min, default.point, (ranged map (_.pos.end)).max) } @@ -59,13 +59,25 @@ self: scala.tools.nsc.Global => if (headpos.isDefined) wrappingPos(headpos, trees) else headpos } -/* - override def integratePos(tree: Tree, pos: Position) = - if (pos.isSynthetic && !tree.pos.isSynthetic) tree.syntheticDuplicate - else tree -*/ - // -------------- ensuring no overlaps ------------------------------- + + /** Ensure that given tree has no positions that overlap with + * any of the positions of `others`. This is done by + * shortening the range, assigning TransparentPositions + * to some of the nodes in `tree` or focusing on the position. + */ + override def ensureNonOverlapping(tree: Tree, others: List[Tree], focus: Boolean) { + def isOverlapping(pos: Position) = + pos.isRange && (others exists (pos overlaps _.pos)) + if (isOverlapping(tree.pos)) { + val children = tree.children + children foreach (ensureNonOverlapping(_, others, focus)) + if (tree.pos.isOpaqueRange) { + val wpos = wrappingPos(tree.pos, children, focus) + tree setPos (if (isOverlapping(wpos)) tree.pos.makeTransparent else wpos) + } + } + } def solidDescendants(tree: Tree): List[Tree] = if (tree.pos.isTransparent) tree.children flatMap solidDescendants @@ -106,24 +118,6 @@ self: scala.tools.nsc.Global => if (ts.head == t) replacement ::: ts.tail else ts.head :: replace(ts.tail, t, replacement) - /** Ensure that given tree has no positions that overlap with - * any of the positions of `others`. This is done by - * shortening the range or assigning TransparentPositions - * to some of the nodes in `tree`. - */ - override def ensureNonOverlapping(tree: Tree, others: List[Tree]) { - def isOverlapping(pos: Position) = - pos.isRange && (others exists (pos overlaps _.pos)) - if (isOverlapping(tree.pos)) { - val children = tree.children - children foreach (ensureNonOverlapping(_, others)) - if (tree.pos.isOpaqueRange) { - val wpos = wrappingPos(tree.pos.focus, children) - tree setPos (if (isOverlapping(wpos)) tree.pos.makeTransparent else wpos) - } - } - } - /** Does given list of trees have mutually non-overlapping positions? * pre: None of the trees is transparent */ diff --git a/src/reflect/scala/reflect/internal/Positions.scala b/src/reflect/scala/reflect/internal/Positions.scala index 6ae9b40fcb..faa161d6b1 100644 --- a/src/reflect/scala/reflect/internal/Positions.scala +++ b/src/reflect/scala/reflect/internal/Positions.scala @@ -10,23 +10,25 @@ trait Positions extends api.Positions { self: SymbolTable => /** A position that wraps a set of trees. * The point of the wrapping position is the point of the default position. * If some of the trees are ranges, returns a range position enclosing all ranges - * Otherwise returns default position. + * Otherwise returns default position that is either focused or not. */ - def wrappingPos(default: Position, trees: List[Tree]): Position = default + def wrappingPos(default: Position, trees: List[Tree]) = wrappingPos(default, trees, true) + def wrappingPos(default: Position, trees: List[Tree], focus: Boolean): Position = default /** A position that wraps the non-empty set of trees. * The point of the wrapping position is the point of the first trees' position. - * If all some the trees are non-synthetic, returns a range position enclosing the non-synthetic trees + * If some of the trees are non-synthetic, returns a range position enclosing the non-synthetic trees * Otherwise returns a synthetic offset position to point. */ def wrappingPos(trees: List[Tree]): Position = trees.head.pos /** Ensure that given tree has no positions that overlap with * any of the positions of `others`. This is done by - * shortening the range or assigning TransparentPositions - * to some of the nodes in `tree`. + * shortening the range, assigning TransparentPositions + * to some of the nodes in `tree` or focusing on the position. */ - def ensureNonOverlapping(tree: Tree, others: List[Tree]) {} + def ensureNonOverlapping(tree: Tree, others: List[Tree]){ ensureNonOverlapping(tree, others, true) } + def ensureNonOverlapping(tree: Tree, others: List[Tree], focus: Boolean) {} trait PosAssigner extends Traverser { var pos: Position diff --git a/test/files/run/t5603.check b/test/files/run/t5603.check new file mode 100644 index 0000000000..5127d3c1c7 --- /dev/null +++ b/test/files/run/t5603.check @@ -0,0 +1,29 @@ +[[syntax trees at end of parser]] // newSource1 +[0:241]package [0:0] { + [0:82]abstract trait Greeting extends [15:82][83]scala.AnyRef { + [15]def $init$() = [15]{ + [15]() + }; + [23:39]val name: [33:39]String; + [46:76]val msg = [56:76][56:72][56:71]"How are you, ".$plus([72:76]name) + }; + [87:209]class C extends [94:209][151:159]Greeting { + [119:139]val nameElse = _; + [95:101] private[this] val i: [98:101]Int = _; + <119:139>def ([95]i: [98]Int) = <119:139>{ + <119:139>val nameElse = <134:139>"Bob"; + [94][94][94]super.(); + [94]() + }; + [168:184]val name = [179:184]"avc"; + [191:203][191:198]println([199:202]msg) + }; + [215:241]object Test extends [227:241][235:238]App { + [227]def () = [227]{ + [227][227][227]super.(); + [227]() + }; + [NoPosition] + } +} + diff --git a/test/files/run/t5603.scala b/test/files/run/t5603.scala new file mode 100644 index 0000000000..60dfd01fee --- /dev/null +++ b/test/files/run/t5603.scala @@ -0,0 +1,42 @@ +import scala.tools.partest._ +import java.io._ +import scala.tools.nsc._ +import scala.tools.nsc.util.CommandLineParser +import scala.tools.nsc.{Global, Settings, CompilerCommand} +import scala.tools.nsc.reporters.ConsoleReporter + +object Test extends DirectTest { + + override def extraSettings: String = "-usejavacp -Xprint:parser -Ystop-after:parser -d " + testOutput.path + + override def code = """ + trait Greeting { + val name: String + val msg = "How are you, "+name + } + class C(i: Int) extends { + val nameElse = "Bob" + } with Greeting { + val name = "avc" + println(msg) + } + + object Test extends App {} + """.trim + + override def show(): Unit = { + // redirect err to out, for logging + val prevErr = System.err + System.setErr(System.out) + compile() + System.setErr(prevErr) + } + + override def newCompiler(args: String*): Global = { + + val settings = new Settings() + settings.Xprintpos.value = true + val command = new CompilerCommand((CommandLineParser tokenize extraSettings) ++ args.toList, settings) + new Global(command.settings, new ConsoleReporter(settings)) with interactive.RangePositions + } +} -- cgit v1.2.3 From 2a14dd2d23e78775301d38dd235873e5cddc6e23 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 27 Jul 2012 11:32:29 +0200 Subject: Fixed SI-5031. Only consider classes when looking for companion class. sym.effectiveOwner revealed this piece of inconsistency. companionModule is fine because similar check is there already. Review by @paulp. --- src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala | 1 - src/reflect/scala/reflect/internal/Symbols.scala | 6 ++---- test/files/neg/t5031.check | 5 +++++ test/files/neg/t5031/Id.scala | 4 ++++ test/files/neg/t5031/package.scala | 3 +++ test/files/pos/t5031/Id.scala | 4 ++++ test/files/pos/t5031/package.scala | 3 +++ test/files/pos/t5031_2.scala | 7 +++++++ 8 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/files/neg/t5031.check create mode 100644 test/files/neg/t5031/Id.scala create mode 100644 test/files/neg/t5031/package.scala create mode 100644 test/files/pos/t5031/Id.scala create mode 100644 test/files/pos/t5031/package.scala create mode 100644 test/files/pos/t5031_2.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala index f4c96505a7..9d141efe0a 100755 --- a/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala @@ -8,7 +8,6 @@ package doc package model import scala.collection._ -import language.reflectiveCalls object IndexModelFactory { diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index b14306282b..5c9999b3bd 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2035,7 +2035,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Is this symbol defined in the same scope and compilation unit as `that` symbol? */ def isCoDefinedWith(that: Symbol) = { - import language.reflectiveCalls (this.rawInfo ne NoType) && (this.effectiveOwner == that.effectiveOwner) && { !this.effectiveOwner.isPackageClass || @@ -2706,7 +2705,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => override def moduleClass = referenced override def companionClass = - flatOwnerInfo.decl(name.toTypeName).suchThat(_ isCoDefinedWith this) + flatOwnerInfo.decl(name.toTypeName).suchThat(sym => sym.isClass && (sym isCoDefinedWith this)) override def owner = { Statistics.incCounter(ownerCount) @@ -3071,7 +3070,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => */ protected final def companionModule0: Symbol = flatOwnerInfo.decl(name.toTermName).suchThat( - sym => sym.hasFlag(MODULE) && (sym isCoDefinedWith this) && !sym.isMethod) + sym => sym.isModule && (sym isCoDefinedWith this) && !sym.isMethod) override def companionModule = companionModule0 override def companionSymbol = companionModule0 @@ -3394,7 +3393,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => } case class InvalidCompanions(sym1: Symbol, sym2: Symbol) extends Throwable({ - import language.reflectiveCalls "Companions '" + sym1 + "' and '" + sym2 + "' must be defined in same file:\n" + " Found in " + sym1.sourceFile.canonicalPath + " and " + sym2.sourceFile.canonicalPath }) { diff --git a/test/files/neg/t5031.check b/test/files/neg/t5031.check new file mode 100644 index 0000000000..8983d8daf9 --- /dev/null +++ b/test/files/neg/t5031.check @@ -0,0 +1,5 @@ +Id.scala:3: error: Companions 'class Test' and 'object Test' must be defined in same file: + Found in t5031/package.scala and t5031/Id.scala +object Test + ^ +one error found diff --git a/test/files/neg/t5031/Id.scala b/test/files/neg/t5031/Id.scala new file mode 100644 index 0000000000..2f0db002d2 --- /dev/null +++ b/test/files/neg/t5031/Id.scala @@ -0,0 +1,4 @@ +package t5031 + +object Test + diff --git a/test/files/neg/t5031/package.scala b/test/files/neg/t5031/package.scala new file mode 100644 index 0000000000..17b63220be --- /dev/null +++ b/test/files/neg/t5031/package.scala @@ -0,0 +1,3 @@ +package object t5031 { + class Test +} diff --git a/test/files/pos/t5031/Id.scala b/test/files/pos/t5031/Id.scala new file mode 100644 index 0000000000..7bc3ebd348 --- /dev/null +++ b/test/files/pos/t5031/Id.scala @@ -0,0 +1,4 @@ +package t5031 + +object ID + diff --git a/test/files/pos/t5031/package.scala b/test/files/pos/t5031/package.scala new file mode 100644 index 0000000000..c02e69db8e --- /dev/null +++ b/test/files/pos/t5031/package.scala @@ -0,0 +1,3 @@ +package object t5031 { + type ID = Int +} diff --git a/test/files/pos/t5031_2.scala b/test/files/pos/t5031_2.scala new file mode 100644 index 0000000000..ded3e82301 --- /dev/null +++ b/test/files/pos/t5031_2.scala @@ -0,0 +1,7 @@ +package object t5031 { + class ID +} + +package t5031 { + object ID +} -- cgit v1.2.3 From a5aa050a25886597f72f79dd84e43d21d76a6c36 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 30 Jul 2012 12:47:50 +0200 Subject: ClassTag.Nothing now throws an exception Nothing is a bottom type, so it doesn't make much sense for it to have a meaningful erasure (ClassTag.Nothing.runtimeClass). --- src/library/scala/reflect/ClassTag.scala | 9 +++-- test/files/run/classtags_core.check | 60 ++++++++++++++++---------------- 2 files changed, 37 insertions(+), 32 deletions(-) (limited to 'test/files') diff --git a/src/library/scala/reflect/ClassTag.scala b/src/library/scala/reflect/ClassTag.scala index 5255c44f10..7b6df6e31c 100644 --- a/src/library/scala/reflect/ClassTag.scala +++ b/src/library/scala/reflect/ClassTag.scala @@ -64,7 +64,6 @@ trait ClassTag[T] extends ClassManifestDeprecatedApis[T] with Equals with Serial } object ClassTag { - private val NothingTYPE = classOf[scala.runtime.Nothing$] private val NullTYPE = classOf[scala.runtime.Null$] private val ObjectTYPE = classOf[java.lang.Object] @@ -81,7 +80,13 @@ object ClassTag { val Object : ClassTag[java.lang.Object] = new ClassTag[java.lang.Object]{ def runtimeClass = ObjectTYPE; private def readResolve() = ClassTag.Object } val AnyVal : ClassTag[scala.AnyVal] = ClassTag.Object.asInstanceOf[ClassTag[scala.AnyVal]] val AnyRef : ClassTag[scala.AnyRef] = ClassTag.Object.asInstanceOf[ClassTag[scala.AnyRef]] - val Nothing : ClassTag[scala.Nothing] = new ClassTag[scala.Nothing]{ def runtimeClass = NothingTYPE; private def readResolve() = ClassTag.Nothing } + val Nothing : ClassTag[scala.Nothing] = new ClassTag[scala.Nothing]{ + def runtimeClass = throw new Exception("Nothing is a bottom type, therefore its erasure does not return a value") + private def readResolve() = ClassTag.Nothing + override def equals(x: Any) = x.isInstanceOf[ClassTag[_]] && (x.asInstanceOf[AnyRef] eq ClassTag.Nothing) + override def hashCode = System.identityHashCode(this) + override def toString = "ClassTag[Nothing]" + } val Null : ClassTag[scala.Null] = new ClassTag[scala.Null]{ def runtimeClass = NullTYPE; private def readResolve() = ClassTag.Null } def apply[T](runtimeClass1: jClass[_]): ClassTag[T] = diff --git a/test/files/run/classtags_core.check b/test/files/run/classtags_core.check index 6519db2178..2241108ba0 100644 --- a/test/files/run/classtags_core.check +++ b/test/files/run/classtags_core.check @@ -1,30 +1,30 @@ -true -ClassTag[byte] -true -ClassTag[short] -true -ClassTag[char] -true -ClassTag[int] -true -ClassTag[long] -true -ClassTag[float] -true -ClassTag[double] -true -ClassTag[boolean] -true -ClassTag[void] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class scala.runtime.Null$] -true -ClassTag[class scala.runtime.Nothing$] +true +ClassTag[byte] +true +ClassTag[short] +true +ClassTag[char] +true +ClassTag[int] +true +ClassTag[long] +true +ClassTag[float] +true +ClassTag[double] +true +ClassTag[boolean] +true +ClassTag[void] +true +ClassTag[class java.lang.Object] +true +ClassTag[class java.lang.Object] +true +ClassTag[class java.lang.Object] +true +ClassTag[class java.lang.Object] +true +ClassTag[class scala.runtime.Null$] +true +ClassTag[Nothing] -- cgit v1.2.3 From 5589eeeb9a5e09352544efc629013caf2d18a842 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 30 Jul 2012 14:30:17 +0200 Subject: SI-5866 Support casting null to value classes The fix now supports null.asInstanceOf[C] where C is a value class that wraps a primitive type. --- src/compiler/scala/tools/nsc/transform/Erasure.scala | 12 ++++++++++-- test/files/run/t5866.check | 2 ++ test/files/run/t5866.scala | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/files/run/t5866.check create mode 100644 test/files/run/t5866.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 5115c49c87..24a74722b0 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -563,8 +563,16 @@ abstract class Erasure extends AddInterfaces case _ => val clazz = tref.sym log("not boxed: "+tree) - val tree0 = adaptToType(tree, clazz.tpe) - cast(Apply(Select(tree0, clazz.derivedValueClassUnbox), List()), pt) + lazy val underlying = underlyingOfValueClass(clazz) + val tree0 = + if (tree.tpe.typeSymbol == NullClass && + isPrimitiveValueClass(underlying.typeSymbol)) { + // convert `null` directly to underlying type, as going + // via the unboxed type would yield a NPE (see SI-5866) + unbox1(tree, underlying) + } else + Apply(Select(adaptToType(tree, clazz.tpe), clazz.derivedValueClassUnbox), List()) + cast(tree0, pt) } case _ => pt.typeSymbol match { diff --git a/test/files/run/t5866.check b/test/files/run/t5866.check new file mode 100644 index 0000000000..9f4ec729a7 --- /dev/null +++ b/test/files/run/t5866.check @@ -0,0 +1,2 @@ +0.0 +Foo(0.0) diff --git a/test/files/run/t5866.scala b/test/files/run/t5866.scala new file mode 100644 index 0000000000..120773effa --- /dev/null +++ b/test/files/run/t5866.scala @@ -0,0 +1,11 @@ +class Foo(val d: Double) extends AnyVal { + override def toString = s"Foo($d)" +} +object Test { + def main(args: Array[String]): Unit = { + val d: Double = null.asInstanceOf[Double] + println(d) + val f: Foo = null.asInstanceOf[Foo] + println(f) + } +} -- cgit v1.2.3 From 7d8c46479104a694c79a18861a1713a0a65e89f1 Mon Sep 17 00:00:00 2001 From: clhodapp Date: Mon, 30 Jul 2012 09:29:43 -0500 Subject: Removed resolveOverloaded It was decided to remove it until the next release --- src/reflect/scala/reflect/api/Symbols.scala | 25 -- src/reflect/scala/reflect/internal/Symbols.scala | 275 --------------------- .../run/reflect-resolveoverload-bynameparam.scala | 32 --- .../run/reflect-resolveoverload-expected.scala | 43 ---- .../run/reflect-resolveoverload-invalid.scala | 43 ---- test/files/run/reflect-resolveoverload-named.scala | 26 -- test/files/run/reflect-resolveoverload-targs.scala | 29 --- .../reflect-resolveoverload-tparm-substitute.scala | 77 ------ .../run/reflect-resolveoverload-variadic.scala | 27 -- test/files/run/reflect-resolveoverload1.scala | 19 -- test/files/run/reflect-resolveoverload2.scala | 51 ---- 11 files changed, 647 deletions(-) delete mode 100644 test/files/run/reflect-resolveoverload-bynameparam.scala delete mode 100644 test/files/run/reflect-resolveoverload-expected.scala delete mode 100644 test/files/run/reflect-resolveoverload-invalid.scala delete mode 100644 test/files/run/reflect-resolveoverload-named.scala delete mode 100644 test/files/run/reflect-resolveoverload-targs.scala delete mode 100644 test/files/run/reflect-resolveoverload-tparm-substitute.scala delete mode 100644 test/files/run/reflect-resolveoverload-variadic.scala delete mode 100644 test/files/run/reflect-resolveoverload1.scala delete mode 100644 test/files/run/reflect-resolveoverload2.scala (limited to 'test/files') diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala index 1d2888961b..c94c796279 100644 --- a/src/reflect/scala/reflect/api/Symbols.scala +++ b/src/reflect/scala/reflect/api/Symbols.scala @@ -232,31 +232,6 @@ trait Symbols extends base.Symbols { self: Universe => /** The overloaded alternatives of this symbol */ def alternatives: List[Symbol] - /** Performs method overloading resolution. More precisely, resolves an overloaded TermSymbol - * to a single, non-overloaded TermSymbol that accepts the specified argument types. - * @param pre The prefix type, i.e. the type of the value the method is dispatched on. - * This is required when resolving references to type parameters of the type - * the method is declared in. For example if the method is declared in class `List[A]`, - * providing the prefix as `List[Int]` allows the overloading resolution to use - * `Int` instead of `A`. - * @param targs Type arguments that a candidate alternative must be able to accept. Candidates - * will be considered with these arguments substituted for their corresponding - * type parameters. - * @param posVargs Positional argument types that a candidate alternative must be able to accept. - * @param nameVargs Named argument types that a candidate alternative must be able to accept. - * Each element in the sequence should be a pair of a parameter name and an - * argument type. - * @param expected Return type that a candidate alternative has to be compatible with. - * @return Either a single, non-overloaded Symbol referring to the selected alternative - * or NoSymbol if no single member could be selected given the passed arguments. - */ - def resolveOverloaded( - pre: Type = NoPrefix, - targs: Seq[Type] = List(), - posVargs: Seq[Type] = List(), - nameVargs: Seq[(TermName, Type)] = List(), - expected: Type = NoType - ): Symbol } /** The API of type symbols */ diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index b14306282b..959d4d31ee 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -84,281 +84,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => def getAnnotations: List[AnnotationInfo] = { initialize; annotations } def setAnnotations(annots: AnnotationInfo*): this.type = { setAnnotations(annots.toList); this } - def resolveOverloaded( - pre: Type, - targs: Seq[Type], - posVargTypes: Seq[Type], - nameVargTypes: Seq[(TermName, Type)], - expected: Type - ): Symbol = { - - // Begin Correlation Helpers - - def isCompatible(tp: Type, pt: Type): Boolean = { - def isCompatibleByName(tp: Type, pt: Type): Boolean = pt match { - case TypeRef(_, ByNameParamClass, List(res)) if !definitions.isByNameParamType(tp) => - isCompatible(tp, res) - case _ => - false - } - (tp weak_<:< pt) || isCompatibleByName(tp, pt) - } - - def signatureAsSpecific(method1: MethodSymbol, method2: MethodSymbol): Boolean = { - (substituteTypeParams(method1), substituteTypeParams(method2)) match { - case (NullaryMethodType(r1), NullaryMethodType(r2)) => - r1 weak_<:< r2 - case (NullaryMethodType(_), MethodType(_, _)) => - true - case (MethodType(_, _), NullaryMethodType(_)) => - false - case (MethodType(p1, _), MethodType(p2, _)) => - val len = p1.length max p2.length - val sub = extend(p1 map (_.typeSignature), len) - val sup = extend(p2 map (_.typeSignature), len) - (sub corresponds sup)(isCompatible) - } - } - - def scopeMoreSpecific(method1: MethodSymbol, method2: MethodSymbol): Boolean = { - val o1 = method1.owner.asClassSymbol - val o2 = method2.owner.asClassSymbol - val c1 = if (o1.hasFlag(Flag.MODULE)) o1.companionSymbol else o1 - val c2 = if (o2.hasFlag(Flag.MODULE)) o2.companionSymbol else o2 - c1.typeSignature <:< c2.typeSignature - } - - def moreSpecific(method1: MethodSymbol, method2: MethodSymbol): Boolean = { - def points(m1: MethodSymbol, m2: MethodSymbol) = { - val p1 = if (signatureAsSpecific(m1, m2)) 1 else 0 - val p2 = if (scopeMoreSpecific(m1, m2)) 1 else 0 - p1 + p2 - } - points(method1, method2) > points(method2, method1) - } - - def combineInto ( - variadic: Boolean - )( - positional: Seq[Type], - named: Seq[(TermName, Type)] - )( - target: Seq[TermName], - defaults: Map[Int, Type] - ): Option[Seq[Type]] = { - - val offset = positional.length - val unfilled = target.zipWithIndex drop offset - val canAcceptAllNameVargs = named forall { case (argName, _) => - unfilled exists (_._1 == argName) - } - - val paramNamesUnique = { - named.length == named.map(_._1).distinct.length - } - - if (canAcceptAllNameVargs && paramNamesUnique) { - - val rest = unfilled map { case (paramName, paramIndex) => - val passedIn = named.collect { - case (argName, argType) if argName == paramName => argType - }.headOption - - passedIn orElse defaults.get(paramIndex).map(_.asInstanceOf[Type]) - } - - val rest1 = { - if (variadic && !rest.isEmpty && !rest.last.isDefined) rest.init - else rest - } - - - if (rest1 forall (_.isDefined)) { - val joined = positional ++ rest1.map(_.get) - val repeatedCollapsed = { - if (variadic) { - val (normal, repeated) = joined.splitAt(target.length - 1) - if (repeated.forall(_ =:= repeated.head)) Some(normal ++ repeated.headOption) - else None - } - else Some(joined) - } - if (repeatedCollapsed.exists(_.length == target.length)) - repeatedCollapsed - else if (variadic && repeatedCollapsed.exists(_.length == target.length - 1)) - repeatedCollapsed - else None - } else None - - } else None - } - - // Begin Reflection Helpers - - // Replaces a repeated parameter type at the end of the parameter list - // with a number of non-repeated parameter types in order to pad the - // list to be nargs in length - def extend(types: Seq[Type], nargs: Int): Seq[Type] = { - if (isVarArgTypes(types)) { - val repeatedType = types.last.normalize.typeArgs.head - types.init ++ Seq.fill(nargs - (types.length - 1))(repeatedType) - } else types - } - - // Replaces by-name parameters with their result type and - // TypeRefs with the thing they reference - def unwrap(paramType: Type): Type = paramType match { - case TypeRef(_, IntClass, _) => typeOf[Int] - case TypeRef(_, LongClass, _) => typeOf[Long] - case TypeRef(_, ShortClass, _) => typeOf[Short] - case TypeRef(_, ByteClass, _) => typeOf[Byte] - case TypeRef(_, CharClass, _) => typeOf[Char] - case TypeRef(_, FloatClass, _) => typeOf[Float] - case TypeRef(_, DoubleClass, _) => typeOf[Double] - case TypeRef(_, BooleanClass, _) => typeOf[Boolean] - case TypeRef(_, UnitClass, _) => typeOf[Unit] - case TypeRef(_, NullClass, _) => typeOf[Null] - case TypeRef(_, AnyClass, _) => typeOf[Any] - case TypeRef(_, NothingClass, _) => typeOf[Nothing] - case TypeRef(_, AnyRefClass, _) => typeOf[AnyRef] - case TypeRef(_, ByNameParamClass, List(resultType)) => unwrap(resultType) - case t: Type => t - } - - // Gives the names of the parameters to a method - def paramNames(signature: Type): Seq[TermName] = signature match { - case PolyType(_, resultType) => paramNames(resultType) - case MethodType(params, _) => params.map(_.name.asInstanceOf[TermName]) - case NullaryMethodType(_) => Seq.empty - } - - def valParams(signature: Type): Seq[TermSymbol] = signature match { - case PolyType(_, resultType) => valParams(resultType) - case MethodType(params, _) => params.map(_.asTermSymbol) - case NullaryMethodType(_) => Seq.empty - } - - // Returns a map from parameter index to default argument type - def defaultTypes(method: MethodSymbol): Map[Int, Type] = { - val typeSig = substituteTypeParams(method) - val owner = method.owner - valParams(typeSig).zipWithIndex.filter(_._1.hasFlag(Flag.DEFAULTPARAM)).map { case(_, index) => - val name = nme.defaultGetterName(method.name.decodedName, index + 1) - val default = owner.asType member name - index -> default.typeSignature.asInstanceOf[NullaryMethodType].resultType - }.toMap - } - - // True if any of method's parameters have default values. False otherwise. - def usesDefault(method: MethodSymbol): Boolean = valParams(method.typeSignature) drop(posVargTypes).length exists { param => - (param hasFlag Flag.DEFAULTPARAM) && nameVargTypes.forall { case (argName, _) => - param.name != argName - } - } - - // The number of type parameters that the method takes - def numTypeParams(x: MethodSymbol): Int = { - x.typeSignature.typeParams.length - } - - def substituteTypeParams(m: MethodSymbol): Type = { - (pre memberType m) match { - case m: MethodType => m - case n: NullaryMethodType => n - case PolyType(tparams, rest) => rest.substituteTypes(tparams, targs.toList) - } - } - - // Begin Selection Helpers - - def select( - alternatives: Seq[MethodSymbol], - filters: Seq[Seq[MethodSymbol] => Seq[MethodSymbol]] - ): Seq[MethodSymbol] = - filters.foldLeft(alternatives)((a, f) => { - if (a.size > 1) f(a) else a - }) - - // Drop arguments that take the wrong number of type - // arguments. - val posTargLength: Seq[MethodSymbol] => Seq[MethodSymbol] = _.filter { alt => - numTypeParams(alt) == targs.length - } - - // Drop methods that are not applicable to the arguments - val applicable: Seq[MethodSymbol] => Seq[MethodSymbol] = _.filter { alt => - // Note: combine returns None if a is not applicable and - // None.exists(_ => true) == false - val paramTypes = - valParams(substituteTypeParams(alt)).map(p => unwrap(p.typeSignature)) - val variadic = isVarArgTypes(paramTypes) - val maybeArgTypes = - combineInto(variadic)(posVargTypes, nameVargTypes)(paramNames(alt.typeSignature), defaultTypes(alt)) - maybeArgTypes exists { argTypes => - if (isVarArgTypes(argTypes) && !isVarArgTypes(paramTypes)) false - else { - val a = argTypes - val p = extend(paramTypes, argTypes.length) - (a corresponds p)(_ weak_<:< _) - } - } - } - - // Always prefer methods that don't need to use default - // arguments over those that do. - // e.g. when resolving foo(1), prefer def foo(x: Int) over - // def foo(x: Int, y: Int = 4) - val noDefaults: Seq[MethodSymbol] => Seq[MethodSymbol] = - _ filterNot usesDefault - - // Try to select the most specific method. If that's not possible, - // return all of the candidates (this will likely cause an error - // higher up in the call stack) - val mostSpecific: Seq[MethodSymbol] => Seq[MethodSymbol] = { alts => - val sorted = alts.sortWith(moreSpecific) - val mostSpecific = sorted.head - val agreeTest: MethodSymbol => Boolean = - moreSpecific(mostSpecific, _) - val disagreeTest: MethodSymbol => Boolean = - moreSpecific(_, mostSpecific) - if (!sorted.tail.forall(agreeTest)) { - mostSpecific +: sorted.tail.filterNot(agreeTest) - } else if (sorted.tail.exists(disagreeTest)) { - mostSpecific +: sorted.tail.filter(disagreeTest) - } else { - Seq(mostSpecific) - } - } - - def finalResult(t: Type): Type = t match { - case PolyType(_, rest) => finalResult(rest) - case MethodType(_, result) => finalResult(result) - case NullaryMethodType(result) => finalResult(result) - case t: Type => t - } - - // If a result type is given, drop alternatives that don't meet it - val resultType: Seq[MethodSymbol] => Seq[MethodSymbol] = - if (expected == NoType) identity - else _.filter { alt => - finalResult(substituteTypeParams(alt)) <:< expected - } - - def defaultFilteringOps = - Seq(posTargLength, resultType, applicable, noDefaults, mostSpecific) - - // Begin Method Proper - - - val alts = alternatives.map(_.asMethodSymbol) - - val selection = select(alts, defaultFilteringOps) - - val knownApplicable = applicable(selection) - - if (knownApplicable.size == 1) knownApplicable.head - else NoSymbol - } } /** The class for all symbols */ diff --git a/test/files/run/reflect-resolveoverload-bynameparam.scala b/test/files/run/reflect-resolveoverload-bynameparam.scala deleted file mode 100644 index 7fb8c82ab8..0000000000 --- a/test/files/run/reflect-resolveoverload-bynameparam.scala +++ /dev/null @@ -1,32 +0,0 @@ - -class A -class B extends A - -class C { - def foo(x: => Int)(y: String) = x - def foo(x: String)(y: List[_]) = x - def foo(x: => A)(y: Array[_]) = 1 - def foo(x: A)(y: Seq[_]) = 2 - def foo(x: B)(y: Map[_, _]) = 4 -} - -object Test extends App { - val cm = reflect.runtime.currentMirror - val u = cm.universe - val c = new C - val im = cm.reflect(c) - val t = u.typeOf[C] member u.newTermName("foo") asTermSymbol - val f1 = t.resolveOverloaded(posVargs = List(u.typeOf[Int])) asMethodSymbol - val f2 = t.resolveOverloaded(posVargs = List(u.typeOf[String])) asMethodSymbol - val f3 = t.resolveOverloaded(posVargs = List(u.typeOf[A])) asMethodSymbol - val f4 = t.resolveOverloaded(posVargs = List(u.typeOf[B])) asMethodSymbol - val m1 = im.reflectMethod(f1) - val m2 = im.reflectMethod(f2) - val m3 = im.reflectMethod(f3) - val m4 = im.reflectMethod(f4) - assert(m1(() => 1, null) == c.foo(1)(null)) - assert(m2("a", null) == c.foo("a")(null)) - assert(m3(new A, null) == c.foo(new A)(null)) - assert(m4(new B, null) == c.foo(new B)(null)) -} - diff --git a/test/files/run/reflect-resolveoverload-expected.scala b/test/files/run/reflect-resolveoverload-expected.scala deleted file mode 100644 index 1378090309..0000000000 --- a/test/files/run/reflect-resolveoverload-expected.scala +++ /dev/null @@ -1,43 +0,0 @@ - -class A { - override def equals(x: Any) = { - x.isInstanceOf[A] && !x.isInstanceOf[B] - } -} -class B extends A { - override def equals(x: Any) = { - x.isInstanceOf[B] - } -} - -class C { - def a(x: String) = 1 - def a(x: Array[_]) = "a" - def b(x: String) = new A - def b(x: Array[_]) = new B - def c(x: String) = new B - def c(x: Array[_]) = "a" -} - -object Test extends App { - val cm = reflect.runtime.currentMirror - val u = cm.universe - val c = new C - val im = cm.reflect(c) - def invoke(s: String, expectedType: u.Type, expectedResult: Any) { - val ol = (u.typeOf[C] member u.newTermName(s)).asTermSymbol - val methodSym = ol.resolveOverloaded(posVargs = List(u.typeOf[Null]), expected = expectedType).asMethodSymbol - val sig = methodSym.typeSignature.asInstanceOf[u.MethodType] - val method = im.reflectMethod(methodSym) - assert(method(null) == expectedResult) - } - - invoke("a", u.typeOf[Int], c.a(null): Int) - invoke("a", u.typeOf[String], c.a(null): String) - invoke("b", u.typeOf[B], c.b(null): B) - invoke("c", u.typeOf[A], c.c(null): A) - invoke("c", u.typeOf[A], c.c(null): A) - invoke("c", u.typeOf[B], c.c(null): B) - invoke("c", u.typeOf[String], c.c(null): String) - -} diff --git a/test/files/run/reflect-resolveoverload-invalid.scala b/test/files/run/reflect-resolveoverload-invalid.scala deleted file mode 100644 index 8c5dc9f94b..0000000000 --- a/test/files/run/reflect-resolveoverload-invalid.scala +++ /dev/null @@ -1,43 +0,0 @@ - -class A -class B extends A - -class C { - def a(x: Int) = 1 - def a(x: String) = 2 - def b(x: B) = 3 - def c(x: A, y: B) = 4 - def c(x: B, y: A) = 5 - def d[T](x: Int) = 6 - def d(x: String) = 7 - def e(x: A) = 8 - def e(x: =>B) = 9 -} - -object Test extends App { - val cm = reflect.runtime.currentMirror - val u = cm.universe - - val x = new C - val t = u.typeOf[C] - - val a = t member u.newTermName("a") asTermSymbol - val b = t member u.newTermName("b") asTermSymbol - val c = t member u.newTermName("c") asTermSymbol - val d = t member u.newTermName("d") asTermSymbol - val e = t member u.newTermName("e") asTermSymbol - - val n1 = a.resolveOverloaded(posVargs = List(u.typeOf[Long])) - val n2 = b.resolveOverloaded(posVargs = List(u.typeOf[A])) - val n3 = c.resolveOverloaded(posVargs = List(u.typeOf[B], u.typeOf[B])) - val n4 = d.resolveOverloaded(targs = List(u.typeOf[Int])) - val n5 = d.resolveOverloaded() - val n6 = e.resolveOverloaded(posVargs = List(u.typeOf[B])) - - assert(n1 == u.NoSymbol) - assert(n2 == u.NoSymbol) - assert(n3 == u.NoSymbol) - assert(n4 == u.NoSymbol) - assert(n5 == u.NoSymbol) - assert(n6 == u.NoSymbol) -} diff --git a/test/files/run/reflect-resolveoverload-named.scala b/test/files/run/reflect-resolveoverload-named.scala deleted file mode 100644 index 017ec85c0d..0000000000 --- a/test/files/run/reflect-resolveoverload-named.scala +++ /dev/null @@ -1,26 +0,0 @@ - -class A { - def foo(x: String, y: Int) = 1 - def foo(x: Int, y: String) = 2 -} - -object Test extends App { - val cm = reflect.runtime.currentMirror - val u = cm.universe - val a = new A - val im = cm.reflect(a) - val tpe = u.typeOf[A] - val overloaded = tpe member u.newTermName("foo") asTermSymbol - val ms1 = - overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("x"), u.typeOf[String]), (u.newTermName("y"), u.typeOf[Int]))) - val ms2 = - overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("y"), u.typeOf[Int]), (u.newTermName("x"), u.typeOf[String]))) - val ms3 = - overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("x"), u.typeOf[Int]), (u.newTermName("y"), u.typeOf[String]))) - val ms4 = - overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("y"), u.typeOf[String]), (u.newTermName("x"), u.typeOf[Int]))) - assert(im.reflectMethod(ms1 asMethodSymbol)("A", 1) == 1) - assert(im.reflectMethod(ms2 asMethodSymbol)("A", 1) == 1) - assert(im.reflectMethod(ms3 asMethodSymbol)(1, "A") == 2) - assert(im.reflectMethod(ms4 asMethodSymbol)(1, "A") == 2) -} diff --git a/test/files/run/reflect-resolveoverload-targs.scala b/test/files/run/reflect-resolveoverload-targs.scala deleted file mode 100644 index 888b2f0c15..0000000000 --- a/test/files/run/reflect-resolveoverload-targs.scala +++ /dev/null @@ -1,29 +0,0 @@ - -import reflect.runtime.{universe=>u} -import scala.reflect.runtime.{currentMirror => cm} - -class C { - def foo[T: u.TypeTag](x: String) = 1 - def foo[T: u.TypeTag, S: u.TypeTag](x: String) = 2 -} - -object Test extends App { - val c = new C - val im = cm.reflect(c) - val foo = u.typeOf[C] member u.newTermName("foo") asTermSymbol - val f1 = foo.resolveOverloaded( - targs = Seq(u.typeOf[Int]), - posVargs = Seq(u.typeOf[String]) - ) - - val f2 = foo.resolveOverloaded( - targs = Seq(u.typeOf[Int], - u.typeOf[Int]), posVargs = Seq(u.typeOf[String]) - ) - - val m1 = im.reflectMethod(f1 asMethodSymbol) - val m2 = im.reflectMethod(f2 asMethodSymbol) - - assert(m1("a", u.typeTag[Int]) == c.foo[Int]("a")) - assert(m2("a", u.typeTag[Int], u.typeTag[Int]) == c.foo[Int, Int]("a")) -} diff --git a/test/files/run/reflect-resolveoverload-tparm-substitute.scala b/test/files/run/reflect-resolveoverload-tparm-substitute.scala deleted file mode 100644 index 22e7bcd40a..0000000000 --- a/test/files/run/reflect-resolveoverload-tparm-substitute.scala +++ /dev/null @@ -1,77 +0,0 @@ - -class A -class B extends A - -class C { - def foo[T](x: T) = x - def foo(x: Int) = "a" - def foo(x: A) = x -} - -object Test extends App { - val cm = reflect.runtime.currentMirror - val u = cm.universe - val c = new C - val im = cm.reflect(c) - val term = u.typeOf[C] member u.newTermName("foo") asTermSymbol - - val f1 = term.resolveOverloaded( - posVargs = List(u.typeOf[Int]), - expected = u.typeOf[String] - ) - - val f2 = term.resolveOverloaded( - targs = List(u.typeOf[String]), - posVargs = List(u.typeOf[String]), - expected = u.typeOf[String] - ) - - val f3 = term.resolveOverloaded( - posVargs = List(u.typeOf[A]), - expected = u.typeOf[A] - ) - - val f4 = term.resolveOverloaded( - targs = List(u.typeOf[A]), - posVargs = List(u.typeOf[A]), - expected = u.typeOf[A] - ) - - val f5 = term.resolveOverloaded( - targs = List(u.typeOf[B]), - posVargs = List(u.typeOf[B]), - expected = u.typeOf[B] - ) - - val f6 = term.resolveOverloaded( - targs = List(u.typeOf[B]), - posVargs = List(u.typeOf[B]), - expected = u.typeOf[A] - ) - - val f7 = term.resolveOverloaded( - targs = List(u.typeOf[A]), - posVargs = List(u.typeOf[B]), - expected = u.typeOf[A] - ) - - val m1 = im.reflectMethod(f1 asMethodSymbol) - val m2 = im.reflectMethod(f2 asMethodSymbol) - val m3 = im.reflectMethod(f3 asMethodSymbol) - val m4 = im.reflectMethod(f4 asMethodSymbol) - val m5 = im.reflectMethod(f5 asMethodSymbol) - val m6 = im.reflectMethod(f6 asMethodSymbol) - val m7 = im.reflectMethod(f7 asMethodSymbol) - - val a = new A - val b = new B - assert(m1(2) == (c.foo(2): String)) - assert(m2("xyz") == (c.foo[String]("xyz"): String)) - assert(m3(a) == (c.foo(a): A)) - assert(m4(a) == (c.foo[A](a): A)) - assert(m5(b) == (c.foo[B](b): B)) - assert(m6(b) == (c.foo[B](b): A)) - assert(m7(b) == (c.foo[A](b): A)) - - -} diff --git a/test/files/run/reflect-resolveoverload-variadic.scala b/test/files/run/reflect-resolveoverload-variadic.scala deleted file mode 100644 index 8e2e15600f..0000000000 --- a/test/files/run/reflect-resolveoverload-variadic.scala +++ /dev/null @@ -1,27 +0,0 @@ - -class C { - def foo(x: Int*) = 1 + x.sum - def foo(x: String) = 2 -} - -object Test extends App { - val cm = reflect.runtime.currentMirror - val u = cm.universe - val c = new C - val im = cm.reflect(c) - val foo = u.typeOf[C] member u.newTermName("foo") asTermSymbol - val f0 = foo.resolveOverloaded() - val f1 = foo.resolveOverloaded(posVargs = Seq(u.typeOf[Int])) - val f2 = foo.resolveOverloaded(posVargs = Seq(u.typeOf[Int], u.typeOf[Int])) - val f3 = foo.resolveOverloaded(posVargs = Seq(u.typeOf[String])) - - val m0 = im.reflectMethod(f0 asMethodSymbol) - val m1 = im.reflectMethod(f1 asMethodSymbol) - val m2 = im.reflectMethod(f2 asMethodSymbol) - val m3 = im.reflectMethod(f3 asMethodSymbol) - - assert(m0(Seq()) == c.foo()) - assert(m1(Seq(1)) == c.foo(1)) - assert(m2(Seq(4, 9)) == c.foo(4, 9)) - assert(m3("abc") == c.foo("abc")) -} diff --git a/test/files/run/reflect-resolveoverload1.scala b/test/files/run/reflect-resolveoverload1.scala deleted file mode 100644 index a859a0ec4e..0000000000 --- a/test/files/run/reflect-resolveoverload1.scala +++ /dev/null @@ -1,19 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.{currentMirror => cm} - -object Test extends App { - - val s = "hello world" - val m = cm.reflect(s) - val sc = m.symbol - val st = sc.asType - val meth = (st member newTermName("indexOf")).asTermSymbol - val IntType = definitions.IntClass.asType - val indexOf = (meth resolveOverloaded(posVargs = List(IntType))).asMethodSymbol - assert(m.reflectMethod(indexOf)('w') == 6) - assert((m.reflectMethod(indexOf)('w') match { case x: Int => x }) == 6) - - val meth2 = (st member newTermName("substring")).asTermSymbol - val substring = (meth2 resolveOverloaded(posVargs = List(IntType, IntType))).asMethodSymbol - assert(m.reflectMethod(substring)(2, 6) == "llo ") -} diff --git a/test/files/run/reflect-resolveoverload2.scala b/test/files/run/reflect-resolveoverload2.scala deleted file mode 100644 index a800a3e92c..0000000000 --- a/test/files/run/reflect-resolveoverload2.scala +++ /dev/null @@ -1,51 +0,0 @@ -class A -class B extends A - -class C { - def a(x: Int) = 1 - def a(x: String) = 2 - //def b(x: => Int)(s: String) = 1 - //def b(x: => String)(a: Array[_]) = 2 - def c(x: A) = 1 - def c(x: B) = 2 - //def d(x: => A)(s: String) = 1 - //def d(x: => B)(a: Array[_]) = 2 - def e(x: A) = 1 - def e(x: B = new B) = 2 - def f(x: Int) = 1 - def f(x: String) = 2 - def f(x: Long) = 3 - def f(x: Double) = 4 -} - -object Test extends App { - val cm = reflect.runtime.currentMirror - val u = cm.universe - val c = new C - val im = cm.reflect(c) - def invoke(s: String, arg: Any, argType: u.Type): Int = { - val ol = u.typeOf[C] member u.newTermName(s) asTermSymbol - val methodSym = ol.resolveOverloaded(posVargs = List(argType)) asMethodSymbol - val sig = methodSym.typeSignature.asInstanceOf[u.MethodType] - val method = im.reflectMethod(methodSym) - if (sig.resultType.kind == "MethodType") method(arg, null).asInstanceOf[Int] - else method(arg).asInstanceOf[Int] - } - assert(c.a(1) == invoke("a", 1, u.typeOf[Int])) - assert(c.a("a") == invoke("a", "a", u.typeOf[String])) - assert(c.a('a') == invoke("a", 'a', u.typeOf[Char])) - assert(c.a(3: Byte) == invoke("a", 3: Byte, u.typeOf[Byte])) - //assert(c.b(1)(null) == invoke("b", 1, u.typeOf[Int])) - //assert(c.b("a")(null) == invoke("b", "a", u.typeOf[String])) - assert(c.c(new A) == invoke("c", new A, u.typeOf[A])) - assert(c.c(new B) == invoke("c", new B, u.typeOf[B])) - //assert(c.d(new A)(null) == invoke("d", new A, u.typeOf[A])) - //assert(c.d(new B)(null) == invoke("d", new B, u.typeOf[B])) - assert(c.e(new A) == invoke("e", new A, u.typeOf[A])) - assert(c.e(new B) == invoke("e", new B, u.typeOf[B])) - assert(c.f(1: Short) == invoke("f", 1: Short, u.typeOf[Short])) - assert(c.f(2) == invoke("f", 2, u.typeOf[Int])) - assert(c.f(3L) == invoke("f", 3L, u.typeOf[Long])) - assert(c.f(4f) == invoke("f", 4f, u.typeOf[Float])) - assert(c.f(5d) == invoke("f", 5d, u.typeOf[Double])) -} -- cgit v1.2.3 From 8d4b4262b0f9b2b59643ad20d30af7f5ad7ef1c7 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 30 Jul 2012 23:21:34 -0700 Subject: Checkfile update. I screwed around with type printing for a long time and now I have to be done, so I suggest we accept the imperfection in here for now because it's still way ahead of "..." as types go. --- test/files/run/t6028.check | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/files') diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index dca61115ad..34f4b22134 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -15,16 +15,16 @@ package { } }; def bar(barParam: Int): Object = { - @volatile var MethodLocalObject$module: scala.runtime.VolatileObjectRef = new scala.runtime.VolatileObjectRef(); + @volatile var MethodLocalObject$module: runtime.VolatileObjectRef = new runtime.VolatileObjectRef(); T.this.MethodLocalObject$1(barParam, MethodLocalObject$module) }; def tryy(tryyParam: Int): Function0 = { - var tryyLocal: scala.runtime.IntRef = new scala.runtime.IntRef(0); + var tryyLocal: runtime.IntRef = new runtime.IntRef(0); { (new anonymous class $anonfun$tryy$1(T.this, tryyParam, tryyLocal): Function0) } }; - @SerialVersionUID(0) final class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable { + @SerialVersionUID(0) final class $anonfun$foo$1 extends runtime.AbstractFunction0$mcI$sp with Serializable { def ($outer: T, methodParam$1: Int, methodLocal$1: Int): anonymous class $anonfun$foo$1 = { $anonfun$foo$1.super.(); () @@ -41,7 +41,7 @@ package { def T$MethodLocalTrait$$$outer(): T }; object MethodLocalObject$2 extends Object with T#MethodLocalTrait$1 { - def ($outer: T, barParam$1: Int): ... = { + def ($outer: T, barParam$1: Int): T#MethodLocalObject$2.type = { MethodLocalObject$2.super.(); MethodLocalObject$2.this.$asInstanceOf[T#MethodLocalTrait$1$class]()./*MethodLocalTrait$1$class*/$init$(barParam$1); () @@ -50,9 +50,9 @@ package { def T$MethodLocalObject$$$outer(): T = MethodLocalObject$2.this.$outer; def T$MethodLocalTrait$$$outer(): T = MethodLocalObject$2.this.$outer }; - final private[this] def MethodLocalObject$1(barParam$1: Int, MethodLocalObject$module$1: scala.runtime.VolatileObjectRef): ... = { - MethodLocalObject$module$1.elem = new ...(T.this, barParam$1); - MethodLocalObject$module$1.elem.$asInstanceOf[...]() + final private[this] def MethodLocalObject$1(barParam$1: Int, MethodLocalObject$module$1: runtime.VolatileObjectRef): T#MethodLocalObject$2.type = { + MethodLocalObject$module$1.elem = new T#MethodLocalObject$2.type(T.this, barParam$1); + MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type]() }; abstract trait MethodLocalTrait$1$class extends Object with T#MethodLocalTrait$1 { def /*MethodLocalTrait$1$class*/$init$(barParam$1: Int): Unit = { @@ -60,8 +60,8 @@ package { }; scala.this.Predef.print(scala.Int.box(barParam$1)) }; - @SerialVersionUID(0) final class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { - def ($outer: T, tryyParam$1: Int, tryyLocal$1: scala.runtime.IntRef): anonymous class $anonfun$tryy$1 = { + @SerialVersionUID(0) final class $anonfun$tryy$1 extends runtime.AbstractFunction0$mcV$sp with Serializable { + def ($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): anonymous class $anonfun$tryy$1 = { $anonfun$tryy$1.super.(); () }; @@ -76,7 +76,7 @@ package { scala.runtime.BoxedUnit.UNIT }; private[this] val tryyParam$1: Int = _; - private[this] val tryyLocal$1: scala.runtime.IntRef = _ + private[this] val tryyLocal$1: runtime.IntRef = _ } } } -- cgit v1.2.3 From ddcba109843d4f665a010f3dbbd28a6b99e6185a Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 31 Jul 2012 16:32:22 +0200 Subject: SI-5751 cleans up toolboxes for the release Removes the `freeTypes` parameters on `typeCheckExpr` and `runExpr`, since we now have public `substituteTypes` on both trees and types. Also implements long-awaited `inferImplicitValue` and `inferImplicitView` (thanks to Miles Sabin for nudging me!) --- .../scala/reflect/makro/runtime/Typers.scala | 31 +++--- src/compiler/scala/tools/reflect/ToolBox.scala | 54 +++++----- .../scala/tools/reflect/ToolBoxFactory.scala | 120 +++++++++++++-------- src/reflect/scala/reflect/api/Importers.scala | 2 + src/reflect/scala/reflect/internal/Importers.scala | 1 + src/reflect/scala/reflect/makro/Typers.scala | 41 ++++--- test/files/run/reify_newimpl_45.scala | 3 +- .../run/toolbox_typecheck_inferimplicitvalue.check | 1 + .../run/toolbox_typecheck_inferimplicitvalue.scala | 13 +++ 9 files changed, 153 insertions(+), 113 deletions(-) create mode 100644 test/files/run/toolbox_typecheck_inferimplicitvalue.check create mode 100644 test/files/run/toolbox_typecheck_inferimplicitvalue.scala (limited to 'test/files') diff --git a/src/compiler/scala/reflect/makro/runtime/Typers.scala b/src/compiler/scala/reflect/makro/runtime/Typers.scala index 18c1714d15..e43b0459ea 100644 --- a/src/compiler/scala/reflect/makro/runtime/Typers.scala +++ b/src/compiler/scala/reflect/makro/runtime/Typers.scala @@ -10,8 +10,9 @@ trait Typers { def typeCheck(tree: Tree, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree = { macroLogVerbose("typechecking %s with expected type %s, implicit views = %s, macros = %s".format(tree, pt, !withImplicitViewsDisabled, !withMacrosDisabled)) - val wrapper1 = if (!withImplicitViewsDisabled) (callsiteTyper.context.withImplicitsEnabled[Tree] _) else (callsiteTyper.context.withImplicitsDisabled[Tree] _) - val wrapper2 = if (!withMacrosDisabled) (callsiteTyper.context.withMacrosEnabled[Tree] _) else (callsiteTyper.context.withMacrosDisabled[Tree] _) + val context = callsiteTyper.context + val wrapper1 = if (!withImplicitViewsDisabled) (context.withImplicitsEnabled[Tree] _) else (context.withImplicitsDisabled[Tree] _) + val wrapper2 = if (!withMacrosDisabled) (context.withMacrosEnabled[Tree] _) else (context.withMacrosDisabled[Tree] _) def wrapper (tree: => Tree) = wrapper1(wrapper2(tree)) // if you get a "silent mode is not available past typer" here // don't rush to change the typecheck not to use the silent method when the silent parameter is false @@ -31,29 +32,21 @@ trait Typers { def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { macroLogVerbose("inferring implicit value of type %s, macros = %s".format(pt, !withMacrosDisabled)) - import universe.analyzer.SearchResult - val context = callsiteTyper.context - val wrapper1 = if (!withMacrosDisabled) (context.withMacrosEnabled[SearchResult] _) else (context.withMacrosDisabled[SearchResult] _) - def wrapper (inference: => SearchResult) = wrapper1(inference) - wrapper(universe.analyzer.inferImplicit(universe.EmptyTree, pt, true, false, context, !silent, pos)) match { - case failure if failure.tree.isEmpty => - macroLogVerbose("implicit search has failed. to find out the reason, turn on -Xlog-implicits") - if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) - universe.EmptyTree - case success => - success.tree - } + inferImplicit(universe.EmptyTree, pt, isView = false, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) + } + + def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { + macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s".format(from, to, tree, !withMacrosDisabled)) + val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).asTypeConstructor, List(from, to)) + inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) } - def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, reportAmbiguous: Boolean = true, pos: Position = enclosingPosition): Tree = { - macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s, reportAmbiguous = %s".format(from, to, tree, !withMacrosDisabled, reportAmbiguous)) + private def inferImplicit(tree: Tree, pt: Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: Position): Tree = { import universe.analyzer.SearchResult val context = callsiteTyper.context val wrapper1 = if (!withMacrosDisabled) (context.withMacrosEnabled[SearchResult] _) else (context.withMacrosDisabled[SearchResult] _) def wrapper (inference: => SearchResult) = wrapper1(inference) - val fun1 = universe.definitions.FunctionClass(1) - val viewTpe = universe.TypeRef(fun1.typeConstructor.prefix, fun1, List(from, to)) - wrapper(universe.analyzer.inferImplicit(tree, viewTpe, reportAmbiguous, true, context, !silent, pos)) match { + wrapper(universe.analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos)) match { case failure if failure.tree.isEmpty => macroLogVerbose("implicit search has failed. to find out the reason, turn on -Xlog-implicits") if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) diff --git a/src/compiler/scala/tools/reflect/ToolBox.scala b/src/compiler/scala/tools/reflect/ToolBox.scala index edd22c60f4..2505c1afb7 100644 --- a/src/compiler/scala/tools/reflect/ToolBox.scala +++ b/src/compiler/scala/tools/reflect/ToolBox.scala @@ -24,40 +24,46 @@ trait ToolBox[U <: Universe] { /** Typechecks a tree using this ToolBox. * This populates symbols and types of the tree and possibly transforms it to reflect certain desugarings. * - * If the tree has unresolved type variables (represented as instances of ``FreeTypeSymbol'' symbols), - * then they might, might be partially or might not be specified in the ``freeTypes'' parameter. + * If the tree has unresolved type variables (represented as instances of `FreeTypeSymbol` symbols), + * then they all have to be resolved first using `Tree.substituteTypes`, or an error occurs. * - * If ``silent'' is false, ``TypeError'' will be thrown in case of a typecheck error. - * If ``silent'' is true, the typecheck is silent and will return ``EmptyTree'' if an error occurs. + * If `silent` is false, `TypeError` will be thrown in case of a typecheck error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Ydebug. * * Typechecking can be steered with the following optional parameters: - * ``withImplicitViewsDisabled'' recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false - * ``withMacrosDisabled'' recursively prohibits macro expansions and macro-based implicits, default value is false + * `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false + * `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false */ - def typeCheck(tree: u.Tree, pt: u.Type = u.WildcardType, freeTypes: Map[u.FreeTypeSymbol, u.Type] = Map[u.FreeTypeSymbol, u.Type](), silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree + def typeCheck(tree: u.Tree, pt: u.Type = u.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree - - /** Infers an implicit value of the expected type ``pt'' in the macro callsite context. + /** Infers an implicit value of the expected type `pt` in top-level context. + * Optional `pos` parameter provides a position that will be associated with the implicit search. + * + * As mentioned in https://groups.google.com/forum/#!topic/scala-internals/ta-vbUT6JE8 + * this API won't take into account the lexical context of the callsite, because + * currently it's impossible to reify it. * - * If ``silent'' is false, ``TypeError'' will be thrown in case of an inference error. - * If ``silent'' is true, the typecheck is silent and will return ``EmptyTree'' if an error occurs. + * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. - * Unlike in ``typeCheck'', ``silent'' is true by default. + * Unlike in `typeCheck`, `silent` is true by default. */ - def inferImplicitValue(pt: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false): u.Tree + def inferImplicitValue(pt: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree - /** Infers an implicit view from the provided tree ``tree'' from the type ``from'' to the type ``to'' in the macro callsite context. + /** Infers an implicit view from the provided tree `tree` from the type `from` to the type `to` in the toplevel context. + * Optional `pos` parameter provides a position that will be associated with the implicit search. * - * Otional parameter, ``reportAmbiguous`` controls whether ambiguous implicit errors should be reported. - * If we search for a view simply to find out whether one type is coercible to another, it might be desirable to set this flag to ``false''. + * As mentioned in https://groups.google.com/forum/#!topic/scala-internals/ta-vbUT6JE8 + * this API won't take into account the lexical context of the callsite, because + * currently it's impossible to reify it. * - * If ``silent'' is false, ``TypeError'' will be thrown in case of an inference error. - * If ``silent'' is true, the typecheck is silent and will return ``EmptyTree'' if an error occurs. + * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. - * Unlike in ``typeCheck'', ``silent'' is true by default. + * Unlike in `typeCheck`, `silent` is true by default. */ - def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, reportAmbiguous: Boolean = true): u.Tree + def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree /** Recursively resets symbols and types in a given tree. * @@ -78,14 +84,14 @@ trait ToolBox[U <: Universe] { /** Compiles and runs a tree using this ToolBox. * - * If the tree has unresolved type variables (represented as instances of ``FreeTypeSymbol'' symbols), - * then they all have to be specified in the ``freeTypes'' parameter or an error occurs. + * If the tree has unresolved type variables (represented as instances of `FreeTypeSymbol` symbols), + * then they all have to be resolved first using `Tree.substituteTypes`, or an error occurs. * * This spawns the compiler at the Namer phase, and pipelines the tree through that compiler. - * Currently ``runExpr'' does not accept trees that already typechecked, because typechecking isn't idempotent. + * Currently `runExpr` does not accept trees that already typechecked, because typechecking isn't idempotent. * For more info, take a look at https://issues.scala-lang.org/browse/SI-5464. */ - def runExpr(tree: u.Tree, freeTypes: Map[u.FreeTypeSymbol, u.Type] = Map[u.FreeTypeSymbol, u.Type]()): Any + def runExpr(tree: u.Tree): Any } /** Represents an error during toolboxing diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index 589c5c7eb0..6c48762200 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -97,7 +97,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => (expr, freeTermNames) } - def typeCheckExpr(expr0: Tree, pt: Type, silent: Boolean = false, withImplicitViewsDisabled: Boolean, withMacrosDisabled: Boolean): Tree = { + def transformDuringTyper(expr0: Tree, withImplicitViewsDisabled: Boolean, withMacrosDisabled: Boolean)(transform: (analyzer.Typer, Tree) => Tree): Tree = { verifyExpr(expr0) // need to wrap the expr, because otherwise you won't be able to typecheck macros against something that contains free vars @@ -121,34 +121,56 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => currentTyper.context.setReportErrors() // need to manually set context mode, otherwise typer.silent will throw exceptions reporter.reset() - trace("typing (implicit views = %s, macros = %s): ".format(!withImplicitViewsDisabled, !withMacrosDisabled))(showAttributed(expr, true, true, settings.Yshowsymkinds.value)) - wrapper(currentTyper.silent(_.typed(expr, analyzer.EXPRmode, pt)) match { - case analyzer.SilentResultValue(result) => - trace("success: ")(showAttributed(result, true, true, settings.Yshowsymkinds.value)) - var (dummies, unwrapped) = result match { - case Block(dummies, unwrapped) => (dummies, unwrapped) - case unwrapped => (Nil, unwrapped) + val expr1 = wrapper(transform(currentTyper, expr)) + var (dummies1, unwrapped) = expr1 match { + case Block(dummies, unwrapped) => (dummies, unwrapped) + case unwrapped => (Nil, unwrapped) + } + var invertedIndex = freeTerms map (_.swap) + // todo. also fixup singleton types + unwrapped = new Transformer { + override def transform(tree: Tree): Tree = + tree match { + case Ident(name) if invertedIndex contains name => + Ident(invertedIndex(name)) setType tree.tpe + case _ => + super.transform(tree) } - var invertedIndex = freeTerms map (_.swap) - // todo. also fixup singleton types - unwrapped = new Transformer { - override def transform(tree: Tree): Tree = - tree match { - case Ident(name) if invertedIndex contains name => - Ident(invertedIndex(name)) setType tree.tpe - case _ => - super.transform(tree) - } - }.transform(unwrapped) - new TreeTypeSubstituter(dummies map (_.symbol), dummies map (dummy => SingleType(NoPrefix, invertedIndex(dummy.symbol.name)))).traverse(unwrapped) - unwrapped - case error @ analyzer.SilentTypeError(_) => - trace("failed: ")(error.err.errMsg) - if (!silent) throw ToolBoxError("reflective typecheck has failed: %s".format(error.err.errMsg)) - EmptyTree - }) + }.transform(unwrapped) + new TreeTypeSubstituter(dummies1 map (_.symbol), dummies1 map (dummy => SingleType(NoPrefix, invertedIndex(dummy.symbol.name)))).traverse(unwrapped) + unwrapped } + def typeCheckExpr(expr: Tree, pt: Type, silent: Boolean, withImplicitViewsDisabled: Boolean, withMacrosDisabled: Boolean): Tree = + transformDuringTyper(expr, withImplicitViewsDisabled = withImplicitViewsDisabled, withMacrosDisabled = withMacrosDisabled)( + (currentTyper, expr) => { + trace("typing (implicit views = %s, macros = %s): ".format(!withImplicitViewsDisabled, !withMacrosDisabled))(showAttributed(expr, true, true, settings.Yshowsymkinds.value)) + currentTyper.silent(_.typed(expr, analyzer.EXPRmode, pt)) match { + case analyzer.SilentResultValue(result) => + trace("success: ")(showAttributed(result, true, true, settings.Yshowsymkinds.value)) + result + case error @ analyzer.SilentTypeError(_) => + trace("failed: ")(error.err.errMsg) + if (!silent) throw ToolBoxError("reflective typecheck has failed: %s".format(error.err.errMsg)) + EmptyTree + } + }) + + def inferImplicit(tree: Tree, pt: Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: Position): Tree = + transformDuringTyper(tree, withImplicitViewsDisabled = false, withMacrosDisabled = withMacrosDisabled)( + (currentTyper, tree) => { + trace("inferring implicit %s (macros = %s): ".format(if (isView) "view" else "value", !withMacrosDisabled))(showAttributed(pt, true, true, settings.Yshowsymkinds.value)) + val context = currentTyper.context + analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos) match { + case failure if failure.tree.isEmpty => + trace("implicit search has failed. to find out the reason, turn on -Xlog-implicits: ")(failure.tree) + if (context.hasErrors) throw ToolBoxError("reflective implicit search has failed: %s".format(context.errBuffer.head.errMsg)) + EmptyTree + case success => + success.tree + } + }) + def compileExpr(expr: Tree): (Object, java.lang.reflect.Method) = { verifyExpr(expr) @@ -254,7 +276,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => } } - def showAttributed(tree: Tree, printTypes: Boolean = true, printIds: Boolean = true, printKinds: Boolean = false): String = { + def showAttributed(artifact: Any, printTypes: Boolean = true, printIds: Boolean = true, printKinds: Boolean = false): String = { val saved1 = settings.printtypes.value val saved2 = settings.uniqid.value val saved3 = settings.Yshowsymkinds.value @@ -262,7 +284,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => settings.printtypes.value = printTypes settings.uniqid.value = printIds settings.Yshowsymkinds.value = printKinds - tree.toString + artifact.toString } finally { settings.printtypes.value = saved1 settings.uniqid.value = saved2 @@ -312,29 +334,37 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => lazy val exporter = importer.reverse lazy val classLoader = new AbstractFileClassLoader(virtualDirectory, mirror.classLoader) - def typeCheck(tree: u.Tree, expectedType: u.Type, freeTypes: Map[u.FreeTypeSymbol, u.Type], silent: Boolean, withImplicitViewsDisabled: Boolean, withMacrosDisabled: Boolean): u.Tree = { - if (compiler.settings.verbose.value) println("typing "+tree+", expectedType = "+expectedType+", freeTypes = "+freeTypes) + def typeCheck(tree: u.Tree, expectedType: u.Type, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree = { + if (compiler.settings.verbose.value) println("importing "+tree+", expectedType = "+expectedType) var ctree: compiler.Tree = importer.importTree(tree) var cexpectedType: compiler.Type = importer.importType(expectedType) - if (compiler.settings.verbose.value) println("substituting "+ctree+", expectedType = "+expectedType) - val cfreeTypes: Map[compiler.FreeTypeSymbol, compiler.Type] = freeTypes map { case (k, v) => (importer.importSymbol(k).asInstanceOf[compiler.FreeTypeSymbol], importer.importType(v)) } - ctree = ctree.substituteTypes(cfreeTypes.keys.toList, cfreeTypes.values.toList) - cexpectedType = cexpectedType.substituteTypes(cfreeTypes.keys.toList, cfreeTypes.values.toList) - if (compiler.settings.verbose.value) println("typing "+ctree+", expectedType = "+expectedType) val ttree: compiler.Tree = compiler.typeCheckExpr(ctree, cexpectedType, silent = silent, withImplicitViewsDisabled = withImplicitViewsDisabled, withMacrosDisabled = withMacrosDisabled) val uttree = exporter.importTree(ttree) uttree } - def inferImplicitValue(pt: u.Type, silent: Boolean, withMacrosDisabled: Boolean): u.Tree = - // todo. implement this - ??? + def inferImplicitValue(pt: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree = { + inferImplicit(u.EmptyTree, pt, isView = false, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) + } + + def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree = { + val viewTpe = u.appliedType(u.definitions.FunctionClass(1).asTypeConstructor, List(from, to)) + inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) + } - def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean, withMacrosDisabled: Boolean, reportAmbiguous: Boolean): u.Tree = - // todo. implement this - ??? + private def inferImplicit(tree: u.Tree, pt: u.Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: u.Position): u.Tree = { + if (compiler.settings.verbose.value) println("importing "+pt, ", tree = "+tree+", pos = "+pos) + var ctree: compiler.Tree = importer.importTree(tree) + var cpt: compiler.Type = importer.importType(pt) + var cpos: compiler.Position = importer.importPosition(pos) + + if (compiler.settings.verbose.value) println("inferring implicit %s of type %s, macros = %s".format(if (isView) "view" else "value", pt, !withMacrosDisabled)) + val itree: compiler.Tree = compiler.inferImplicit(ctree, cpt, isView = isView, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = cpos) + val uitree = exporter.importTree(itree) + uitree + } def resetAllAttrs(tree: u.Tree): u.Tree = { val ctree: compiler.Tree = importer.importTree(tree) @@ -360,14 +390,10 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => utree } - def runExpr(tree: u.Tree, freeTypes: Map[u.FreeTypeSymbol, u.Type]): Any = { - if (compiler.settings.verbose.value) println("running "+tree+", freeTypes = "+freeTypes) + def runExpr(tree: u.Tree): Any = { + if (compiler.settings.verbose.value) println("importing "+tree) var ctree: compiler.Tree = importer.importTree(tree) - if (compiler.settings.verbose.value) println("substituting "+ctree) - val cfreeTypes: Map[compiler.FreeTypeSymbol, compiler.Type] = freeTypes map { case (k, v) => (importer.importSymbol(k).asInstanceOf[compiler.FreeTypeSymbol], importer.importType(v)) } - ctree = ctree.substituteTypes(cfreeTypes.keys.toList, cfreeTypes.values.toList) - if (compiler.settings.verbose.value) println("running "+ctree) compiler.runExpr(ctree) } diff --git a/src/reflect/scala/reflect/api/Importers.scala b/src/reflect/scala/reflect/api/Importers.scala index 69d6414f4f..de540a9605 100644 --- a/src/reflect/scala/reflect/api/Importers.scala +++ b/src/reflect/scala/reflect/api/Importers.scala @@ -17,5 +17,7 @@ trait Importers { self: Universe => def importType(tpe: from.Type): Type def importTree(tree: from.Tree): Tree + + def importPosition(pos: from.Position): Position } } \ No newline at end of file diff --git a/src/reflect/scala/reflect/internal/Importers.scala b/src/reflect/scala/reflect/internal/Importers.scala index 431d9819a5..00017e087a 100644 --- a/src/reflect/scala/reflect/internal/Importers.scala +++ b/src/reflect/scala/reflect/internal/Importers.scala @@ -14,6 +14,7 @@ trait Importers { self: SymbolTable => def importSymbol(sym: from.Symbol) = sym.asInstanceOf[self.Symbol] def importType(tpe: from.Type) = tpe.asInstanceOf[self.Type] def importTree(tree: from.Tree) = tree.asInstanceOf[self.Tree] + def importPosition(pos: from.Position) = pos.asInstanceOf[self.Position] } } else { // todo. fix this loophole diff --git a/src/reflect/scala/reflect/makro/Typers.scala b/src/reflect/scala/reflect/makro/Typers.scala index 2610d7dd50..4176c184d0 100644 --- a/src/reflect/scala/reflect/makro/Typers.scala +++ b/src/reflect/scala/reflect/makro/Typers.scala @@ -10,8 +10,8 @@ trait Typers { * Can be useful for interoperating with other macros and for imposing compiler-friendly limits on macro expansion. * * Is also priceless for emitting sane error messages for macros that are called by other macros on synthetic (i.e. position-less) trees. - * In that dire case navigate the ``openMacros'' stack, and it will most likely contain at least one macro with a position-ful macro application. - * See ``enclosingPosition'' for a default implementation of this logic. + * In that dire case navigate the `openMacros` stack, and it will most likely contain at least one macro with a position-ful macro application. + * See `enclosingPosition` for a default implementation of this logic. * * Unlike `enclosingMacros`, this is a def, which means that it gets recalculated on every invocation, * so it might change depending on what is going on during macro expansion. @@ -26,41 +26,38 @@ trait Typers { */ def openImplicits: List[(Type, Tree)] - /** Typechecks the provided tree against the expected type ``pt'' in the macro callsite context. + /** Typechecks the provided tree against the expected type `pt` in the macro callsite context. * - * If ``silent'' is false, ``TypeError'' will be thrown in case of a typecheck error. - * If ``silent'' is true, the typecheck is silent and will return ``EmptyTree'' if an error occurs. + * If `silent` is false, `TypeError` will be thrown in case of a typecheck error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Ymacro-debug-verbose. - * Unlike in ``inferImplicitValue'' and ``inferImplicitView'', ``silent'' is false by default. + * Unlike in `inferImplicitValue` and `inferImplicitView`, `silent` is false by default. * * Typechecking can be steered with the following optional parameters: - * ``withImplicitViewsDisabled'' recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false - * ``withMacrosDisabled'' recursively prohibits macro expansions and macro-based implicits, default value is false + * `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false + * `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false */ def typeCheck(tree: Tree, pt: Type = WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree - /** Infers an implicit value of the expected type ``pt'' in the macro callsite context. - * Optional ``pos'' parameter provides a position that will be associated with the implicit search. + /** Infers an implicit value of the expected type `pt` in the macro callsite context. + * Optional `pos` parameter provides a position that will be associated with the implicit search. * - * If ``silent'' is false, ``TypeError'' will be thrown in case of an inference error. - * If ``silent'' is true, the typecheck is silent and will return ``EmptyTree'' if an error occurs. + * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. - * Unlike in ``typeCheck'', ``silent'' is true by default. + * Unlike in `typeCheck`, `silent` is true by default. */ def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree - /** Infers an implicit view from the provided tree ``tree'' from the type ``from'' to the type ``to'' in the macro callsite context. + /** Infers an implicit view from the provided tree `tree` of the type `from` to the type `to` in the macro callsite context. + * Optional `pos` parameter provides a position that will be associated with the implicit search. * - * Optional ``pos'' parameter provides a position that will be associated with the implicit search. - * Another optional parameter, ``reportAmbiguous`` controls whether ambiguous implicit errors should be reported. - * If we search for a view simply to find out whether one type is coercible to another, it might be desirable to set this flag to ``false''. - * - * If ``silent'' is false, ``TypeError'' will be thrown in case of an inference error. - * If ``silent'' is true, the typecheck is silent and will return ``EmptyTree'' if an error occurs. + * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. - * Unlike in ``typeCheck'', ``silent'' is true by default. + * Unlike in `typeCheck`, `silent` is true by default. */ - def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, reportAmbiguous: Boolean = true, pos: Position = enclosingPosition): Tree + def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree /** Recursively resets symbols and types in a given tree. * diff --git a/test/files/run/reify_newimpl_45.scala b/test/files/run/reify_newimpl_45.scala index d2254d6dde..cbae0839b2 100644 --- a/test/files/run/reify_newimpl_45.scala +++ b/test/files/run/reify_newimpl_45.scala @@ -8,7 +8,8 @@ object Test extends App { val code = reify{val x: T = "2".asInstanceOf[T]; println("ima worx: %s".format(x)); x} println(code.tree.freeTypes) val T = code.tree.freeTypes(0) - cm.mkToolBox().runExpr(code.tree, Map(T -> definitions.StringClass.asType)) + val tree = code.tree.substituteSymbols(List(T), List(definitions.StringClass)) + cm.mkToolBox().runExpr(tree) } new C[String] diff --git a/test/files/run/toolbox_typecheck_inferimplicitvalue.check b/test/files/run/toolbox_typecheck_inferimplicitvalue.check new file mode 100644 index 0000000000..23ba536aff --- /dev/null +++ b/test/files/run/toolbox_typecheck_inferimplicitvalue.check @@ -0,0 +1 @@ +C.MC diff --git a/test/files/run/toolbox_typecheck_inferimplicitvalue.scala b/test/files/run/toolbox_typecheck_inferimplicitvalue.scala new file mode 100644 index 0000000000..3c5c994ac9 --- /dev/null +++ b/test/files/run/toolbox_typecheck_inferimplicitvalue.scala @@ -0,0 +1,13 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +class C +object C { + implicit object MC extends C +} + +object Test extends App { + val tb = cm.mkToolBox() + println(tb.inferImplicitValue(typeOf[C])) +} \ No newline at end of file -- cgit v1.2.3 From a727c6fc198d33842ff85d8a16d48143a6757d51 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 30 Jul 2012 13:17:17 +0200 Subject: SI-5732 members and derivatives now return Scope Firstly this unifies the reflection API - now both decls and members return Scope (not Scope and List[Symbol] as it were before). Secondly this fixes SI-5732 without having to sort the result of members. Type.members now returns Scope, a distinguished type, which has the `sorted` method, which does the required sorting if necessary. Also removes nonPrivateMembers and nonPrivateDeclarations to keep the API minimalistic (as can be seen from their implementation in internal.Types they are just members and decls with bridges and private members removed). --- .../scala/tools/nsc/doc/model/ModelFactory.scala | 4 +- .../doc/model/ModelFactoryImplicitSupport.scala | 2 +- .../scala/tools/nsc/interpreter/Imports.scala | 2 +- .../tools/nsc/interpreter/JLineCompletion.scala | 8 ++-- .../tools/nsc/interpreter/MemberHandlers.scala | 2 +- .../scala/tools/nsc/interpreter/Power.scala | 4 +- .../scala/tools/nsc/typechecker/Contexts.scala | 10 ++--- .../scala/tools/nsc/typechecker/Implicits.scala | 2 +- .../scala/tools/nsc/typechecker/RefChecks.scala | 4 +- src/library/scala/reflect/base/Base.scala | 13 ++++-- src/library/scala/reflect/base/Scopes.scala | 22 +++++++++- src/reflect/scala/reflect/api/Types.scala | 31 ++++++-------- src/reflect/scala/reflect/internal/Scopes.scala | 50 +++++++++++++++++++--- src/reflect/scala/reflect/internal/Symbols.scala | 4 +- src/reflect/scala/reflect/internal/Types.scala | 22 +++++----- .../reflect/runtime/SynchronizedSymbols.scala | 2 +- test/files/run/reflection-simple.check | 45 ------------------- test/files/run/reflection-simple.scala | 12 ------ test/files/run/reflection-sorted-decls.check | 7 +++ test/files/run/reflection-sorted-decls.scala | 8 ++++ test/files/run/reflection-sorted-members.check | 34 +++++++++++++++ test/files/run/reflection-sorted-members.scala | 11 +++++ 22 files changed, 178 insertions(+), 121 deletions(-) delete mode 100644 test/files/run/reflection-simple.check delete mode 100644 test/files/run/reflection-simple.scala create mode 100644 test/files/run/reflection-sorted-decls.check create mode 100644 test/files/run/reflection-sorted-decls.scala create mode 100644 test/files/run/reflection-sorted-members.check create mode 100644 test/files/run/reflection-sorted-members.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index 00e6f3769e..8805f68634 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -380,7 +380,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { if (settings.docImplicits.value) makeImplicitConversions(sym, this) else Nil // members as given by the compiler - lazy val memberSyms = sym.info.members.filter(s => membersShouldDocument(s, this)) + lazy val memberSyms = sym.info.members.filter(s => membersShouldDocument(s, this)).toList // the inherited templates (classes, traits or objects) var memberSymsLazy = memberSyms.filter(t => templateShouldDocument(t, this) && !inOriginalOwner(t, this)) @@ -712,7 +712,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { override def inheritedFrom = Nil override def isRootPackage = true override lazy val memberSyms = - (bSym.info.members ++ EmptyPackage.info.members) filter { s => + (bSym.info.members ++ EmptyPackage.info.members).toList filter { s => s != EmptyPackage && s != RootPackage } }) diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala index a12b67c9ed..5a0cc602e5 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala @@ -386,7 +386,7 @@ trait ModelFactoryImplicitSupport { lazy val memberImpls: List[MemberImpl] = { // Obtain the members inherited by the implicit conversion - val memberSyms = toType.members.filter(implicitShouldDocument(_)) + val memberSyms = toType.members.filter(implicitShouldDocument(_)).toList val existingSyms = sym.info.members // Debugging part :) diff --git a/src/compiler/scala/tools/nsc/interpreter/Imports.scala b/src/compiler/scala/tools/nsc/interpreter/Imports.scala index d579e0369e..5e72d2b661 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Imports.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Imports.scala @@ -191,5 +191,5 @@ trait Imports { prevRequestList flatMap (req => req.handlers map (req -> _)) private def membersAtPickler(sym: Symbol): List[Symbol] = - beforePickler(sym.info.nonPrivateMembers) + beforePickler(sym.info.nonPrivateMembers.toList) } \ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala index c429e3b196..b9849e40d1 100644 --- a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala +++ b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala @@ -52,10 +52,10 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput // XXX we'd like to say "filterNot (_.isDeprecated)" but this causes the // compiler to crash for reasons not yet known. - def members = afterTyper((effectiveTp.nonPrivateMembers ++ anyMembers) filter (_.isPublic)) - def methods = members filter (_.isMethod) - def packages = members filter (_.isPackage) - def aliases = members filter (_.isAliasType) + def members = afterTyper((effectiveTp.nonPrivateMembers.toList ++ anyMembers) filter (_.isPublic)) + def methods = members.toList filter (_.isMethod) + def packages = members.toList filter (_.isPackage) + def aliases = members.toList filter (_.isAliasType) def memberNames = members map tos def methodNames = methods map tos diff --git a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala index 236f3f23c5..b0c20f3d0c 100644 --- a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala +++ b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala @@ -211,7 +211,7 @@ trait MemberHandlers { beforePickler(individualNames map (targetType nonPrivateMember _)) lazy val wildcardSymbols: List[Symbol] = - if (importsWildcard) beforePickler(targetType.nonPrivateMembers) + if (importsWildcard) beforePickler(targetType.nonPrivateMembers.toList) else Nil /** Complete list of names imported by a wildcard */ diff --git a/src/compiler/scala/tools/nsc/interpreter/Power.scala b/src/compiler/scala/tools/nsc/interpreter/Power.scala index 57d7cef726..ebc02d98ed 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Power.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Power.scala @@ -62,7 +62,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re def discarded = seen.size - keep.size def members(x: Symbol): List[Symbol] = - if (x.rawInfo.isComplete) x.info.members + if (x.rawInfo.isComplete) x.info.members.toList else Nil var lastCount = -1 @@ -216,7 +216,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re def declsOriginal = membersDeclared filterNot (_.isOverride) def members = membersUnabridged filterNot excludeMember - def membersUnabridged = tpe.members + def membersUnabridged = tpe.members.toList def membersDeclared = members filterNot excludeMember def membersInherited = members filterNot (membersDeclared contains _) def memberTypes = members filter (_.name.isTypeName) diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 0fc298e886..c7dab69f62 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -360,7 +360,7 @@ trait Contexts { self: Analyzer => private def unitError(pos: Position, msg: String) = unit.error(pos, if (checking) "\n**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) - + @inline private def issueCommon(err: AbsTypeError)(pf: PartialFunction[AbsTypeError, Unit]) { debugwarn("issue error: " + err.errMsg) if (settings.Yissuedebug.value) (new Exception).printStackTrace() @@ -611,8 +611,8 @@ trait Contexts { self: Analyzer => (e ne null) && (e.owner == scope) }) - private def collectImplicits(syms: List[Symbol], pre: Type, imported: Boolean = false): List[ImplicitInfo] = - for (sym <- syms if isQualifyingImplicit(sym.name, sym, pre, imported)) yield + private def collectImplicits(syms: Scope, pre: Type, imported: Boolean = false): List[ImplicitInfo] = + for (sym <- syms.toList if isQualifyingImplicit(sym.name, sym, pre, imported)) yield new ImplicitInfo(sym.name, pre, sym) private def collectImplicitImports(imp: ImportInfo): List[ImplicitInfo] = { @@ -657,7 +657,7 @@ trait Contexts { self: Analyzer => } } else if (scope != nextOuter.scope && !owner.isPackageClass) { debuglog("collect local implicits " + scope.toList)//DEBUG - collectImplicits(scope.toList, NoPrefix) + collectImplicits(scope, NoPrefix) } else if (imports != nextOuter.imports) { assert(imports.tail == nextOuter.imports, (imports, nextOuter.imports)) collectImplicitImports(imports.head) @@ -725,7 +725,7 @@ trait Contexts { self: Analyzer => result } - def allImportedSymbols: List[Symbol] = + def allImportedSymbols: Iterable[Symbol] = qual.tpe.members flatMap (transformImport(tree.selectors, _)) private def transformImport(selectors: List[ImportSelector], sym: Symbol): List[Symbol] = selectors match { diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index da045e1a48..529f5408a2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -957,7 +957,7 @@ trait Implicits { companion.moduleClass match { case mc: ModuleClassSymbol => val infos = - for (im <- mc.implicitMembers) yield new ImplicitInfo(im.name, singleType(pre, companion), im) + for (im <- mc.implicitMembers.toList) yield new ImplicitInfo(im.name, singleType(pre, companion), im) if (infos.nonEmpty) infoMap += (sym -> infos) case _ => diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 3518316fbb..9501998152 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -122,7 +122,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R val defaultGetters = clazz.info.findMembers(0L, DEFAULTPARAM) val defaultMethodNames = defaultGetters map (sym => nme.defaultGetterToMethod(sym.name)) - defaultMethodNames.distinct foreach { name => + defaultMethodNames.toList.distinct foreach { name => val methods = clazz.info.findMember(name, 0L, METHOD, false).alternatives val haveDefaults = methods filter (sym => sym.hasParamWhich(_.hasDefault) && !nme.isProtectedAccessorName(sym.name)) @@ -628,7 +628,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R matchingArity match { // So far so good: only one candidate method - case concrete :: Nil => + case Scope(concrete) => val mismatches = abstractParams zip concrete.tpe.paramTypes filterNot { case (x, y) => x =:= y } mismatches match { // Only one mismatched parameter: say something useful. diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala index 53854f160d..ddb502fd44 100644 --- a/src/library/scala/reflect/base/Base.scala +++ b/src/library/scala/reflect/base/Base.scala @@ -170,12 +170,17 @@ class Base extends Universe { self => object BoundedWildcardType extends BoundedWildcardTypeExtractor implicit val BoundedWildcardTypeTag = ClassTag[BoundedWildcardType](classOf[BoundedWildcardType]) - type Scope = Iterable[Symbol] + class Scope(elems: Iterable[Symbol]) extends ScopeBase with MemberScopeBase { + def iterator = elems.iterator + def sorted = elems.toList + } + type MemberScope = Scope implicit val ScopeTag = ClassTag[Scope](classOf[Scope]) + implicit val MemberScopeTag = ClassTag[MemberScope](classOf[MemberScope]) - def newScope = newScopeWith() - def newNestedScope(outer: Iterable[Symbol]) = newScope - def newScopeWith(elems: Symbol*): Scope = elems + def newScope: Scope = newScopeWith() + def newNestedScope(outer: Scope): Scope = newScope + def newScopeWith(elems: Symbol*): Scope = new Scope(elems) abstract class Name(str: String) extends NameBase { override def toString = str diff --git a/src/library/scala/reflect/base/Scopes.scala b/src/library/scala/reflect/base/Scopes.scala index a5db01c0ce..a388fdc392 100644 --- a/src/library/scala/reflect/base/Scopes.scala +++ b/src/library/scala/reflect/base/Scopes.scala @@ -3,13 +3,33 @@ package base trait Scopes { self: Universe => - type Scope >: Null <: Iterable[Symbol] + type Scope >: Null <: ScopeBase + + /** The base API that all scopes support */ + trait ScopeBase extends Iterable[Symbol] /** A tag that preserves the identity of the `Scope` abstract type from erasure. * Can be used for pattern matching, instance tests, serialization and likes. */ implicit val ScopeTag: ClassTag[Scope] + type MemberScope >: Null <: Scope with MemberScopeBase + + /** The base API that all member scopes support */ + trait MemberScopeBase extends ScopeBase { + /** Sorts the symbols included in this scope so that: + * 1) Symbols appear the linearization order of their owners. + * 2) Symbols with the same owner appear in reverse order of their declarations. + * 3) Synthetic members (e.g. getters/setters for vals/vars) might appear in arbitrary order. + */ + def sorted: List[Symbol] + } + + /** A tag that preserves the identity of the `MemberScope` abstract type from erasure. + * Can be used for pattern matching, instance tests, serialization and likes. + */ + implicit val MemberScopeTag: ClassTag[MemberScope] + /** Create a new scope */ def newScope: Scope diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala index 01de5fa9a7..33248fcbee 100644 --- a/src/reflect/scala/reflect/api/Types.scala +++ b/src/reflect/scala/reflect/api/Types.scala @@ -24,33 +24,26 @@ trait Types extends base.Types { self: Universe => */ def declaration(name: Name): Symbol - /** The collection of declarations in this type - * [Eugene++] why not List? + /** A `Scope` containing directly declared members of this type. + * Unlike `members` this method doesn't returns inherited members. + * + * Members in the returned scope might appear in arbitrary order. + * Use `declarations.sorted` to get an ordered list of members. */ - def declarations: Iterable[Symbol] + def declarations: MemberScope /** The member with given name, either directly declared or inherited, * an OverloadedSymbol if several exist, NoSymbol if none exist. */ def member(name: Name): Symbol - /** The non-private member with given name, either directly declared or inherited, - * an OverloadedSymbol if several exist, NoSymbol if none exist. - */ - def nonPrivateMember(name: Name): Symbol - - /** An iterable containing all members of this type (directly declared or inherited) - * Members appear in the linearization order of their owners. - * Members with the same owner appear in reverse order of their declarations. - * [Eugene++] the order needs to be reversed back, at least in the public API - */ - def members: Iterable[Symbol] - - /** An iterable containing all non-private members of this type (directly declared or inherited) - * Members appear in the linearization order of their owners. - * Members with the same owner appear in reverse order of their declarations. + /** A `Scope` containing all members of this type (directly declared or inherited). + * Unlike `declarations` this method also returns inherited members. + * + * Members in the returned scope might appear in arbitrary order. + * Use `declarations.sorted` to get an ordered list of members. */ - def nonPrivateMembers: Iterable[Symbol] + def members: MemberScope /** Substitute symbols in `to` for corresponding occurrences of references to * symbols `from` in this type. diff --git a/src/reflect/scala/reflect/internal/Scopes.scala b/src/reflect/scala/reflect/internal/Scopes.scala index 89e3c52de6..ed390b5a3b 100644 --- a/src/reflect/scala/reflect/internal/Scopes.scala +++ b/src/reflect/scala/reflect/internal/Scopes.scala @@ -41,9 +41,9 @@ trait Scopes extends api.Scopes { self: SymbolTable => * This is necessary because when run from reflection every scope needs to have a * SynchronizedScope as mixin. */ - class Scope protected[Scopes] (initElems: ScopeEntry = null, initFingerPrints: Long = 0L) extends Iterable[Symbol] { - - /** A bitset containing the last 6 bits of the start value of every name + class Scope protected[Scopes] (initElems: ScopeEntry = null, initFingerPrints: Long = 0L) extends ScopeBase with MemberScopeBase { + + /** A bitset containing the last 6 bits of the start value of every name * stored in this scope. */ var fingerPrints: Long = initFingerPrints @@ -118,10 +118,10 @@ trait Scopes extends api.Scopes { self: SymbolTable => * * @param sym ... */ - def enter[T <: Symbol](sym: T): T = { + def enter[T <: Symbol](sym: T): T = { fingerPrints |= sym.name.fingerPrint - enterEntry(newScopeEntry(sym, this)) - sym + enterEntry(newScopeEntry(sym, this)) + sym } /** enter a symbol, asserting that no symbol with same name exists in scope @@ -282,6 +282,10 @@ trait Scopes extends api.Scopes { self: SymbolTable => elemsCache } + /** Vanilla scope - symbols are stored in declaration order. + */ + def sorted: List[Symbol] = toList + /** Return the nesting level of this scope, i.e. the number of times this scope * was nested in another */ def nestingLevel = nestinglevel @@ -324,14 +328,46 @@ trait Scopes extends api.Scopes { self: SymbolTable => toList.map(_.defString).mkString(start, sep, end) override def toString(): String = mkString("Scope{\n ", ";\n ", "\n}") - } implicit val ScopeTag = ClassTag[Scope](classOf[Scope]) + type MemberScope = Scope + + implicit val MemberScopeTag = ClassTag[MemberScope](classOf[MemberScope]) + /** Create a new scope */ def newScope: Scope = new Scope() + /** Create a new scope to be used in `findMembers`. + * + * But why do we need a special scope for `findMembers`? + * Let me tell you a story. + * + * `findMembers` creates a synthetic scope and then iterates over + * base classes in linearization order, and for every scrutinized class + * iterates over `decls`, the collection of symbols declared in that class. + * Declarations that fit the filter get appended to the created scope. + * + * The problem is that `decls` returns a Scope, and to iterate a scope performantly + * one needs to go from its end to its beginning. + * + * Hence the `findMembers` scope is populated in a wicked order: + * symbols that belong to the same declaring class come in reverse order of their declaration, + * however, the scope itself is ordered w.r.t the linearization of the target type. + * + * Once `members` became a public API, this has been confusing countless numbers of users. + * Therefore we introduce a special flavor of scopes to accommodate this quirk of `findMembers` + */ + private[scala] def newFindMemberScope: Scope = new Scope() { + override def sorted = { + val members = toList + val owners = members.map(_.owner).distinct + val grouped = members groupBy (_.owner) + owners.flatMap(owner => grouped(owner).reverse) + } + } + /** Create a new scope nested in another one with which it shares its elements */ def newNestedScope(outer: Scope): Scope = new Scope(outer) diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index e6a9cb46c6..05ead8d1ac 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2890,7 +2890,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => private[this] var typeOfThisCache: Type = _ private[this] var typeOfThisPeriod = NoPeriod - private var implicitMembersCacheValue: List[Symbol] = Nil + private var implicitMembersCacheValue: Scope = EmptyScope private var implicitMembersCacheKey1: Type = NoType private var implicitMembersCacheKey2: ScopeEntry = null @@ -2909,7 +2909,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => typeOfThisCache } - def implicitMembers: List[Symbol] = { + def implicitMembers: Scope = { val tp = info if ((implicitMembersCacheKey1 ne tp) || (implicitMembersCacheKey2 ne tp.decls.elems)) { // Skip a package object class, because the members are also in diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 8972dfa828..1386cca42f 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -612,21 +612,21 @@ trait Types extends api.Types { self: SymbolTable => * Members appear in linearization order of their owners. * Members with the same owner appear in reverse order of their declarations. */ - def members: List[Symbol] = membersBasedOnFlags(0, 0) + def members: Scope = membersBasedOnFlags(0, 0) /** A list of all non-private members of this type (defined or inherited) */ - def nonPrivateMembers: List[Symbol] = membersBasedOnFlags(BridgeAndPrivateFlags, 0) + def nonPrivateMembers: Scope = membersBasedOnFlags(BridgeAndPrivateFlags, 0) /** A list of all non-private members of this type (defined or inherited), * admitting members with given flags `admit` */ - def nonPrivateMembersAdmitting(admit: Long): List[Symbol] = membersBasedOnFlags(BridgeAndPrivateFlags & ~admit, 0) + def nonPrivateMembersAdmitting(admit: Long): Scope = membersBasedOnFlags(BridgeAndPrivateFlags & ~admit, 0) /** A list of all implicit symbols of this type (defined or inherited) */ - def implicitMembers: List[Symbol] = membersBasedOnFlags(BridgeFlags, IMPLICIT) + def implicitMembers: Scope = membersBasedOnFlags(BridgeFlags, IMPLICIT) /** A list of all deferred symbols of this type (defined or inherited) */ - def deferredMembers: List[Symbol] = membersBasedOnFlags(BridgeFlags, DEFERRED) + def deferredMembers: Scope = membersBasedOnFlags(BridgeFlags, DEFERRED) /** The member with given name, * an OverloadedSymbol if several exist, NoSymbol if none exist */ @@ -642,12 +642,12 @@ trait Types extends api.Types { self: SymbolTable => /** All members with the given flags, excluding bridges. */ - def membersWithFlags(requiredFlags: Long): List[Symbol] = + def membersWithFlags(requiredFlags: Long): Scope = membersBasedOnFlags(BridgeFlags, requiredFlags) /** All non-private members with the given flags, excluding bridges. */ - def nonPrivateMembersWithFlags(requiredFlags: Long): List[Symbol] = + def nonPrivateMembersWithFlags(requiredFlags: Long): Scope = membersBasedOnFlags(BridgeAndPrivateFlags, requiredFlags) /** The non-private member with given name, admitting members with given flags `admit`. @@ -668,7 +668,7 @@ trait Types extends api.Types { self: SymbolTable => /** Members excluding and requiring the given flags. * Note: unfortunately it doesn't work to exclude DEFERRED this way. */ - def membersBasedOnFlags(excludedFlags: Long, requiredFlags: Long): List[Symbol] = + def membersBasedOnFlags(excludedFlags: Long, requiredFlags: Long): Scope = findMembers(excludedFlags, requiredFlags) // findMember(nme.ANYNAME, excludedFlags, requiredFlags, false).alternatives @@ -1020,7 +1020,7 @@ trait Types extends api.Types { self: SymbolTable => else (baseClasses.head.newOverloaded(this, alts)) } - def findMembers(excludedFlags: Long, requiredFlags: Long): List[Symbol] = { + def findMembers(excludedFlags: Long, requiredFlags: Long): Scope = { // if this type contains type variables, put them to sleep for a while -- don't just wipe them out by // replacing them by the corresponding type parameter, as that messes up (e.g.) type variables in type refinements // without this, the matchesType call would lead to type variables on both sides @@ -1054,7 +1054,7 @@ trait Types extends api.Types { self: SymbolTable => (bcs eq bcs0) || (flags & PrivateLocal) != PrivateLocal || (bcs0.head.hasTransOwner(bcs.head)))) { - if (members eq null) members = newScope + if (members eq null) members = newFindMemberScope var others: ScopeEntry = members.lookupEntry(sym.name) var symtpe: Type = null while ((others ne null) && { @@ -1083,7 +1083,7 @@ trait Types extends api.Types { self: SymbolTable => } // while (continue) Statistics.popTimer(typeOpsStack, start) if (suspension ne null) suspension foreach (_.suspended = false) - if (members eq null) Nil else members.toList + if (members eq null) EmptyScope else members } /** diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index 3b28ddf42c..6a3501b1dd 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -134,7 +134,7 @@ trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => override def sourceModule = synchronized { super.sourceModule } // [Eugene++ to Martin] doesn't override anything. no longer necessary? // def sourceModule_=(module: ModuleSymbol) = synchronized { super.sourceModule_=(module) } - override def implicitMembers: List[Symbol] = synchronized { super.implicitMembers } + override def implicitMembers: Scope = synchronized { super.implicitMembers } } } diff --git a/test/files/run/reflection-simple.check b/test/files/run/reflection-simple.check deleted file mode 100644 index 671d9d2716..0000000000 --- a/test/files/run/reflection-simple.check +++ /dev/null @@ -1,45 +0,0 @@ -Running -constructor Foo$3 -constructor Object -method != -method != -method ## -method $asInstanceOf -method $init$ -method $isInstanceOf -method == -method == -method _1 -method _2 -method _3 -method a -method asInstanceOf -method b -method c -method canEqual -method clone -method copy -method copy$default$1 -method copy$default$2 -method copy$default$3 -method eq -method equals -method finalize -method getClass -method hashCode -method isInstanceOf -method ne -method notify -method notifyAll -method productArity -method productElement -method productIterator -method productPrefix -method synchronized -method toString -method wait -method wait -method wait -value a -value b -value c diff --git a/test/files/run/reflection-simple.scala b/test/files/run/reflection-simple.scala deleted file mode 100644 index ec34b71cec..0000000000 --- a/test/files/run/reflection-simple.scala +++ /dev/null @@ -1,12 +0,0 @@ -// a.scala -// Wed May 2 01:01:22 PDT 2012 - -object Test { - def main(args: Array[String]) { - System.out.println("Running") - case class Foo(a: Int, b: Int, c: Int) - import scala.reflect.runtime.{currentMirror => cm} - val props = cm.classSymbol(classOf[Foo]).typeSignature.members.filter(_.isTerm).map(_.toString) - props.toList.sorted foreach System.out.println - } -} diff --git a/test/files/run/reflection-sorted-decls.check b/test/files/run/reflection-sorted-decls.check new file mode 100644 index 0000000000..9a9832a683 --- /dev/null +++ b/test/files/run/reflection-sorted-decls.check @@ -0,0 +1,7 @@ +value a +value b +value c +method c +method b +method a +constructor Foo$1 diff --git a/test/files/run/reflection-sorted-decls.scala b/test/files/run/reflection-sorted-decls.scala new file mode 100644 index 0000000000..242f17d9bb --- /dev/null +++ b/test/files/run/reflection-sorted-decls.scala @@ -0,0 +1,8 @@ +object Test { + def main(args: Array[String]) { + class Foo(val a: Int, val b: Int, val c: Int) + import scala.reflect.runtime.{currentMirror => cm} + val decls = cm.classSymbol(classOf[Foo]).typeSignature.declarations + decls.sorted.toList foreach System.out.println + } +} diff --git a/test/files/run/reflection-sorted-members.check b/test/files/run/reflection-sorted-members.check new file mode 100644 index 0000000000..d58b691c42 --- /dev/null +++ b/test/files/run/reflection-sorted-members.check @@ -0,0 +1,34 @@ +value a +value b +value c +method c +method b +method a +constructor Foo$1 +value x +method x +constructor Bar$1 +method finalize +method wait +method wait +method wait +method equals +method toString +method hashCode +method getClass +method clone +method notify +method notifyAll +constructor Object +method eq +method ne +method == +method != +method ## +method synchronized +method $isInstanceOf +method $asInstanceOf +method == +method != +method isInstanceOf +method asInstanceOf diff --git a/test/files/run/reflection-sorted-members.scala b/test/files/run/reflection-sorted-members.scala new file mode 100644 index 0000000000..9980d79999 --- /dev/null +++ b/test/files/run/reflection-sorted-members.scala @@ -0,0 +1,11 @@ +object Test { + def main(args: Array[String]) { + trait T1 { def a: Int; def c: Int } + trait T2 { def a: Int; def b: Int } + class Bar(val x: Int) + class Foo(val a: Int, val b: Int, val c: Int) extends Bar(a + b + c) with T1 with T2 + import scala.reflect.runtime.{currentMirror => cm} + val members = cm.classSymbol(classOf[Foo]).typeSignature.members + members.sorted.toList foreach System.out.println + } +} -- cgit v1.2.3 From 7112c66d6951ac83ae3591426291ec2797824258 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 30 Jul 2012 22:35:36 +0200 Subject: navigation between fields and accessors This works around SI-5736 that's been deemed too risky to be fixed in 2.10.0. A reflection newbie will be unlikely to acquire a field symbol from its name, but the `accessed` method provides an easy way to navigate to it from a getter. --- src/reflect/scala/reflect/api/Mirrors.scala | 2 +- src/reflect/scala/reflect/api/Symbols.scala | 12 ++++++++++++ src/reflect/scala/reflect/internal/Symbols.scala | 2 ++ test/files/run/reflection-fieldsymbol-navigation.check | 6 ++++++ test/files/run/reflection-fieldsymbol-navigation.scala | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/files/run/reflection-fieldsymbol-navigation.check create mode 100644 test/files/run/reflection-fieldsymbol-navigation.scala (limited to 'test/files') diff --git a/src/reflect/scala/reflect/api/Mirrors.scala b/src/reflect/scala/reflect/api/Mirrors.scala index 27176a2a2d..fe4348d568 100644 --- a/src/reflect/scala/reflect/api/Mirrors.scala +++ b/src/reflect/scala/reflect/api/Mirrors.scala @@ -34,7 +34,7 @@ trait Mirrors { self: Universe => * that can be used to get and, if appropriate, set the value of the field. * * To get a field symbol by the name of the field you would like to reflect, - * use `.symbol.typeSignature.member(newTermName()).asTermSymbol`. + * use `.symbol.typeSignature.member(newTermName()).asTermSymbol.accessed`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala index 7a5db4a3f5..7ca1d9c7c6 100644 --- a/src/reflect/scala/reflect/api/Symbols.scala +++ b/src/reflect/scala/reflect/api/Symbols.scala @@ -185,6 +185,18 @@ trait Symbols extends base.Symbols { self: Universe => /** The overloaded alternatives of this symbol */ def alternatives: List[Symbol] + + /** Backing field for an accessor method, NoSymbol for all other term symbols. + */ + def accessed: Symbol + + /** Getter method for a backing field of a val or a val, NoSymbol for all other term symbols. + */ + def getter: Symbol + + /** Setter method for a backing field of a val or a val, NoSymbol for all other term symbols. + */ + def setter: Symbol } /** The API of type symbols */ diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 05ead8d1ac..8cf20ba062 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -84,6 +84,8 @@ trait Symbols extends api.Symbols { self: SymbolTable => def getAnnotations: List[AnnotationInfo] = { initialize; annotations } def setAnnotations(annots: AnnotationInfo*): this.type = { setAnnotations(annots.toList); this } + def getter: Symbol = getter(owner) + def setter: Symbol = setter(owner) } /** The class for all symbols */ diff --git a/test/files/run/reflection-fieldsymbol-navigation.check b/test/files/run/reflection-fieldsymbol-navigation.check new file mode 100644 index 0000000000..79f0928ea5 --- /dev/null +++ b/test/files/run/reflection-fieldsymbol-navigation.check @@ -0,0 +1,6 @@ +method x +false +variable x +true +method x +method x_= diff --git a/test/files/run/reflection-fieldsymbol-navigation.scala b/test/files/run/reflection-fieldsymbol-navigation.scala new file mode 100644 index 0000000000..da4612a564 --- /dev/null +++ b/test/files/run/reflection-fieldsymbol-navigation.scala @@ -0,0 +1,15 @@ +import scala.reflect.runtime.universe._ + +class C { + var x = 2 +} + +object Test extends App { + val x = typeOf[C].member(newTermName("x")).asTerm + println(x) + println(x.isVariable) + println(x.accessed) + println(x.accessed.asTerm.isVariable) + println(x.getter) + println(x.setter) +} \ No newline at end of file -- cgit v1.2.3 From 367b82de04bdee24b0994e30c1464297eae16d74 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 30 Jul 2012 21:14:42 +0200 Subject: miscellaneous refinements of reflection API 1) Removed unnecessary (i.e. implementable with pattern matching) type APIs. 2) Renamed isHigherKinded to takesTypeArgs making it easier to understand. 2) typeParams and resultType have been moved from MethodType to MethodSymbol Strictly speaking they are superfluous, but they are used very often. --- .../scala/tools/nsc/interpreter/TypeStrings.scala | 3 +- .../tools/nsc/typechecker/MethodSynthesis.scala | 5 +- src/reflect/scala/reflect/api/Symbols.scala | 79 ++++++++++------- src/reflect/scala/reflect/api/Types.scala | 98 ++++++++-------------- src/reflect/scala/reflect/internal/Symbols.scala | 23 +++++ src/reflect/scala/reflect/internal/Types.scala | 1 + .../reflect/runtime/SynchronizedSymbols.scala | 3 + .../run/reflection-methodsymbol-allparams.check | 8 ++ .../run/reflection-methodsymbol-allparams.scala | 24 ++++++ .../files/run/reflection-methodsymbol-params.check | 8 ++ .../files/run/reflection-methodsymbol-params.scala | 24 ++++++ .../run/reflection-methodsymbol-resulttype.check | 8 ++ .../run/reflection-methodsymbol-resulttype.scala | 24 ++++++ .../run/reflection-methodsymbol-typeparams.check | 8 ++ .../run/reflection-methodsymbol-typeparams.scala | 24 ++++++ 15 files changed, 239 insertions(+), 101 deletions(-) create mode 100644 test/files/run/reflection-methodsymbol-allparams.check create mode 100644 test/files/run/reflection-methodsymbol-allparams.scala create mode 100644 test/files/run/reflection-methodsymbol-params.check create mode 100644 test/files/run/reflection-methodsymbol-params.scala create mode 100644 test/files/run/reflection-methodsymbol-resulttype.check create mode 100644 test/files/run/reflection-methodsymbol-resulttype.scala create mode 100644 test/files/run/reflection-methodsymbol-typeparams.check create mode 100644 test/files/run/reflection-methodsymbol-typeparams.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala index 56b9c7011c..202d5d3f82 100644 --- a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala +++ b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala @@ -212,8 +212,7 @@ trait TypeStrings { } private def tparamString[T: ru.TypeTag] : String = { - // [Eugene++ to Paul] needs review!! - def typeArguments: List[ru.Type] = ru.typeOf[T].typeArguments + def typeArguments: List[ru.Type] = ru.typeOf[T] match { case ru.TypeRef(_, _, args) => args; case _ => Nil } // [Eugene++] todo. need to use not the `rootMirror`, but a mirror with the REPL's classloader // how do I get to it? acquiring context classloader seems unreliable because of multithreading def typeVariables: List[java.lang.Class[_]] = typeArguments map (targ => ru.rootMirror.runtimeClass(targ)) diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala index 7bd5f4caeb..bd2808d049 100644 --- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala +++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala @@ -70,11 +70,8 @@ trait MethodSynthesis { // [Eugene++->Martin] now this compiles, will soon check it out def newMethodType[F](owner: Symbol)(implicit t: TT[F]): Type = { val fnSymbol = compilerSymbolFromTag(t) - assert(fnSymbol isSubClass FunctionClass(t.tpe.typeArguments.size - 1), (owner, t)) - // [Eugene++ to Paul] needs review!! - // val symbols = m.typeArguments map (m => manifestToSymbol(m)) - // val formals = symbols.init map (_.typeConstructor) val formals = compilerTypeFromTag(t).typeArguments + assert(fnSymbol isSubClass FunctionClass(formals.size - 1), (owner, t)) val params = owner newSyntheticValueParams formals MethodType(params, formals.last) } diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala index 7ca1d9c7c6..cd9044c934 100644 --- a/src/reflect/scala/reflect/api/Symbols.scala +++ b/src/reflect/scala/reflect/api/Symbols.scala @@ -43,23 +43,6 @@ trait Symbols extends base.Symbols { self: Universe => */ def hasAnnotation(sym: Symbol): Boolean - /** ... - */ - def orElse(alt: => Symbol): Symbol - - /** ... - */ - def filter(cond: Symbol => Boolean): Symbol - - /** If this is a NoSymbol, returns NoSymbol, otherwise - * returns the result of applying `f` to this symbol. - */ - def map(f: Symbol => Symbol): Symbol - - /** ... - */ - def suchThat(cond: Symbol => Boolean): Symbol - /** * Set when symbol has a modifier of the form private[X], NoSymbol otherwise. * @@ -93,15 +76,17 @@ trait Symbols extends base.Symbols { self: Universe => */ def companionSymbol: Symbol - /** If this symbol is a package class, this symbol; otherwise the next enclosing - * package class, or `NoSymbol` if none exists. + /** The type signature of this symbol seen as a member of given type `site`. */ - def enclosingPackageClass: Symbol + def typeSignatureIn(site: Type): Type - /** If this symbol is a top-level class, this symbol; otherwise the next enclosing - * top-level class, or `NoSymbol` if none exists. + /** The type signature of this symbol. + * Note if the symbol is a member of a class, one almost always is interested + * in `typeSignatureIn` with a site type instead. */ - def enclosingTopLevelClass: Symbol + def typeSignature: Type + + /******************* tests *******************/ /** Does this symbol represent the definition of a package? * If yes, `isTerm` is also guaranteed to be true. @@ -136,15 +121,24 @@ trait Symbols extends base.Symbols { self: Universe => */ def isStatic: Boolean - /** The type signature of this symbol seen as a member of given type `site`. + /******************* helpers *******************/ + + /** ... */ - def typeSignatureIn(site: Type): Type + def orElse(alt: => Symbol): Symbol - /** The type signature of this symbol. - * Note if the symbol is a member of a class, one almost always is interested - * in `typeSignatureIn` with a site type instead. + /** ... */ - def typeSignature: Type + def filter(cond: Symbol => Boolean): Symbol + + /** If this is a NoSymbol, returns NoSymbol, otherwise + * returns the result of applying `f` to this symbol. + */ + def map(f: Symbol => Symbol): Symbol + + /** ... + */ + def suchThat(cond: Symbol => Boolean): Symbol /** The string discriminator of this symbol; useful for debugging */ def kind: String @@ -263,10 +257,33 @@ trait Symbols extends base.Symbols { self: Universe => } /** The API of method symbols */ - type MethodSymbolApi = MethodSymbolBase + trait MethodSymbolApi extends TermSymbolApi with MethodSymbolBase { this: MethodSymbol => + /** For a polymorphic method, its type parameters, the empty list for all other methods */ + def typeParams: List[Symbol] + + /** The first parameter list of the method. + * + * For a nullary method, returns the empty list. + * For a method with an empty parameter list, returns the empty list. + * To distinguish between those, use `allParams`. + */ + def params: List[Symbol] + + /** All parameter lists of the method. + * + * Can be used to distinguish nullary methods and methods with empty parameter lists. + * For a nullary method, returns the empty list (i.e. `List()`). + * For a method with an empty parameter list, returns a list that contains the empty list (i.e. `List(List())`). + */ + def allParams: List[List[Symbol]] + + /** The result type of the method */ + def resultType: Type + } /** The API of module symbols */ - type ModuleSymbolApi = ModuleSymbolBase + trait ModuleSymbolApi extends TermSymbolApi with ModuleSymbolBase { this: ModuleSymbol => + } /** The API of class symbols */ trait ClassSymbolApi extends TypeSymbolApi with ClassSymbolBase { this: ClassSymbol => diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala index 33248fcbee..199cf9b9e5 100644 --- a/src/reflect/scala/reflect/api/Types.scala +++ b/src/reflect/scala/reflect/api/Types.scala @@ -45,45 +45,14 @@ trait Types extends base.Types { self: Universe => */ def members: MemberScope - /** Substitute symbols in `to` for corresponding occurrences of references to - * symbols `from` in this type. - */ - def substituteSymbols(from: List[Symbol], to: List[Symbol]): Type - - /** Substitute types in `to` for corresponding occurrences of references to - * symbols `from` in this type. - */ - def substituteTypes(from: List[Symbol], to: List[Type]): Type - - /** If this is a parameterized types, the type arguments. - * Otherwise the empty list - */ - def typeArguments: List[Type] - - /** For a (potentially wrapped) poly type, its type parameters, - * the empty list for all other types */ - def typeParams: List[Symbol] - - /** For a (nullary) method or poly type, its direct result type, - * the type itself for all other types. */ - def resultType: Type - /** Is this type a type constructor that is missing its type arguments? */ - def isHigherKinded: Boolean // !!! This should be called "isTypeConstructor", no? + def takesTypeArgs: Boolean /** Returns the corresponding type constructor (e.g. List for List[T] or List[String]) */ def typeConstructor: Type - /** Does this type refer to spliceable types or is a spliceable type? - */ - def isConcrete: Boolean - - /** Is this type an abstract type that needs to be resolved? - */ - def isSpliceable: Boolean - /** * Expands type aliases and converts higher-kinded TypeRefs to PolyTypes. * Functions on types are also implemented as PolyTypes. @@ -92,7 +61,7 @@ trait Types extends base.Types { self: Universe => * TypeRef(pre, , List()) is replaced by * PolyType(X, TypeRef(pre, , List(X))) */ - def normalize: Type // !!! Alternative name? "normalize" is used to mean too many things. + def normalize: Type /** Does this type conform to given type argument `that`? */ def <:< (that: Type): Boolean @@ -104,7 +73,7 @@ trait Types extends base.Types { self: Universe => * in reverse linearization order, starting with the class itself and ending * in class Any. */ - def baseClasses: List[Symbol] // !!! Alternative name, perhaps linearization? + def baseClasses: List[Symbol] /** The least type instance of given class which is a supertype * of this type. Example: @@ -134,36 +103,7 @@ trait Types extends base.Types { self: Universe => /** The erased type corresponding to this type after * all transformations from Scala to Java have been performed. */ - def erasure: Type // !!! "erasedType", compare with "widen" (so "erase") or "underlying" (so "erased") - // why not name it "erasure"? - - /** Apply `f` to each part of this type, returning - * a new type. children get mapped before their parents */ - def map(f: Type => Type): Type - - /** Apply `f` to each part of this type, for side effects only */ - def foreach(f: Type => Unit) - - /** Returns optionally first type (in a preorder traversal) which satisfies predicate `p`, - * or None if none exists. - */ - def find(p: Type => Boolean): Option[Type] - - /** Is there part of this type which satisfies predicate `p`? */ - def exists(p: Type => Boolean): Boolean - - /** Does this type contain a reference to given symbol? */ - def contains(sym: Symbol): Boolean - - /** If this is a compound type, the list of its parent types; - * otherwise the empty list - */ - def parents: List[Type] - - /** If this is a singleton type, returns the type underlying it; - * otherwise returns this type itself. - */ - def underlying: Type + def erasure: Type /** If this is a singleton type, widen it to its nearest underlying non-singleton * base type by applying one or more `underlying` dereferences. @@ -186,6 +126,36 @@ trait Types extends base.Types { self: Universe => */ def narrow: Type + /******************* helpers *******************/ + + /** Substitute symbols in `to` for corresponding occurrences of references to + * symbols `from` in this type. + */ + def substituteSymbols(from: List[Symbol], to: List[Symbol]): Type + + /** Substitute types in `to` for corresponding occurrences of references to + * symbols `from` in this type. + */ + def substituteTypes(from: List[Symbol], to: List[Type]): Type + + /** Apply `f` to each part of this type, returning + * a new type. children get mapped before their parents */ + def map(f: Type => Type): Type + + /** Apply `f` to each part of this type, for side effects only */ + def foreach(f: Type => Unit) + + /** Returns optionally first type (in a preorder traversal) which satisfies predicate `p`, + * or None if none exists. + */ + def find(p: Type => Boolean): Option[Type] + + /** Is there part of this type which satisfies predicate `p`? */ + def exists(p: Type => Boolean): Boolean + + /** Does this type contain a reference to given symbol? */ + def contains(sym: Symbol): Boolean + /** The string discriminator of this type; useful for debugging */ def kind: String } diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 8cf20ba062..68144da2d7 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2486,6 +2486,29 @@ trait Symbols extends api.Symbols { self: SymbolTable => mtpeResult = res res } + + override def allParams: List[List[Symbol]] = paramss + + override def params: List[Symbol] = { + def loop(tpe: Type): List[Symbol] = + tpe match { + case NullaryMethodType(_) => Nil + case MethodType(params, _) => params + case PolyType(_, tpe) => loop(tpe) + } + loop(info) + } + + override def resultType: Type = { + def loop(tpe: Type): Type = + tpe match { + case NullaryMethodType(ret) => loop(ret) + case MethodType(_, ret) => loop(ret) + case PolyType(_, tpe) => loop(tpe) + case tpe => tpe + } + loop(info) + } } implicit val MethodSymbolTag = ClassTag[MethodSymbol](classOf[MethodSymbol]) diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 1386cca42f..442a91774d 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -323,6 +323,7 @@ trait Types extends api.Types { self: SymbolTable => /** Is this type higher-kinded, i.e., is it a type constructor @M */ def isHigherKinded: Boolean = false + def takesTypeArgs: Boolean = this.isHigherKinded /** Does this type denote a stable reference (i.e. singleton type)? */ def isStable: Boolean = false diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index 6a3501b1dd..525673fe6d 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -110,6 +110,9 @@ trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => trait SynchronizedMethodSymbol extends MethodSymbol with SynchronizedTermSymbol { override def typeAsMemberOf(pre: Type): Type = synchronized { super.typeAsMemberOf(pre) } + override def allParams: List[List[Symbol]] = synchronized { super.allParams } + override def params: List[Symbol] = synchronized { super.params } + override def resultType: Type = synchronized { super.resultType } } trait SynchronizedTypeSymbol extends TypeSymbol with SynchronizedSymbol { diff --git a/test/files/run/reflection-methodsymbol-allparams.check b/test/files/run/reflection-methodsymbol-allparams.check new file mode 100644 index 0000000000..11f349d52b --- /dev/null +++ b/test/files/run/reflection-methodsymbol-allparams.check @@ -0,0 +1,8 @@ +List() +List(List()) +List(List(value x)) +List(List(value x), List(value y)) +List() +List(List()) +List(List(value x)) +List(List(value x), List(value y)) diff --git a/test/files/run/reflection-methodsymbol-allparams.scala b/test/files/run/reflection-methodsymbol-allparams.scala new file mode 100644 index 0000000000..cfd14f56a5 --- /dev/null +++ b/test/files/run/reflection-methodsymbol-allparams.scala @@ -0,0 +1,24 @@ +import scala.reflect.runtime.universe._ + +class C { + def x1: Int = ??? + def x2(): Int = ??? + def x3(x: Int): Int = ??? + def x4(x: Int)(y: Int): Int = ??? + + def y1[T]: Int = ??? + def y2[T](): Int = ??? + def y3[T](x: Int): Int = ??? + def y4[T](x: Int)(y: Int): Int = ??? +} + +object Test extends App { + println(typeOf[C].member(newTermName("x1")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("x2")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("x3")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("x4")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("y1")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("y2")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("y3")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("y4")).asMethodSymbol.allParams) +} \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-params.check b/test/files/run/reflection-methodsymbol-params.check new file mode 100644 index 0000000000..899ae15a0c --- /dev/null +++ b/test/files/run/reflection-methodsymbol-params.check @@ -0,0 +1,8 @@ +List() +List() +List(value x) +List(value x) +List() +List() +List(value x) +List(value x) diff --git a/test/files/run/reflection-methodsymbol-params.scala b/test/files/run/reflection-methodsymbol-params.scala new file mode 100644 index 0000000000..654a16b59d --- /dev/null +++ b/test/files/run/reflection-methodsymbol-params.scala @@ -0,0 +1,24 @@ +import scala.reflect.runtime.universe._ + +class C { + def x1: Int = ??? + def x2(): Int = ??? + def x3(x: Int): Int = ??? + def x4(x: Int)(y: Int): Int = ??? + + def y1[T]: Int = ??? + def y2[T](): Int = ??? + def y3[T](x: Int): Int = ??? + def y4[T](x: Int)(y: Int): Int = ??? +} + +object Test extends App { + println(typeOf[C].member(newTermName("x1")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("x2")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("x3")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("x4")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("y1")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("y2")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("y3")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("y4")).asMethodSymbol.params) +} \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-resulttype.check b/test/files/run/reflection-methodsymbol-resulttype.check new file mode 100644 index 0000000000..0f30d1beaf --- /dev/null +++ b/test/files/run/reflection-methodsymbol-resulttype.check @@ -0,0 +1,8 @@ +Int +Int +Int +Int +Int +Int +Int +Int diff --git a/test/files/run/reflection-methodsymbol-resulttype.scala b/test/files/run/reflection-methodsymbol-resulttype.scala new file mode 100644 index 0000000000..7a9f66dda8 --- /dev/null +++ b/test/files/run/reflection-methodsymbol-resulttype.scala @@ -0,0 +1,24 @@ +import scala.reflect.runtime.universe._ + +class C { + def x1: Int = ??? + def x2(): Int = ??? + def x3(x: Int): Int = ??? + def x4(x: Int)(y: Int): Int = ??? + + def y1[T]: Int = ??? + def y2[T](): Int = ??? + def y3[T](x: Int): Int = ??? + def y4[T](x: Int)(y: Int): Int = ??? +} + +object Test extends App { + println(typeOf[C].member(newTermName("x1")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("x2")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("x3")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("x4")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("y1")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("y2")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("y3")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("y4")).asMethodSymbol.resultType) +} \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-typeparams.check b/test/files/run/reflection-methodsymbol-typeparams.check new file mode 100644 index 0000000000..c888e09a17 --- /dev/null +++ b/test/files/run/reflection-methodsymbol-typeparams.check @@ -0,0 +1,8 @@ +List() +List() +List() +List() +List(type T) +List(type T) +List(type T) +List(type T) diff --git a/test/files/run/reflection-methodsymbol-typeparams.scala b/test/files/run/reflection-methodsymbol-typeparams.scala new file mode 100644 index 0000000000..28f1c8973d --- /dev/null +++ b/test/files/run/reflection-methodsymbol-typeparams.scala @@ -0,0 +1,24 @@ +import scala.reflect.runtime.universe._ + +class C { + def x1: Int = ??? + def x2(): Int = ??? + def x3(x: Int): Int = ??? + def x4(x: Int)(y: Int): Int = ??? + + def y1[T]: Int = ??? + def y2[T](): Int = ??? + def y3[T](x: Int): Int = ??? + def y4[T](x: Int)(y: Int): Int = ??? +} + +object Test extends App { + println(typeOf[C].member(newTermName("x1")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("x2")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("x3")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("x4")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("y1")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("y2")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("y3")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("y4")).asMethodSymbol.typeParams) +} \ No newline at end of file -- cgit v1.2.3 From 013acf6eb0117ca12ab2a0d0e8560df40a7392a3 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 30 Jul 2012 21:14:42 +0200 Subject: renames asType to toType and asXXXSymbol to asXXX This renaming arguably makes the intent of `asType` more clear, but more importantly it shaves 6 symbols off pervasive casts that are required to anything meaningful with reflection API (as in mirror.reflectMethod(tpe.member(newTermName("x")).asMethodSymbol)). --- .../scala/reflect/makro/runtime/ExprUtils.scala | 2 +- .../scala/reflect/makro/runtime/Typers.scala | 2 +- .../scala/reflect/reify/codegen/GenSymbols.scala | 2 +- .../scala/reflect/reify/codegen/GenTypes.scala | 8 ++-- src/compiler/scala/reflect/reify/package.scala | 4 +- .../scala/reflect/reify/utils/Extractors.scala | 2 +- .../scala/tools/nsc/typechecker/Tags.scala | 2 +- .../scala/tools/nsc/typechecker/Typers.scala | 2 +- src/compiler/scala/tools/reflect/StdTags.scala | 4 +- .../scala/tools/reflect/ToolBoxFactory.scala | 4 +- src/library/scala/reflect/base/Base.scala | 12 +++-- src/library/scala/reflect/base/Symbols.scala | 54 ++++++++++++++-------- src/reflect/scala/reflect/api/Mirrors.scala | 10 ++-- src/reflect/scala/reflect/api/Symbols.scala | 18 -------- src/reflect/scala/reflect/api/TagInterop.scala | 4 +- .../scala/reflect/internal/BuildUtils.scala | 8 ++-- .../scala/reflect/internal/Definitions.scala | 42 ++++++++--------- src/reflect/scala/reflect/internal/StdNames.scala | 12 ++--- src/reflect/scala/reflect/internal/Symbols.scala | 6 +-- src/reflect/scala/reflect/internal/Trees.scala | 6 +-- .../scala/reflect/runtime/JavaMirrors.scala | 29 ++++++------ test/files/run/compiler-asSeenFrom.scala | 18 ++++---- .../Macros_Test_2.scala | 2 +- .../run/macro-sip19-revised/Impls_Macros_1.scala | 2 +- .../run/macro-typecheck-macrosdisabled2.check | 2 +- ...eflection-constructormirror-inner-badpath.scala | 2 +- .../reflection-constructormirror-inner-good.scala | 2 +- ...flection-constructormirror-nested-badpath.scala | 2 +- .../reflection-constructormirror-nested-good.scala | 2 +- ...ection-constructormirror-toplevel-badpath.scala | 2 +- ...eflection-constructormirror-toplevel-good.scala | 2 +- test/files/run/reflection-equality.check | 2 +- test/files/run/reflection-equality.scala | 2 +- .../reflection-fieldmirror-accessorsareokay.scala | 6 +-- .../run/reflection-fieldmirror-ctorparam.scala | 2 +- .../run/reflection-fieldmirror-getsetval.scala | 2 +- .../run/reflection-fieldmirror-getsetvar.scala | 2 +- ...flection-fieldmirror-nmelocalsuffixstring.scala | 2 +- .../run/reflection-fieldmirror-privatethis.scala | 2 +- .../run/reflection-methodsymbol-allparams.scala | 16 +++---- .../files/run/reflection-methodsymbol-params.scala | 16 +++---- .../run/reflection-methodsymbol-resulttype.scala | 16 +++---- .../run/reflection-methodsymbol-typeparams.scala | 16 +++---- test/files/run/reflection-sanitychecks.scala | 8 ++-- .../run/toolbox_typecheck_macrosdisabled2.check | 2 +- 45 files changed, 182 insertions(+), 181 deletions(-) (limited to 'test/files') diff --git a/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala b/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala index e301dfc2a4..c89606289f 100644 --- a/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala +++ b/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala @@ -29,7 +29,7 @@ trait ExprUtils { def literal(x: Double) = Expr[Double](Literal(Constant(x)))(TypeTag.Double) - def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.asTypeConstructor)) + def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.toTypeConstructor)) def literal(x: Char) = Expr[Char](Literal(Constant(x)))(TypeTag.Char) } diff --git a/src/compiler/scala/reflect/makro/runtime/Typers.scala b/src/compiler/scala/reflect/makro/runtime/Typers.scala index e43b0459ea..7e92c1e9ca 100644 --- a/src/compiler/scala/reflect/makro/runtime/Typers.scala +++ b/src/compiler/scala/reflect/makro/runtime/Typers.scala @@ -37,7 +37,7 @@ trait Typers { def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s".format(from, to, tree, !withMacrosDisabled)) - val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).asTypeConstructor, List(from, to)) + val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).toTypeConstructor, List(from, to)) inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) } diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala index 38c8fedac5..59651bcdf9 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala @@ -36,7 +36,7 @@ trait GenSymbols { else if (sym.isEmptyPackageClass) mirrorMirrorSelect(nme.EmptyPackageClass) else if (sym.isModuleClass) - Select(Select(reify(sym.sourceModule), nme.asModuleSymbol), nme.moduleClass) + Select(Select(reify(sym.sourceModule), nme.asModule), nme.moduleClass) else if (sym.isPackage) mirrorMirrorCall(nme.staticPackage, reify(sym.fullName)) else if (sym.isLocatable) { diff --git a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala index c49e5b3342..c762a28f99 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala @@ -30,7 +30,7 @@ trait GenTypes { val tsym = tpe.typeSymbolDirect if (tsym.isClass && tpe == tsym.typeConstructor && tsym.isStatic) - Select(Select(reify(tsym), nme.asTypeSymbol), nme.asTypeConstructor) + Select(Select(reify(tsym), nme.asType), nme.toTypeConstructor) else tpe match { case tpe @ NoType => reifyMirrorObject(tpe) @@ -42,7 +42,7 @@ trait GenTypes { mirrorBuildCall(nme.thisPrefix, mirrorMirrorSelect(nme.EmptyPackageClass)) case tpe @ ThisType(clazz) if clazz.isModuleClass && clazz.isStatic => val module = reify(clazz.sourceModule) - val moduleClass = Select(Select(module, nme.asModuleSymbol), nme.moduleClass) + val moduleClass = Select(Select(module, nme.asModule), nme.moduleClass) mirrorFactoryCall(nme.ThisType, moduleClass) case tpe @ ThisType(_) => reifyProduct(tpe) @@ -94,7 +94,7 @@ trait GenTypes { } case success => if (reifyDebug) println("implicit search has produced a result: " + success) - state.reificationIsConcrete &= concrete || success.tpe <:< TypeTagClass.asTypeConstructor + state.reificationIsConcrete &= concrete || success.tpe <:< TypeTagClass.toTypeConstructor Select(Apply(Select(success, nme.in), List(Ident(nme.MIRROR_SHORT))), nme.tpe) } if (result != EmptyTree) return result @@ -109,7 +109,7 @@ trait GenTypes { def searchForManifest(typer: analyzer.Typer): Tree = analyzer.inferImplicit( EmptyTree, - appliedType(FullManifestClass.asTypeConstructor, List(tpe)), + appliedType(FullManifestClass.toTypeConstructor, List(tpe)), reportAmbiguous = false, isView = false, context = typer.context, diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala index 80011368a8..e4cf451643 100644 --- a/src/compiler/scala/reflect/reify/package.scala +++ b/src/compiler/scala/reflect/reify/package.scala @@ -29,7 +29,7 @@ package object reify { import definitions._ val enclosingErasure = reifyEnclosingRuntimeClass(global)(typer0) // JavaUniverse is defined in scala-reflect.jar, so we must be very careful in case someone reifies stuff having only scala-library.jar on the classpath - val isJavaUniverse = JavaUniverseClass != NoSymbol && universe.tpe <:< JavaUniverseClass.asTypeConstructor + val isJavaUniverse = JavaUniverseClass != NoSymbol && universe.tpe <:< JavaUniverseClass.toTypeConstructor if (isJavaUniverse && !enclosingErasure.isEmpty) Apply(Select(universe, nme.runtimeMirror), List(Select(enclosingErasure, sn.GetClassLoader))) else Select(universe, nme.rootMirror) } @@ -69,7 +69,7 @@ package object reify { if (isThisInScope) { val enclosingClasses = typer0.context.enclosingContextChain map (_.tree) collect { case classDef: ClassDef => classDef } val classInScope = enclosingClasses.headOption getOrElse EmptyTree - if (!classInScope.isEmpty) reifyRuntimeClass(global)(typer0, classInScope.symbol.asTypeConstructor, concrete = true) + if (!classInScope.isEmpty) reifyRuntimeClass(global)(typer0, classInScope.symbol.toTypeConstructor, concrete = true) else Select(This(tpnme.EMPTY), sn.GetClass) } else EmptyTree } diff --git a/src/compiler/scala/reflect/reify/utils/Extractors.scala b/src/compiler/scala/reflect/reify/utils/Extractors.scala index 86265ec77a..7352b2cbd5 100644 --- a/src/compiler/scala/reflect/reify/utils/Extractors.scala +++ b/src/compiler/scala/reflect/reify/utils/Extractors.scala @@ -40,7 +40,7 @@ trait Extractors { // def apply[U >: Nothing <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Type = { // val $u: U = $m$untyped.universe; // val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - // $u.TypeRef($u.ThisType($m.staticPackage("scala.collection.immutable").moduleClass), $m.staticClass("scala.collection.immutable.List"), List($m.staticClass("scala.Int").asTypeConstructor)) + // $u.TypeRef($u.ThisType($m.staticPackage("scala.collection.immutable").moduleClass), $m.staticClass("scala.collection.immutable.List"), List($m.staticClass("scala.Int").toTypeConstructor)) // } // }; // new $typecreator1() diff --git a/src/compiler/scala/tools/nsc/typechecker/Tags.scala b/src/compiler/scala/tools/nsc/typechecker/Tags.scala index 052484e8e1..f82e009be8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Tags.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Tags.scala @@ -61,7 +61,7 @@ trait Tags { */ def resolveTypeTag(pos: Position, pre: Type, tp: Type, concrete: Boolean, allowMaterialization: Boolean = true): Tree = { val tagSym = if (concrete) TypeTagClass else AbsTypeTagClass - val tagTp = if (pre == NoType) TypeRef(BaseUniverseClass.asTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name) + val tagTp = if (pre == NoType) TypeRef(BaseUniverseClass.toTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name) val taggedTp = appliedType(tagTp, List(tp)) resolveTag(pos, taggedTp, allowMaterialization) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e57cae00e0..b06ea639b0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5089,7 +5089,7 @@ trait Typers extends Modes with Adaptations with Tags { // convert new Array^N[T](len) for N > 1 to evidence[ClassTag[Array[...Array[T]...]]].newArray(len), where Array HK gets applied (N-1) times // [Eugene] no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions) val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe) - val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.asType, List(tpe))).last + val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.toTypeConstructor, List(tpe))).last val newArrayApp = atPos(tree.pos) { val tag = resolveClassTag(tree.pos, tagType) if (tag.isEmpty) MissingClassTagError(tree, tagType) diff --git a/src/compiler/scala/tools/reflect/StdTags.scala b/src/compiler/scala/tools/reflect/StdTags.scala index 25a42a82cd..30bded4f86 100644 --- a/src/compiler/scala/tools/reflect/StdTags.scala +++ b/src/compiler/scala/tools/reflect/StdTags.scala @@ -20,7 +20,7 @@ trait StdTags { def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = { val u = m.universe val pre = u.ThisType(m.staticPackage("scala.collection.immutable").moduleClass.asInstanceOf[u.Symbol]) - u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.asTypeConstructor)) + u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.toTypeConstructor)) } }) @@ -29,7 +29,7 @@ trait StdTags { m, new TypeCreator { def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = - m.staticClass(classTag[T].runtimeClass.getName).asTypeConstructor.asInstanceOf[U # Type] + m.staticClass(classTag[T].runtimeClass.getName).toTypeConstructor.asInstanceOf[U # Type] }) lazy val tagOfInt = u.TypeTag.Int lazy val tagOfString = tagOfStaticClass[String] diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index 6c48762200..9987931cf3 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -85,7 +85,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => if (tree.hasSymbol && tree.symbol.isFreeTerm) { tree match { case Ident(_) => - val freeTermRef = Ident(freeTermNames(tree.symbol.asFreeTermSymbol)) + val freeTermRef = Ident(freeTermNames(tree.symbol.asFreeTerm)) if (wrapFreeTermRefs) Apply(freeTermRef, List()) else freeTermRef case _ => throw new Error("internal error: %s (%s, %s) is not supported".format(tree, tree.productPrefix, tree.getClass)) @@ -350,7 +350,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => } def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree = { - val viewTpe = u.appliedType(u.definitions.FunctionClass(1).asTypeConstructor, List(from, to)) + val viewTpe = u.appliedType(u.definitions.FunctionClass(1).toTypeConstructor, List(from, to)) inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) } diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala index 6d13395019..385dc6275f 100644 --- a/src/library/scala/reflect/base/Base.scala +++ b/src/library/scala/reflect/base/Base.scala @@ -62,7 +62,9 @@ class Base extends Universe { self => class TypeSymbol(val owner: Symbol, override val name: TypeName, flags: FlagSet) extends Symbol(name, flags) with TypeSymbolBase { - override val asTypeConstructor = TypeRef(ThisType(owner), this, Nil) + override def toTypeConstructor = TypeRef(ThisType(owner), this, Nil) + override def toType = TypeRef(ThisType(owner), this, Nil) + override def toTypeIn(site: Type) = TypeRef(ThisType(owner), this, Nil) } implicit val TypeSymbolTag = ClassTag[TypeSymbol](classOf[TypeSymbol]) @@ -295,16 +297,16 @@ class Base extends Universe { self => object build extends BuildBase { def selectType(owner: Symbol, name: String): TypeSymbol = { val clazz = new ClassSymbol(owner, newTypeName(name), NoFlags) - cached(clazz.fullName)(clazz).asTypeSymbol + cached(clazz.fullName)(clazz).asType } def selectTerm(owner: Symbol, name: String): TermSymbol = { val valu = new MethodSymbol(owner, newTermName(name), NoFlags) - cached(valu.fullName)(valu).asTermSymbol + cached(valu.fullName)(valu).asTerm } def selectOverloadedMethod(owner: Symbol, name: String, index: Int): MethodSymbol = - selectTerm(owner, name).asMethodSymbol + selectTerm(owner, name).asMethod def newNestedSymbol(owner: Symbol, name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol = if (name.isTypeName) @@ -384,7 +386,7 @@ class Base extends Universe { self => object definitions extends DefinitionsBase { lazy val ScalaPackage = staticModule("scala") - lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClassSymbol + lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClass lazy val AnyClass = staticClass("scala.Any") lazy val AnyValClass = staticClass("scala.Any") diff --git a/src/library/scala/reflect/base/Symbols.scala b/src/library/scala/reflect/base/Symbols.scala index ced1f33395..052571dbcb 100644 --- a/src/library/scala/reflect/base/Symbols.scala +++ b/src/library/scala/reflect/base/Symbols.scala @@ -134,7 +134,7 @@ trait Symbols { self: Universe => /** This symbol cast to a TypeSymbol. * Returns ClassCastException if `isType` is false. */ - def asTypeSymbol: TypeSymbol = throw new ClassCastException(toString) + def asType: TypeSymbol = throw new ClassCastException(toString) /** Does this symbol represent the definition of a term? * Note that every symbol is either a term or a term. @@ -146,7 +146,7 @@ trait Symbols { self: Universe => /** This symbol cast to a TermSymbol. * Returns ClassCastException if `isTerm` is false. */ - def asTermSymbol: TermSymbol = throw new ClassCastException(toString) + def asTerm: TermSymbol = throw new ClassCastException(toString) /** Does this symbol represent the definition of a method? * If yes, `isTerm` is also guaranteed to be true. @@ -156,7 +156,7 @@ trait Symbols { self: Universe => /** This symbol cast to a MethodSymbol. * Returns ClassCastException if `isMethod` is false. */ - def asMethodSymbol: MethodSymbol = throw new ClassCastException(toString) + def asMethod: MethodSymbol = throw new ClassCastException(toString) /** Does this symbol represent the definition of a module (i.e. it * results from an object definition?). @@ -167,7 +167,7 @@ trait Symbols { self: Universe => /** This symbol cast to a ModuleSymbol defined by an object definition. * Returns ClassCastException if `isModule` is false. */ - def asModuleSymbol: ModuleSymbol = throw new ClassCastException(toString) + def asModule: ModuleSymbol = throw new ClassCastException(toString) /** Does this symbol represent the definition of a class or trait? * If yes, `isType` is also guaranteed to be true. @@ -183,7 +183,7 @@ trait Symbols { self: Universe => /** This symbol cast to a ClassSymbol representing a class or trait. * Returns ClassCastException if `isClass` is false. */ - def asClassSymbol: ClassSymbol = throw new ClassCastException(toString) + def asClass: ClassSymbol = throw new ClassCastException(toString) /** Does this symbol represent a free term captured by reification? * If yes, `isTerm` is also guaranteed to be true. @@ -193,7 +193,7 @@ trait Symbols { self: Universe => /** This symbol cast to a free term symbol. * Returns ClassCastException if `isFreeTerm` is false. */ - def asFreeTermSymbol: FreeTermSymbol = throw new ClassCastException(toString) + def asFreeTerm: FreeTermSymbol = throw new ClassCastException(toString) /** Does this symbol represent a free type captured by reification? * If yes, `isType` is also guaranteed to be true. @@ -203,7 +203,7 @@ trait Symbols { self: Universe => /** This symbol cast to a free type symbol. * Returns ClassCastException if `isFreeType` is false. */ - def asFreeTypeSymbol: FreeTypeSymbol = throw new ClassCastException(toString) + def asFreeType: FreeTypeSymbol = throw new ClassCastException(toString) def newTermSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol def newModuleAndClassSymbol(name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol) @@ -219,16 +219,34 @@ trait Symbols { self: Universe => final type NameType = TypeName /** The type constructor corresponding to this type symbol. - * This is different from `asType` in that type parameters - * are part of results of `asType`, but not of `asTypeConstructor`. + * This is different from `toType` in that type parameters + * are part of results of `toType`, but not of `toTypeConstructor`. * * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol - * `C`. Then `C.asType` is the type `C[T]`, but `C.asTypeConstructor` is `C`. + * `C`. Then `C.toType` is the type `C[T]`, but `C.toTypeConstructor` is `C`. */ - def asTypeConstructor: Type + def toTypeConstructor: Type + + /** A type reference that refers to this type symbol seen + * as a member of given type `site`. + */ + def toTypeIn(site: Type): Type + + /** A type reference that refers to this type symbol + * Note if symbol is a member of a class, one almost always is interested + * in `asTypeIn` with a site type instead. + * + * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol + * `C`. Then `C.toType` is the type `C[T]`. + * + * By contrast, `C.typeSignature` would be a type signature of form + * `PolyType(ClassInfoType(...))` that describes type parameters, value + * parameters, parent types, and members of `C`. + */ + def toType: Type override def isType = true - override def asTypeSymbol = this + override def asType = this } /** The base API that all term symbols support */ @@ -238,13 +256,13 @@ trait Symbols { self: Universe => final type NameType = TermName final override def isTerm = true - final override def asTermSymbol = this + final override def asTerm = this } /** The base API that all method symbols support */ trait MethodSymbolBase extends TermSymbolBase { this: MethodSymbol => final override def isMethod = true - final override def asMethodSymbol = this + final override def asMethod = this } /** The base API that all module symbols support */ @@ -257,24 +275,24 @@ trait Symbols { self: Universe => // [Eugene++] when this becomes `moduleClass: ClassSymbol`, it will be the happiest day in my life final override def isModule = true - final override def asModuleSymbol = this + final override def asModule = this } /** The base API that all class symbols support */ trait ClassSymbolBase extends TypeSymbolBase { this: ClassSymbol => final override def isClass = true - final override def asClassSymbol = this + final override def asClass = this } /** The base API that all free type symbols support */ trait FreeTypeSymbolBase extends TypeSymbolBase { this: FreeTypeSymbol => final override def isFreeType = true - final override def asFreeTypeSymbol = this + final override def asFreeType = this } /** The base API that all free term symbols support */ trait FreeTermSymbolBase extends TermSymbolBase { this: FreeTermSymbol => final override def isFreeTerm = true - final override def asFreeTermSymbol = this + final override def asFreeTerm = this } } diff --git a/src/reflect/scala/reflect/api/Mirrors.scala b/src/reflect/scala/reflect/api/Mirrors.scala index fe4348d568..a4d86cf1fd 100644 --- a/src/reflect/scala/reflect/api/Mirrors.scala +++ b/src/reflect/scala/reflect/api/Mirrors.scala @@ -34,7 +34,7 @@ trait Mirrors { self: Universe => * that can be used to get and, if appropriate, set the value of the field. * * To get a field symbol by the name of the field you would like to reflect, - * use `.symbol.typeSignature.member(newTermName()).asTermSymbol.accessed`. + * use `.symbol.typeSignature.member(newTermName()).asTerm.accessed`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -54,7 +54,7 @@ trait Mirrors { self: Universe => * that can be used to invoke the method provided. * * To get a method symbol by the name of the method you would like to reflect, - * use `.symbol.typeSignature.member(newTermName()).asMethodSymbol`. + * use `.symbol.typeSignature.member(newTermName()).asMethod`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -66,7 +66,7 @@ trait Mirrors { self: Universe => * that can be used to create instances of the class, inspect its companion object or perform further reflections. * * To get a class symbol by the name of the class you would like to reflect, - * use `.symbol.typeSignature.member(newTypeName()).asClassSymbol`. + * use `.symbol.typeSignature.member(newTypeName()).asClass`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -78,7 +78,7 @@ trait Mirrors { self: Universe => * that can be used to get the instance of the object or inspect its companion class. * * To get a module symbol by the name of the object you would like to reflect, - * use `.symbol.typeSignature.member(newTermName()).asModuleSymbol`. + * use `.symbol.typeSignature.member(newTermName()).asModule`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -201,7 +201,7 @@ trait Mirrors { self: Universe => * that can be used to invoke it and construct instances of this mirror's symbols. * * To get a constructor symbol you would like to reflect, - * use `.symbol.typeSignature.member(nme.CONSTRUCTOR).asMethodSymbol`. + * use `.symbol.typeSignature.member(nme.CONSTRUCTOR).asMethod`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala index cd9044c934..e55c1ea11a 100644 --- a/src/reflect/scala/reflect/api/Symbols.scala +++ b/src/reflect/scala/reflect/api/Symbols.scala @@ -236,24 +236,6 @@ trait Symbols extends base.Symbols { self: Universe => /** Does this symbol represent an existentially bound type? */ def isExistential : Boolean - - /** A type reference that refers to this type symbol seen - * as a member of given type `site`. - */ - def asTypeIn(site: Type): Type - - /** A type reference that refers to this type symbol - * Note if symbol is a member of a class, one almost always is interested - * in `asTypeIn` with a site type instead. - * - * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol - * `C`. Then `C.asType` is the type `C[T]`. - * - * By contrast, `C.typeSignature` would be a type signature of form - * `PolyType(ClassInfoType(...))` that describes type parameters, value - * parameters, parent types, and members of `C`. - */ - def asType: Type // !!! Same as typeSignature. } /** The API of method symbols */ diff --git a/src/reflect/scala/reflect/api/TagInterop.scala b/src/reflect/scala/reflect/api/TagInterop.scala index f1938083b5..4d2254cb9f 100644 --- a/src/reflect/scala/reflect/api/TagInterop.scala +++ b/src/reflect/scala/reflect/api/TagInterop.scala @@ -27,8 +27,8 @@ trait TagInterop { self: JavaUniverse => val jm = mirror.asInstanceOf[ju.Mirror] val sym = jm.classSymbol(manifest.erasure) val tpe = - if (manifest.typeArguments.isEmpty) sym.asType - else ju.appliedType(sym.asTypeConstructor, manifest.typeArguments map (targ => ju.manifestToTypeTag(jm, targ)) map (_.in(jm).tpe)) + if (manifest.typeArguments.isEmpty) sym.toType + else ju.appliedType(sym.toTypeConstructor, manifest.typeArguments map (targ => ju.manifestToTypeTag(jm, targ)) map (_.in(jm).tpe)) tpe.asInstanceOf[U # Type] case u => u.manifestToTypeTag(mirror.asInstanceOf[u.Mirror], manifest).in(mirror).tpe diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala index ad59605760..74b9442076 100644 --- a/src/reflect/scala/reflect/internal/BuildUtils.scala +++ b/src/reflect/scala/reflect/internal/BuildUtils.scala @@ -8,11 +8,11 @@ trait BuildUtils extends base.BuildUtils { self: SymbolTable => class BuildImpl extends BuildBase { def selectType(owner: Symbol, name: String): TypeSymbol = - select(owner, newTypeName(name)).asTypeSymbol + select(owner, newTypeName(name)).asType def selectTerm(owner: Symbol, name: String): TermSymbol = { - val result = select(owner, newTermName(name)).asTermSymbol - if (result.isOverloaded) result.suchThat(!_.isMethod).asTermSymbol + val result = select(owner, newTermName(name)).asTerm + if (result.isOverloaded) result.suchThat(!_.isMethod).asTerm else result } @@ -26,7 +26,7 @@ trait BuildUtils extends base.BuildUtils { self: SymbolTable => def selectOverloadedMethod(owner: Symbol, name: String, index: Int): MethodSymbol = { val result = owner.info.decl(newTermName(name)).alternatives(index) - if (result ne NoSymbol) result.asMethodSymbol + if (result ne NoSymbol) result.asMethod else MissingRequirementError.notFound("overloaded method %s #%d in %s".format(name, index, owner.fullName)) } diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 90aa0b732c..7248fac5fb 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -20,21 +20,21 @@ trait Definitions extends api.StandardDefinitions { object definitions extends DefinitionsClass // [Eugene] find a way to make these non-lazy - lazy val ByteTpe = definitions.ByteClass.asType - lazy val ShortTpe = definitions.ShortClass.asType - lazy val CharTpe = definitions.CharClass.asType - lazy val IntTpe = definitions.IntClass.asType - lazy val LongTpe = definitions.LongClass.asType - lazy val FloatTpe = definitions.FloatClass.asType - lazy val DoubleTpe = definitions.DoubleClass.asType - lazy val BooleanTpe = definitions.BooleanClass.asType - lazy val UnitTpe = definitions.UnitClass.asType - lazy val AnyTpe = definitions.AnyClass.asType - lazy val ObjectTpe = definitions.ObjectClass.asType - lazy val AnyValTpe = definitions.AnyValClass.asType - lazy val AnyRefTpe = definitions.AnyRefClass.asType - lazy val NothingTpe = definitions.NothingClass.asType - lazy val NullTpe = definitions.NullClass.asType + lazy val ByteTpe = definitions.ByteClass.toTypeConstructor + lazy val ShortTpe = definitions.ShortClass.toTypeConstructor + lazy val CharTpe = definitions.CharClass.toTypeConstructor + lazy val IntTpe = definitions.IntClass.toTypeConstructor + lazy val LongTpe = definitions.LongClass.toTypeConstructor + lazy val FloatTpe = definitions.FloatClass.toTypeConstructor + lazy val DoubleTpe = definitions.DoubleClass.toTypeConstructor + lazy val BooleanTpe = definitions.BooleanClass.toTypeConstructor + lazy val UnitTpe = definitions.UnitClass.toTypeConstructor + lazy val AnyTpe = definitions.AnyClass.toTypeConstructor + lazy val ObjectTpe = definitions.ObjectClass.toTypeConstructor + lazy val AnyValTpe = definitions.AnyValClass.toTypeConstructor + lazy val AnyRefTpe = definitions.AnyRefClass.toTypeConstructor + lazy val NothingTpe = definitions.NothingClass.toTypeConstructor + lazy val NullTpe = definitions.NullClass.toTypeConstructor /** Since both the value parameter types and the result type may * require access to the type parameter symbols, we model polymorphic @@ -183,11 +183,11 @@ trait Definitions extends api.StandardDefinitions { // It becomes tricky to create dedicated objects for other symbols because // of initialization order issues. lazy val JavaLangPackage = getRequiredPackage(sn.JavaLang) - lazy val JavaLangPackageClass = JavaLangPackage.moduleClass.asClassSymbol + lazy val JavaLangPackageClass = JavaLangPackage.moduleClass.asClass lazy val ScalaPackage = getRequiredPackage(nme.scala_) - lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClassSymbol + lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClass lazy val RuntimePackage = getRequiredPackage("scala.runtime") - lazy val RuntimePackageClass = RuntimePackage.moduleClass.asClassSymbol + lazy val RuntimePackageClass = RuntimePackage.moduleClass.asClass lazy val JavaLangEnumClass = requiredClass[java.lang.Enum[_]] @@ -1045,7 +1045,7 @@ trait Definitions extends api.StandardDefinitions { // System.err.println("isMethod = " + result.isMethod) // System.err.println("isTerm = " + result.isTerm) // System.err.println("isValue = " + result.isValue) - // result.asMethodSymbol + // result.asMethod // // prints this: // @@ -1074,8 +1074,8 @@ trait Definitions extends api.StandardDefinitions { // [scalacfork] // [scalacfork] uncaught exception during compilation: java.lang.ClassCastException // [scalacfork] error: java.lang.ClassCastException: value apply - // [scalacfork] at scala.reflect.base.Symbols$SymbolBase$class.asMethodSymbol(Symbols.scala:118) - // [scalacfork] at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethodSymbol(Symbols.scala:63) + // [scalacfork] at scala.reflect.base.Symbols$SymbolBase$class.asMethod(Symbols.scala:118) + // [scalacfork] at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethod(Symbols.scala:63) // [scalacfork] at scala.reflect.internal.Definitions$DefinitionsClass.Symbol_apply(Definitions.scala:381) // [Eugene++] should be a ClassCastException instead? diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 75962ff9d0..133b035228 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -628,14 +628,13 @@ trait StdNames { val array_length : NameType = "array_length" val array_update : NameType = "array_update" val arraycopy: NameType = "arraycopy" - val asTermSymbol: NameType = "asTermSymbol" - val asModuleSymbol: NameType = "asModuleSymbol" - val asMethodSymbol: NameType = "asMethodSymbol" - val asTypeSymbol: NameType = "asTypeSymbol" - val asClassSymbol: NameType = "asClassSymbol" + val asTerm: NameType = "asTerm" + val asModule: NameType = "asModule" + val asMethod: NameType = "asMethod" + val asType: NameType = "asType" + val asClass: NameType = "asClass" val asInstanceOf_ : NameType = "asInstanceOf" val asInstanceOf_Ob : NameType = "$asInstanceOf" - val asTypeConstructor: NameType = "asTypeConstructor" val assert_ : NameType = "assert" val assume_ : NameType = "assume" val basis : NameType = "basis" @@ -767,6 +766,7 @@ trait StdNames { val toObjectArray : NameType = "toObjectArray" val toSeq: NameType = "toSeq" val toString_ : NameType = if (forMSIL) "ToString" else "toString" + val toTypeConstructor: NameType = "toTypeConstructor" val tpe : NameType = "tpe" val tree : NameType = "tree" val true_ : NameType = "true" diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 68144da2d7..372520e48f 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -75,9 +75,9 @@ trait Symbols extends api.Symbols { self: SymbolTable => def typeSignature: Type = info def typeSignatureIn(site: Type): Type = site memberInfo this - def asType: Type = tpe - def asTypeIn(site: Type): Type = site.memberType(this) - def asTypeConstructor: Type = typeConstructor + def toType: Type = tpe + def toTypeIn(site: Type): Type = site.memberType(this) + def toTypeConstructor: Type = typeConstructor def setFlags(flags: FlagSet): this.type = setInternalFlags(flags) def setInternalFlags(flag: Long): this.type = { setFlag(flag); this } def setTypeSignature(tpe: Type): this.type = { setInfo(tpe); this } diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 619e3bc170..ddc40b2e9f 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -1024,14 +1024,14 @@ trait Trees extends api.Trees { self: SymbolTable => } } - + /** Delegate for a TypeTree symbol. This operation is unsafe because * it may trigger type checking when forcing the type symbol of the * underlying type. */ protected def typeTreeSymbol(tree: TypeTree): Symbol = if (tree.tpe == null) null else tree.tpe.typeSymbol - + // --- generic traversers and transformers override protected def itraverse(traverser: Traverser, tree: Tree): Unit = { @@ -1266,7 +1266,7 @@ trait Trees extends api.Trees { self: SymbolTable => } } - private def mclass(sym: Symbol) = sym map (_.asModuleSymbol.moduleClass) + private def mclass(sym: Symbol) = sym map (_.asModule.moduleClass) // --- specific traversers and transformers diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 0878801715..6ae7e6d7eb 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -150,7 +150,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym def classSymbol(rtcls: RuntimeClass): ClassSymbol = classToScala(rtcls) - def moduleSymbol(rtcls: RuntimeClass): ModuleSymbol = classToScala(rtcls).companionModule.asModuleSymbol + def moduleSymbol(rtcls: RuntimeClass): ModuleSymbol = classToScala(rtcls).companionModule.asModule private def checkMemberOf(wannabe: Symbol, owner: Symbol) = if (!owner.info.member(wannabe.name).alternatives.contains(wannabe)) ErrorNotMember(wannabe, owner) @@ -166,7 +166,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym if (field.isGetter) nme.getterToLocal(field.name) else if (field.isSetter) nme.getterToLocal(nme.setterToGetter(field.name)) else field.name - val field1 = (field.owner.info decl name).asTermSymbol + val field1 = (field.owner.info decl name).asTerm try fieldToJava(field1) catch { case _: NoSuchFieldException => ErrorNonExistentField(field1) @@ -260,7 +260,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private class JavaModuleMirror(val outer: AnyRef, val symbol: ModuleSymbol) extends JavaTemplateMirror with ModuleMirror { - def erasure = symbol.moduleClass.asClassSymbol + def erasure = symbol.moduleClass.asClass def isStatic = true def instance = { if (!symbol.owner.isPackageClass) throw new Error("inner and nested modules are not supported yet") @@ -629,7 +629,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym val preOwner = classToScala(jOwner) val owner = followStatic(preOwner, jmeth.getModifiers) (lookup(owner, jmeth.getName) suchThat (erasesTo(_, jmeth)) orElse jmethodAsScala(jmeth)) - .asMethodSymbol + .asMethod } /** @@ -643,7 +643,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private def constructorToScala1(jconstr: jConstructor[_]): MethodSymbol = { val owner = followStatic(classToScala(jconstr.getDeclaringClass), jconstr.getModifiers) (lookup(owner, jconstr.getName) suchThat (erasesTo(_, jconstr)) orElse jconstrAsScala(jconstr)) - .asMethodSymbol + .asMethod } /** @@ -657,8 +657,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private def fieldToScala1(jfield: jField): TermSymbol = { val owner = followStatic(classToScala(jfield.getDeclaringClass), jfield.getModifiers) - (lookup(owner, jfield.getName) suchThat (!_.isMethod) orElse jfieldAsScala(jfield)) - .asTermSymbol + (lookup(owner, jfield.getName) suchThat (!_.isMethod) orElse jfieldAsScala(jfield)).asTerm } /** @@ -691,7 +690,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym val name = (fullname: TermName) drop split + 1 val opkg = owner.info decl name if (opkg.isPackage) - opkg.asModuleSymbol + opkg.asModule else if (opkg == NoSymbol) { val pkg = owner.newPackage(name) pkg.moduleClass setInfo new LazyPackageType @@ -758,7 +757,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym s"""${if (cls == NoSymbol) "not a type: symbol" else "no symbol could be"} | loaded from $jclazz in $owner with name $simpleName and classloader $classLoader""".stripMargin) - cls.asClassSymbol + cls.asClass } } @@ -773,7 +772,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private def typeParamToScala1(jparam: jTypeVariable[_ <: GenericDeclaration]): TypeSymbol = { val owner = genericDeclarationToScala(jparam.getGenericDeclaration) owner.info match { - case PolyType(tparams, _) => tparams.find(_.name.toString == jparam.getName).get.asTypeSymbol + case PolyType(tparams, _) => tparams.find(_.name.toString == jparam.getName).get.asType } } @@ -941,7 +940,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym else if (clazz.owner.isPackageClass) javaClass(clazz.javaClassName) else if (clazz.owner.isClass) - classToJava(clazz.owner.asClassSymbol) + classToJava(clazz.owner.asClass) .getDeclaredClasses .find(_.getSimpleName == clazz.name.toString) .getOrElse(noClass) @@ -957,7 +956,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym * @param meth The Scala field. */ def fieldToJava(fld: TermSymbol): jField = fieldCache.toJava(fld) { - val jclazz = classToJava(fld.owner.asClassSymbol) + val jclazz = classToJava(fld.owner.asClass) val jname = nme.dropLocalSuffix(fld.name).toString try jclazz getDeclaredField jname catch { @@ -969,7 +968,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym * @param meth The Scala method */ def methodToJava(meth: MethodSymbol): jMethod = methodCache.toJava(meth) { - val jclazz = classToJava(meth.owner.asClassSymbol) + val jclazz = classToJava(meth.owner.asClass) val paramClasses = transformedType(meth).paramTypes map typeToJavaClass val jname = nme.dropLocalSuffix(meth.name).toString try jclazz getDeclaredMethod (jname, paramClasses: _*) @@ -983,7 +982,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym * @param constr The Scala constructor */ def constructorToJava(constr: MethodSymbol): jConstructor[_] = constructorCache.toJava(constr) { - val jclazz = classToJava(constr.owner.asClassSymbol) + val jclazz = classToJava(constr.owner.asClass) val paramClasses = transformedType(constr).paramTypes map typeToJavaClass val effectiveParamClasses = if (!constr.owner.owner.isStaticOwner) jclazz.getEnclosingClass +: paramClasses @@ -1001,7 +1000,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym def typeToJavaClass(tpe: Type): jClass[_] = tpe match { case ExistentialType(_, rtpe) => typeToJavaClass(rtpe) case TypeRef(_, ArrayClass, List(elemtpe)) => jArrayClass(typeToJavaClass(elemtpe)) - case TypeRef(_, sym: ClassSymbol, _) => classToJava(sym.asClassSymbol) + case TypeRef(_, sym: ClassSymbol, _) => classToJava(sym.asClass) case tpe @ TypeRef(_, sym: AliasTypeSymbol, _) => typeToJavaClass(tpe.dealias) case _ => throw new NoClassDefFoundError("no Java class corresponding to "+tpe+" found") } diff --git a/test/files/run/compiler-asSeenFrom.scala b/test/files/run/compiler-asSeenFrom.scala index 1fc3a5ee71..19feb45101 100644 --- a/test/files/run/compiler-asSeenFrom.scala +++ b/test/files/run/compiler-asSeenFrom.scala @@ -47,10 +47,10 @@ package ll { for (p <- typeRefPrefixes ; c <- classes filter (isPossibleEnclosure(p.typeSymbol, _)) ; a <- targs) yield typeRef(p, c, List(a)) ) - + val wfmt = "%-" + 25 + "s" def to_s(x: Any): String = wfmt.format(x.toString.replaceAll("""\bll\.""", "")) - + def fmt(args: Any*): String = { (args map to_s mkString " ").replaceAll("""\s+$""", "") } @@ -61,7 +61,7 @@ package ll { } def permuteAsSeenFrom(targs: List[Type]) = ( - for { + for { tp <- typeRefs(targs filterNot (_ eq NoType)) prefix <- asSeenPrefixes if tp.prefix != prefix @@ -72,11 +72,11 @@ package ll { } yield ((site, tp, prefix, seen)) ) - + def block(label: Any)(lines: List[String]): List[String] = { val first = "" + label + " {" val last = "}" - + first +: lines.map(" " + _) :+ last } @@ -84,7 +84,7 @@ package ll { permuteAsSeenFrom(targs).groupBy(_._1).toList.sortBy(_._1.toString) flatMap { case (site, xs) => block(fmt(site)) { - fmt("type", "seen from prefix", "is") :: + fmt("type", "seen from prefix", "is") :: fmt("----", "----------------", "--") :: { xs.groupBy(_._2).toList.sortBy(_._1.toString) flatMap { case (tp, ys) => @@ -95,15 +95,15 @@ package ll { } } } - + def pretty(xs: List[_]) = if (xs.isEmpty) "" else xs.mkString("\n ", "\n ", "\n") def signaturesIn(info: Type): List[String] = ( - info.members + info.members.toList filterNot (s => s.isType || s.owner == ObjectClass || s.owner == AnyClass || s.isConstructor) map (_.defString) ) - + def check(source: String, unit: global.CompilationUnit) = { import syms._ diff --git a/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala b/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala index 32a8958577..7a2c0a6fa9 100644 --- a/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala +++ b/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala @@ -9,7 +9,7 @@ object Test extends App { import scala.tools.reflect.ToolBox val macrobody = Select(Ident(newTermName("Impls")), newTermName("foo")) - val macroparam = ValDef(NoMods, newTermName("x"), TypeTree(definitions.IntClass.asType), EmptyTree) + val macroparam = ValDef(NoMods, newTermName("x"), TypeTree(definitions.IntClass.toType), EmptyTree) val macrodef = DefDef(Modifiers(MACRO), newTermName("foo"), Nil, List(List(macroparam)), TypeTree(), macrobody) val modulector = DefDef(NoMods, nme.CONSTRUCTOR, Nil, List(List()), TypeTree(), Block(Apply(Select(Super(This(EmptyTypeName), EmptyTypeName), nme.CONSTRUCTOR), List()))) val module = ModuleDef(NoMods, newTermName("Macros"), Template(Nil, emptyValDef, List(modulector, macrodef))) 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 013130d181..05d3e036d9 100644 --- a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala @@ -4,7 +4,7 @@ object Macros { def impl(c: Context) = { import c.universe._ - val inscope = c.inferImplicitValue(c.mirror.staticClass("SourceLocation").asType) + val inscope = c.inferImplicitValue(c.mirror.staticClass("SourceLocation").toType) val outer = c.Expr[SourceLocation](if (!inscope.isEmpty) inscope else Literal(Constant(null))) val Apply(fun, args) = c.enclosingImplicits(0)._2 diff --git a/test/files/run/macro-typecheck-macrosdisabled2.check b/test/files/run/macro-typecheck-macrosdisabled2.check index 2160d3800a..908fb65bb3 100644 --- a/test/files/run/macro-typecheck-macrosdisabled2.check +++ b/test/files/run/macro-typecheck-macrosdisabled2.check @@ -28,7 +28,7 @@ def apply[U >: Nothing <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - $u.TypeRef.apply($u.ThisType.apply($m.staticPackage("scala").asModuleSymbol.moduleClass), $m.staticClass("scala.Array"), scala.collection.immutable.List.apply[$u.Type]($m.staticClass("scala.Int").asTypeSymbol.asTypeConstructor)) + $u.TypeRef.apply($u.ThisType.apply($m.staticPackage("scala").asModule.moduleClass), $m.staticClass("scala.Array"), scala.collection.immutable.List.apply[$u.Type]($m.staticClass("scala.Int").asType.toTypeConstructor)) } }; new $typecreator2() diff --git a/test/files/run/reflection-constructormirror-inner-badpath.scala b/test/files/run/reflection-constructormirror-inner-badpath.scala index a42bedea83..4bccff21fe 100644 --- a/test/files/run/reflection-constructormirror-inner-badpath.scala +++ b/test/files/run/reflection-constructormirror-inner-badpath.scala @@ -12,7 +12,7 @@ class Foo{ val classTag = implicitly[ClassTag[R]] val cl = classTag.runtimeClass.getClassLoader val cm = runtimeMirror(cl) - val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethodSymbol + val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethod val sig = constructor.typeSignature val sym = cm.classSymbol( classTag.runtimeClass ) try { diff --git a/test/files/run/reflection-constructormirror-inner-good.scala b/test/files/run/reflection-constructormirror-inner-good.scala index c09f464b24..861332161f 100644 --- a/test/files/run/reflection-constructormirror-inner-good.scala +++ b/test/files/run/reflection-constructormirror-inner-good.scala @@ -12,7 +12,7 @@ class Foo{ val classTag = implicitly[ClassTag[R]] val cl = classTag.runtimeClass.getClassLoader val cm = runtimeMirror(cl) - val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethodSymbol + val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethod val sig = constructor.typeSignature val sym = cm.classSymbol( classTag.runtimeClass ) val cls = cm.reflect( this ).reflectClass( sym ) diff --git a/test/files/run/reflection-constructormirror-nested-badpath.scala b/test/files/run/reflection-constructormirror-nested-badpath.scala index ece0044c61..2983f185de 100644 --- a/test/files/run/reflection-constructormirror-nested-badpath.scala +++ b/test/files/run/reflection-constructormirror-nested-badpath.scala @@ -8,7 +8,7 @@ class Foo{ val classTag = implicitly[ClassTag[R]] val cl = classTag.runtimeClass.getClassLoader val cm = runtimeMirror(cl) - val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethodSymbol + val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethod val sig = constructor.typeSignature val sym = cm.classSymbol( classTag.runtimeClass ) try { diff --git a/test/files/run/reflection-constructormirror-nested-good.scala b/test/files/run/reflection-constructormirror-nested-good.scala index 432e9d3707..0b7c413975 100644 --- a/test/files/run/reflection-constructormirror-nested-good.scala +++ b/test/files/run/reflection-constructormirror-nested-good.scala @@ -8,7 +8,7 @@ class Foo{ val classTag = implicitly[ClassTag[R]] val cl = classTag.runtimeClass.getClassLoader val cm = runtimeMirror(cl) - val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethodSymbol + val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethod val sig = constructor.typeSignature val sym = cm.classSymbol( classTag.runtimeClass ) val cls = cm.reflectClass( sym ) diff --git a/test/files/run/reflection-constructormirror-toplevel-badpath.scala b/test/files/run/reflection-constructormirror-toplevel-badpath.scala index 7a7adbd603..cf92929119 100644 --- a/test/files/run/reflection-constructormirror-toplevel-badpath.scala +++ b/test/files/run/reflection-constructormirror-toplevel-badpath.scala @@ -13,7 +13,7 @@ class Foo{ val classTag = implicitly[ClassTag[R]] val cl = classTag.runtimeClass.getClassLoader val cm = runtimeMirror(cl) - val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethodSymbol + val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethod val sig = constructor.typeSignature val sym = cm.classSymbol( classTag.runtimeClass ) try { diff --git a/test/files/run/reflection-constructormirror-toplevel-good.scala b/test/files/run/reflection-constructormirror-toplevel-good.scala index 96713a11cb..b68134b2cb 100644 --- a/test/files/run/reflection-constructormirror-toplevel-good.scala +++ b/test/files/run/reflection-constructormirror-toplevel-good.scala @@ -13,7 +13,7 @@ class Foo{ val classTag = implicitly[ClassTag[R]] val cl = classTag.runtimeClass.getClassLoader val cm = runtimeMirror(cl) - val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethodSymbol + val constructor = expectedType.tpe.member( nme.CONSTRUCTOR ).asMethod val sig = constructor.typeSignature val sym = cm.classSymbol( classTag.runtimeClass ) val cls = cm.reflectClass( sym ) diff --git a/test/files/run/reflection-equality.check b/test/files/run/reflection-equality.check index feafb58d3b..be531fbbd3 100644 --- a/test/files/run/reflection-equality.check +++ b/test/files/run/reflection-equality.check @@ -29,7 +29,7 @@ java.lang.Object { def methodIntIntInt: } -scala> val ms: MethodSymbol = ts.declaration(newTermName("methodIntIntInt")).asMethodSymbol +scala> val ms: MethodSymbol = ts.declaration(newTermName("methodIntIntInt")).asMethod ms: reflect.runtime.universe.MethodSymbol = method methodIntIntInt scala> val MethodType( _, t1 ) = ms.typeSignature diff --git a/test/files/run/reflection-equality.scala b/test/files/run/reflection-equality.scala index 35dc47a59f..8fc82721e7 100644 --- a/test/files/run/reflection-equality.scala +++ b/test/files/run/reflection-equality.scala @@ -11,7 +11,7 @@ object Test extends ReplTest { |def im: InstanceMirror = cm.reflect(new X) |val cs: ClassSymbol = im.symbol |val ts: Type = cs.typeSignature - |val ms: MethodSymbol = ts.declaration(newTermName("methodIntIntInt")).asMethodSymbol + |val ms: MethodSymbol = ts.declaration(newTermName("methodIntIntInt")).asMethod |val MethodType( _, t1 ) = ms.typeSignature |val t2 = typeOf[scala.Int] |t1 == t2 diff --git a/test/files/run/reflection-fieldmirror-accessorsareokay.scala b/test/files/run/reflection-fieldmirror-accessorsareokay.scala index c586ce9bdd..9590cbe811 100644 --- a/test/files/run/reflection-fieldmirror-accessorsareokay.scala +++ b/test/files/run/reflection-fieldmirror-accessorsareokay.scala @@ -13,7 +13,7 @@ object Test extends App { def test(f: Symbol) = { try { - val fm: FieldMirror = im.reflectField(f.asTermSymbol) + val fm: FieldMirror = im.reflectField(f.asTerm) println(fm.symbol.isVariable) println(fm.get) fm.set(2) @@ -24,6 +24,6 @@ object Test extends App { } } - test(cs.typeSignature.declaration(newTermName("x")).asTermSymbol) - test(cs.typeSignature.declaration(newTermName("x_$eq")).asTermSymbol) + test(cs.typeSignature.declaration(newTermName("x")).asTerm) + test(cs.typeSignature.declaration(newTermName("x_$eq")).asTerm) } diff --git a/test/files/run/reflection-fieldmirror-ctorparam.scala b/test/files/run/reflection-fieldmirror-ctorparam.scala index fa9dd81d7f..b9d50fe97b 100644 --- a/test/files/run/reflection-fieldmirror-ctorparam.scala +++ b/test/files/run/reflection-fieldmirror-ctorparam.scala @@ -10,7 +10,7 @@ object Test extends App { val im: InstanceMirror = cm.reflect(a) val cs = im.symbol - val f = cs.typeSignature.declaration(newTermName("x")).asTermSymbol + val f = cs.typeSignature.declaration(newTermName("x")).asTerm try { val fm: FieldMirror = im.reflectField(f) println(fm.get) diff --git a/test/files/run/reflection-fieldmirror-getsetval.scala b/test/files/run/reflection-fieldmirror-getsetval.scala index af9a6e4c56..67c54d9708 100644 --- a/test/files/run/reflection-fieldmirror-getsetval.scala +++ b/test/files/run/reflection-fieldmirror-getsetval.scala @@ -10,7 +10,7 @@ object Test extends App { val im: InstanceMirror = cm.reflect(a) val cs = im.symbol - val f = cs.typeSignature.declaration(newTermName("x" + nme.LOCAL_SUFFIX_STRING)).asTermSymbol + val f = cs.typeSignature.declaration(newTermName("x" + nme.LOCAL_SUFFIX_STRING)).asTerm val fm: FieldMirror = im.reflectField(f) try { println(fm.get) diff --git a/test/files/run/reflection-fieldmirror-getsetvar.scala b/test/files/run/reflection-fieldmirror-getsetvar.scala index d9fbdaade0..abcf396dd1 100644 --- a/test/files/run/reflection-fieldmirror-getsetvar.scala +++ b/test/files/run/reflection-fieldmirror-getsetvar.scala @@ -10,7 +10,7 @@ object Test extends App { val im: InstanceMirror = cm.reflect(a) val cs = im.symbol - val f = cs.typeSignature.declaration(newTermName("x" + nme.LOCAL_SUFFIX_STRING)).asTermSymbol + val f = cs.typeSignature.declaration(newTermName("x" + nme.LOCAL_SUFFIX_STRING)).asTerm val fm: FieldMirror = im.reflectField(f) println(fm.get) fm.set(2) diff --git a/test/files/run/reflection-fieldmirror-nmelocalsuffixstring.scala b/test/files/run/reflection-fieldmirror-nmelocalsuffixstring.scala index d89e6a90ef..5cfe583ed5 100644 --- a/test/files/run/reflection-fieldmirror-nmelocalsuffixstring.scala +++ b/test/files/run/reflection-fieldmirror-nmelocalsuffixstring.scala @@ -10,7 +10,7 @@ object Test extends App { val im: InstanceMirror = cm.reflect(a) val cs = im.symbol - val f = cs.typeSignature.declaration(newTermName("x" + nme.LOCAL_SUFFIX_STRING)).asTermSymbol + val f = cs.typeSignature.declaration(newTermName("x" + nme.LOCAL_SUFFIX_STRING)).asTerm val fm: FieldMirror = im.reflectField(f) println(fm.symbol.isVariable) } diff --git a/test/files/run/reflection-fieldmirror-privatethis.scala b/test/files/run/reflection-fieldmirror-privatethis.scala index 0c415e09e4..7aa179958d 100644 --- a/test/files/run/reflection-fieldmirror-privatethis.scala +++ b/test/files/run/reflection-fieldmirror-privatethis.scala @@ -10,7 +10,7 @@ object Test extends App { val im: InstanceMirror = cm.reflect(a) val cs = im.symbol - val f = cs.typeSignature.declaration(newTermName("x")).asTermSymbol + val f = cs.typeSignature.declaration(newTermName("x")).asTerm val fm: FieldMirror = im.reflectField(f) println(fm.symbol.isVariable) println(fm.get) diff --git a/test/files/run/reflection-methodsymbol-allparams.scala b/test/files/run/reflection-methodsymbol-allparams.scala index cfd14f56a5..d7c1c281b0 100644 --- a/test/files/run/reflection-methodsymbol-allparams.scala +++ b/test/files/run/reflection-methodsymbol-allparams.scala @@ -13,12 +13,12 @@ class C { } object Test extends App { - println(typeOf[C].member(newTermName("x1")).asMethodSymbol.allParams) - println(typeOf[C].member(newTermName("x2")).asMethodSymbol.allParams) - println(typeOf[C].member(newTermName("x3")).asMethodSymbol.allParams) - println(typeOf[C].member(newTermName("x4")).asMethodSymbol.allParams) - println(typeOf[C].member(newTermName("y1")).asMethodSymbol.allParams) - println(typeOf[C].member(newTermName("y2")).asMethodSymbol.allParams) - println(typeOf[C].member(newTermName("y3")).asMethodSymbol.allParams) - println(typeOf[C].member(newTermName("y4")).asMethodSymbol.allParams) + println(typeOf[C].member(newTermName("x1")).asMethod.allParams) + println(typeOf[C].member(newTermName("x2")).asMethod.allParams) + println(typeOf[C].member(newTermName("x3")).asMethod.allParams) + println(typeOf[C].member(newTermName("x4")).asMethod.allParams) + println(typeOf[C].member(newTermName("y1")).asMethod.allParams) + println(typeOf[C].member(newTermName("y2")).asMethod.allParams) + println(typeOf[C].member(newTermName("y3")).asMethod.allParams) + println(typeOf[C].member(newTermName("y4")).asMethod.allParams) } \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-params.scala b/test/files/run/reflection-methodsymbol-params.scala index 654a16b59d..7174c6f49b 100644 --- a/test/files/run/reflection-methodsymbol-params.scala +++ b/test/files/run/reflection-methodsymbol-params.scala @@ -13,12 +13,12 @@ class C { } object Test extends App { - println(typeOf[C].member(newTermName("x1")).asMethodSymbol.params) - println(typeOf[C].member(newTermName("x2")).asMethodSymbol.params) - println(typeOf[C].member(newTermName("x3")).asMethodSymbol.params) - println(typeOf[C].member(newTermName("x4")).asMethodSymbol.params) - println(typeOf[C].member(newTermName("y1")).asMethodSymbol.params) - println(typeOf[C].member(newTermName("y2")).asMethodSymbol.params) - println(typeOf[C].member(newTermName("y3")).asMethodSymbol.params) - println(typeOf[C].member(newTermName("y4")).asMethodSymbol.params) + println(typeOf[C].member(newTermName("x1")).asMethod.params) + println(typeOf[C].member(newTermName("x2")).asMethod.params) + println(typeOf[C].member(newTermName("x3")).asMethod.params) + println(typeOf[C].member(newTermName("x4")).asMethod.params) + println(typeOf[C].member(newTermName("y1")).asMethod.params) + println(typeOf[C].member(newTermName("y2")).asMethod.params) + println(typeOf[C].member(newTermName("y3")).asMethod.params) + println(typeOf[C].member(newTermName("y4")).asMethod.params) } \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-resulttype.scala b/test/files/run/reflection-methodsymbol-resulttype.scala index 7a9f66dda8..0e3de26b9f 100644 --- a/test/files/run/reflection-methodsymbol-resulttype.scala +++ b/test/files/run/reflection-methodsymbol-resulttype.scala @@ -13,12 +13,12 @@ class C { } object Test extends App { - println(typeOf[C].member(newTermName("x1")).asMethodSymbol.resultType) - println(typeOf[C].member(newTermName("x2")).asMethodSymbol.resultType) - println(typeOf[C].member(newTermName("x3")).asMethodSymbol.resultType) - println(typeOf[C].member(newTermName("x4")).asMethodSymbol.resultType) - println(typeOf[C].member(newTermName("y1")).asMethodSymbol.resultType) - println(typeOf[C].member(newTermName("y2")).asMethodSymbol.resultType) - println(typeOf[C].member(newTermName("y3")).asMethodSymbol.resultType) - println(typeOf[C].member(newTermName("y4")).asMethodSymbol.resultType) + println(typeOf[C].member(newTermName("x1")).asMethod.resultType) + println(typeOf[C].member(newTermName("x2")).asMethod.resultType) + println(typeOf[C].member(newTermName("x3")).asMethod.resultType) + println(typeOf[C].member(newTermName("x4")).asMethod.resultType) + println(typeOf[C].member(newTermName("y1")).asMethod.resultType) + println(typeOf[C].member(newTermName("y2")).asMethod.resultType) + println(typeOf[C].member(newTermName("y3")).asMethod.resultType) + println(typeOf[C].member(newTermName("y4")).asMethod.resultType) } \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-typeparams.scala b/test/files/run/reflection-methodsymbol-typeparams.scala index 28f1c8973d..bb0a3c3aec 100644 --- a/test/files/run/reflection-methodsymbol-typeparams.scala +++ b/test/files/run/reflection-methodsymbol-typeparams.scala @@ -13,12 +13,12 @@ class C { } object Test extends App { - println(typeOf[C].member(newTermName("x1")).asMethodSymbol.typeParams) - println(typeOf[C].member(newTermName("x2")).asMethodSymbol.typeParams) - println(typeOf[C].member(newTermName("x3")).asMethodSymbol.typeParams) - println(typeOf[C].member(newTermName("x4")).asMethodSymbol.typeParams) - println(typeOf[C].member(newTermName("y1")).asMethodSymbol.typeParams) - println(typeOf[C].member(newTermName("y2")).asMethodSymbol.typeParams) - println(typeOf[C].member(newTermName("y3")).asMethodSymbol.typeParams) - println(typeOf[C].member(newTermName("y4")).asMethodSymbol.typeParams) + println(typeOf[C].member(newTermName("x1")).asMethod.typeParams) + println(typeOf[C].member(newTermName("x2")).asMethod.typeParams) + println(typeOf[C].member(newTermName("x3")).asMethod.typeParams) + println(typeOf[C].member(newTermName("x4")).asMethod.typeParams) + println(typeOf[C].member(newTermName("y1")).asMethod.typeParams) + println(typeOf[C].member(newTermName("y2")).asMethod.typeParams) + println(typeOf[C].member(newTermName("y3")).asMethod.typeParams) + println(typeOf[C].member(newTermName("y4")).asMethod.typeParams) } \ No newline at end of file diff --git a/test/files/run/reflection-sanitychecks.scala b/test/files/run/reflection-sanitychecks.scala index a6a24088a4..e95d130460 100644 --- a/test/files/run/reflection-sanitychecks.scala +++ b/test/files/run/reflection-sanitychecks.scala @@ -19,10 +19,10 @@ object Test extends App { def test(tpe: Type): Unit = { def failsafe(action: => Any): Any = try action catch { case ex: Throwable => ex.toString } - println("field: " + failsafe(im.reflectField(tpe.member(newTermName("foo")).asTermSymbol).get)) - println("method: " + failsafe(im.reflectMethod(tpe.member(newTermName("bar")).asMethodSymbol)())) - println("class: " + failsafe(im.reflectClass(tpe.member(newTypeName("C")).asClassSymbol).reflectConstructor(typeOf[C].member(newTypeName("C")).asClassSymbol.typeSignature.member(newTermName("")).asMethodSymbol)())) - println("object: " + failsafe(im.reflectModule(tpe.member(newTermName("O")).asModuleSymbol).instance)) + println("field: " + failsafe(im.reflectField(tpe.member(newTermName("foo")).asTerm).get)) + println("method: " + failsafe(im.reflectMethod(tpe.member(newTermName("bar")).asMethod)())) + println("class: " + failsafe(im.reflectClass(tpe.member(newTypeName("C")).asClass).reflectConstructor(typeOf[C].member(newTypeName("C")).asClass.typeSignature.member(newTermName("")).asMethod)())) + println("object: " + failsafe(im.reflectModule(tpe.member(newTermName("O")).asModule).instance)) } test(typeOf[C]) diff --git a/test/files/run/toolbox_typecheck_macrosdisabled2.check b/test/files/run/toolbox_typecheck_macrosdisabled2.check index 53041e328d..fa55a09c40 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled2.check +++ b/test/files/run/toolbox_typecheck_macrosdisabled2.check @@ -28,7 +28,7 @@ def apply[U <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - $u.TypeRef.apply($u.ThisType.apply($m.staticPackage("scala").asModuleSymbol.moduleClass), $m.staticClass("scala.Array"), scala.collection.immutable.List.apply[$u.Type]($m.staticClass("scala.Int").asTypeSymbol.asTypeConstructor)) + $u.TypeRef.apply($u.ThisType.apply($m.staticPackage("scala").asModule.moduleClass), $m.staticClass("scala.Array"), scala.collection.immutable.List.apply[$u.Type]($m.staticClass("scala.Int").asType.toTypeConstructor)) } }; new $typecreator2() -- cgit v1.2.3 From b578059b43a4caaadee2cb20f74cd9a7c876c8ef Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 31 Jul 2012 10:50:54 +0200 Subject: SI-5888 Mirrors now have sane toStrings Adds informative toString for InstanceMirror, FieldMirror, MethodMirror (for methods and constructors), ClassMirror and ModuleMirror. Universe mirrors (e.g. JavaMirrors or compiler mirrors) already have good toString methods that show their affiliation and/or classpaths. --- .../scala/reflect/runtime/JavaMirrors.scala | 32 +++++++++++++++- .../files/run/reflection-allmirrors-tostring.check | 14 +++++++ .../files/run/reflection-allmirrors-tostring.scala | 43 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/files/run/reflection-allmirrors-tostring.check create mode 100644 test/files/run/reflection-allmirrors-tostring.scala (limited to 'test/files') diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 6ae7e6d7eb..b11eda9b7b 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -187,6 +187,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym checkMemberOf(mod, symbol) new JavaModuleMirror(instance, mod) } + override def toString = s"instance mirror for $obj" } private class JavaFieldMirror(val receiver: AnyRef, val symbol: TermSymbol) @@ -201,6 +202,32 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym if (!symbol.isMutable) ErrorSetImmutableField(symbol) jfield.set(receiver, value) } + override def toString = s"field mirror for ${symbol.fullName} (bound to $receiver)" + } + + private def showMethodSig(symbol: MethodSymbol): String = { + var sig = s"${symbol.fullName}" + if (symbol.typeParams.nonEmpty) { + def showTparam(tparam: Symbol) = + tparam.typeSignature match { + case tpe @ TypeBounds(_, _) => s"${tparam.name}$tpe" + case _ => tparam.name + } + def showTparams(tparams: List[Symbol]) = "[" + (tparams map showTparam mkString ", ") + "]" + sig += showTparams(symbol.typeParams) + } + if (symbol.allParams.nonEmpty) { + def showParam(param: Symbol) = s"${param.name}: ${param.typeSignature}" + def showParams(params: List[Symbol]) = { + val s_mods = if (params.nonEmpty && params(0).hasFlag(IMPLICIT)) "implicit " else "" + val s_params = params map showParam mkString ", " + "(" + s_mods + s_params + ")" + } + def showParamss(paramss: List[List[Symbol]]) = paramss map showParams mkString "" + sig += showParamss(symbol.allParams) + } + sig += s": ${symbol.resultType}" + sig } private class JavaMethodMirror(val receiver: AnyRef, val symbol: MethodSymbol) @@ -220,6 +247,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym } else jmeth.invoke(receiver, args.asInstanceOf[Seq[AnyRef]]: _*) + override def toString = s"method mirror for ${showMethodSig(symbol)} (bound to $receiver)" } private class JavaConstructorMirror(val outer: AnyRef, val symbol: MethodSymbol) @@ -236,9 +264,9 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym else outer +: args.asInstanceOf[Seq[AnyRef]] jconstr.newInstance(effectiveArgs: _*) } + override def toString = s"constructor mirror for ${showMethodSig(symbol)} (bound to $outer)" } - private abstract class JavaTemplateMirror extends TemplateMirror { def outer: AnyRef @@ -256,6 +284,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym case module: ModuleSymbol => Some(new JavaModuleMirror(outer, module)) case _ => None } + override def toString = s"class mirror for ${symbol.fullName} (bound to $outer)" } private class JavaModuleMirror(val outer: AnyRef, val symbol: ModuleSymbol) @@ -270,6 +299,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym case cls: ClassSymbol => Some(new JavaClassMirror(outer, cls)) case _ => None } + override def toString = s"module mirror for ${symbol.fullName} (bound to $outer)" } // -------------------- Java to Scala ----------------------------------- diff --git a/test/files/run/reflection-allmirrors-tostring.check b/test/files/run/reflection-allmirrors-tostring.check new file mode 100644 index 0000000000..b5fe6c33bb --- /dev/null +++ b/test/files/run/reflection-allmirrors-tostring.check @@ -0,0 +1,14 @@ +class mirror for C (bound to null) +module mirror for M (bound to null) +instance mirror for an instance of C +field mirror for C.f1 (bound to an instance of C) +field mirror for C.f2 (bound to an instance of C) +method mirror for C.m1: Int (bound to an instance of C) +method mirror for C.m2(): Int (bound to an instance of C) +method mirror for C.m3[T >: String <: Int]: T (bound to an instance of C) +method mirror for C.m4[A, B <: A[Int]](x: A[B])(implicit y: Int): Nothing (bound to an instance of C) +method mirror for C.m5(x: => Int, y: Int*): String (bound to an instance of C) +class mirror for C.C (bound to an instance of C) +module mirror for C.M (bound to an instance of C) +constructor mirror for C.(): C (bound to null) +constructor mirror for C.C.(): C.this.C (bound to an instance of C) diff --git a/test/files/run/reflection-allmirrors-tostring.scala b/test/files/run/reflection-allmirrors-tostring.scala new file mode 100644 index 0000000000..73afff291c --- /dev/null +++ b/test/files/run/reflection-allmirrors-tostring.scala @@ -0,0 +1,43 @@ +import scala.reflect.runtime.universe._ + +class C { + val f1 = 2 + var f2 = 3 + + def m1 = 4 + def m2() = 5 + def m3[T >: String <: Int]: T = ??? + def m4[A[_], B <: A[Int]](x: A[B])(implicit y: Int) = ??? + def m5(x: => Int, y: Int*): String = ??? + + class C + object M + + override def toString = "an instance of C" +} +object M + +object Test extends App { + val cm = scala.reflect.runtime.currentMirror +// println(cm) + + println(cm.reflectClass(cm.staticClass("C"))) + println(cm.reflectModule(cm.staticModule("M"))) + println(cm.reflect(new C)) + + val im = cm.reflect(new C) + println(im.reflectField(typeOf[C].member(newTermName("f1")).asTerm)) + println(im.reflectField(typeOf[C].member(newTermName("f2")).asTerm)) + println(im.reflectMethod(typeOf[C].member(newTermName("m1")).asMethod)) + println(im.reflectMethod(typeOf[C].member(newTermName("m2")).asMethod)) + println(im.reflectMethod(typeOf[C].member(newTermName("m3")).asMethod)) + println(im.reflectMethod(typeOf[C].member(newTermName("m4")).asMethod)) + println(im.reflectMethod(typeOf[C].member(newTermName("m5")).asMethod)) + println(im.reflectClass(typeOf[C].member(newTypeName("C")).asClass)) + println(im.reflectModule(typeOf[C].member(newTermName("M")).asModule)) + + val c = cm.staticClass("C") + val cc = typeOf[C].member(newTypeName("C")).asClass + println(cm.reflectClass(c).reflectConstructor(c.typeSignature.member(nme.CONSTRUCTOR).asMethod)) + println(im.reflectClass(cc).reflectConstructor(cc.typeSignature.member(nme.CONSTRUCTOR).asMethod)) +} \ No newline at end of file -- cgit v1.2.3 From 027b00171c0d92ec669deaa471966e6468c6b8cf Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 31 Jul 2012 11:33:16 +0200 Subject: more refinements of reflection API Added a bunch of test methods to symbols to cover public flags: (e.g. isPrivate, isFinal, isOverride, isImplicit, etc). I'd argue that the API duplication w.r.t flag sets is trumped by unified interface to tests and better encapsulation. Also updated the API to be easier to understand after prior exposure to Java or .NET reflection APIs: 1) Added typeParams to TypeSymbol and ClassSymbol. 2) Renamed MethodSymbol.resultType to returnType. 3) Removed the distinction between MethodSymbol.params vs MethodSymbol.allParams now we just have MethodSymbol.params: List[List[Symbol]]. --- src/library/scala/reflect/base/Symbols.scala | 16 --- src/reflect/scala/reflect/api/FlagSets.scala | 4 - src/reflect/scala/reflect/api/Symbols.scala | 155 +++++++++++++++------ src/reflect/scala/reflect/api/Trees.scala | 12 +- src/reflect/scala/reflect/internal/Symbols.scala | 17 +-- .../scala/reflect/runtime/JavaMirrors.scala | 6 +- .../reflect/runtime/SynchronizedSymbols.scala | 5 +- .../run/reflection-methodsymbol-allparams.check | 8 -- .../run/reflection-methodsymbol-allparams.scala | 24 ---- .../files/run/reflection-methodsymbol-params.check | 12 +- .../run/reflection-methodsymbol-resulttype.check | 8 -- .../run/reflection-methodsymbol-resulttype.scala | 24 ---- .../run/reflection-methodsymbol-returntype.check | 8 ++ .../run/reflection-methodsymbol-returntype.scala | 24 ++++ 14 files changed, 167 insertions(+), 156 deletions(-) delete mode 100644 test/files/run/reflection-methodsymbol-allparams.check delete mode 100644 test/files/run/reflection-methodsymbol-allparams.scala delete mode 100644 test/files/run/reflection-methodsymbol-resulttype.check delete mode 100644 test/files/run/reflection-methodsymbol-resulttype.scala create mode 100644 test/files/run/reflection-methodsymbol-returntype.check create mode 100644 test/files/run/reflection-methodsymbol-returntype.scala (limited to 'test/files') diff --git a/src/library/scala/reflect/base/Symbols.scala b/src/library/scala/reflect/base/Symbols.scala index 052571dbcb..45f7c0c1bd 100644 --- a/src/library/scala/reflect/base/Symbols.scala +++ b/src/library/scala/reflect/base/Symbols.scala @@ -80,10 +80,6 @@ trait Symbols { self: Universe => /** The base API that all symbols support */ trait SymbolBase { this: Symbol => - /** An id number which is unique for all symbols in this universe */ - // [Eugene++ to Martin] do we leave this here? - def id: Int - /** The owner of this symbol. This is the symbol * that directly contains the current symbol's definition. * The `NoSymbol` symbol does not have an owner, and calling this method @@ -112,18 +108,6 @@ trait Symbols { self: Universe => */ def fullName: String - /** If this symbol is a class, this symbol; otherwise the next enclosing - * class, or `NoSymbol` if none exists. - */ - def enclosingClass: Symbol = - if (isClass || this == NoSymbol) this else owner.enclosingClass - - /** If this symbol is a method, this symbol; otherwise the next enclosing - * method, or `NoSymbol` if none exists. - */ - def enclosingMethod: Symbol = - if (isMethod || this == NoSymbol) this else owner.enclosingMethod - /** Does this symbol represent the definition of a type? * Note that every symbol is either a term or a type. * So for every symbol `sym`, either `sym.isTerm` is true diff --git a/src/reflect/scala/reflect/api/FlagSets.scala b/src/reflect/scala/reflect/api/FlagSets.scala index c56de49962..6d105c9d20 100644 --- a/src/reflect/scala/reflect/api/FlagSets.scala +++ b/src/reflect/scala/reflect/api/FlagSets.scala @@ -97,9 +97,5 @@ trait FlagSets { self: Universe => /** Flag indicating that parameter has a default value */ val DEFAULTPARAM: FlagSet - - /** Flag indicating that trait has neither method implementations nor fields. - * This means the trait can be represented as a Java interface. */ - val INTERFACE: FlagSet } } diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala index e55c1ea11a..13f5f743f1 100644 --- a/src/reflect/scala/reflect/api/Symbols.scala +++ b/src/reflect/scala/reflect/api/Symbols.scala @@ -43,6 +43,53 @@ trait Symbols extends base.Symbols { self: Universe => */ def hasAnnotation(sym: Symbol): Boolean + /** For a class: the module or case class factory with the same name in the same package. + * For a module: the class with the same name in the same package. + * For all others: NoSymbol + */ + def companionSymbol: Symbol + + /** The type signature of this symbol seen as a member of given type `site`. + */ + def typeSignatureIn(site: Type): Type + + /** The type signature of this symbol. + * Note if the symbol is a member of a class, one almost always is interested + * in `typeSignatureIn` with a site type instead. + */ + def typeSignature: Type + + /******************* tests *******************/ + + /** Does this symbol represent a synthetic (i.e. a compiler-generated) entity? + * Examples of synthetic entities are accessors for vals and vars + * or mixin constructors in trait implementation classes. + */ + def isSynthetic: Boolean + + /** Does this symbol represent a local declaration or definition? + * + * If yes, either `isPrivate` or `isProtected` are guaranteed to be true. + * Local symbols can only be accessed from the same object instance. + * + * If yes, `privateWithin` might tell more about this symbol's visibility scope. + */ + def isLocal: Boolean + + /** Does this symbol represent a private declaration or definition? + * If yes, `privateWithin` might tell more about this symbol's visibility scope. + */ + def isPrivate: Boolean + + /** Does this symbol represent a protected declaration or definition? + * If yes, `privateWithin` might tell more about this symbol's visibility scope. + */ + def isProtected: Boolean + + /** Does this symbol represent a public declaration or definition? + */ + def isPublic: Boolean + /** * Set when symbol has a modifier of the form private[X], NoSymbol otherwise. * @@ -70,24 +117,6 @@ trait Symbols extends base.Symbols { self: Universe => */ def privateWithin: Symbol - /** For a class: the module or case class factory with the same name in the same package. - * For a module: the class with the same name in the same package. - * For all others: NoSymbol - */ - def companionSymbol: Symbol - - /** The type signature of this symbol seen as a member of given type `site`. - */ - def typeSignatureIn(site: Type): Type - - /** The type signature of this symbol. - * Note if the symbol is a member of a class, one almost always is interested - * in `typeSignatureIn` with a site type instead. - */ - def typeSignature: Type - - /******************* tests *******************/ - /** Does this symbol represent the definition of a package? * If yes, `isTerm` is also guaranteed to be true. */ @@ -121,6 +150,18 @@ trait Symbols extends base.Symbols { self: Universe => */ def isStatic: Boolean + /** Is this symbol final? + */ + def isFinal: Boolean + + /** Is this symbol overriding something? + */ + def isOverride: Boolean + + /** Is this symbol a macro? + */ + def isMacro: Boolean + /******************* helpers *******************/ /** ... @@ -177,6 +218,14 @@ trait Symbols extends base.Symbols { self: Universe => */ def isOverloaded : Boolean + /** Does this symbol represent an implicit value, definition or parameter? + */ + def isImplicit: Boolean + + /** Does this symbol represent a lazy value? + */ + def isLazy: Boolean + /** The overloaded alternatives of this symbol */ def alternatives: List[Symbol] @@ -208,23 +257,6 @@ trait Symbols extends base.Symbols { self: Universe => */ def isSkolem : Boolean - /** Does this symbol represent the definition of a primitive class? - * Namely, is it one of [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]], - * [[scala.Short]], [[scala.Byte]], [[scala.Unit]] or [[scala.Boolean]]? - */ - def isPrimitiveValueClass: Boolean - - /** Does this symbol represent the definition of a numeric value class? - * Namely, is it one of [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]], - * [[scala.Short]], [[scala.Byte]], [[scala.Unit]] or [[scala.Boolean]]? - */ - def isNumericValueClass: Boolean - - /** Does this symbol represent the definition of a custom value class? - * Namely, is AnyVal among its parent classes? - */ - def isDerivedValueClass: Boolean - /** Does this symbol represent the definition of a type alias? */ def isAliasType : Boolean @@ -236,6 +268,9 @@ trait Symbols extends base.Symbols { self: Universe => /** Does this symbol represent an existentially bound type? */ def isExistential : Boolean + + /** For a polymorphic type, its type parameters, the empty list for all other types */ + def typeParams: List[Symbol] } /** The API of method symbols */ @@ -243,24 +278,16 @@ trait Symbols extends base.Symbols { self: Universe => /** For a polymorphic method, its type parameters, the empty list for all other methods */ def typeParams: List[Symbol] - /** The first parameter list of the method. - * - * For a nullary method, returns the empty list. - * For a method with an empty parameter list, returns the empty list. - * To distinguish between those, use `allParams`. - */ - def params: List[Symbol] - /** All parameter lists of the method. * * Can be used to distinguish nullary methods and methods with empty parameter lists. * For a nullary method, returns the empty list (i.e. `List()`). * For a method with an empty parameter list, returns a list that contains the empty list (i.e. `List(List())`). */ - def allParams: List[List[Symbol]] + def params: List[List[Symbol]] - /** The result type of the method */ - def resultType: Type + /** The return type of the method */ + def returnType: Type } /** The API of module symbols */ @@ -269,6 +296,39 @@ trait Symbols extends base.Symbols { self: Universe => /** The API of class symbols */ trait ClassSymbolApi extends TypeSymbolApi with ClassSymbolBase { this: ClassSymbol => + /** Does this symbol represent the definition of a primitive class? + * Namely, is it one of [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]], + * [[scala.Short]], [[scala.Byte]], [[scala.Unit]] or [[scala.Boolean]]? + */ + def isPrimitive: Boolean + + /** Does this symbol represent the definition of a numeric value class? + * Namely, is it one of [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]], + * [[scala.Short]], [[scala.Byte]], [[scala.Unit]] or [[scala.Boolean]]? + */ + def isNumeric: Boolean + + /** Does this symbol represent the definition of a custom value class? + * Namely, is AnyVal among its parent classes? + */ + def isDerivedValueClass: Boolean + + /** Does this symbol represent a trait? + */ + def isTrait: Boolean + + /** Does this symbol represent an abstract class? + */ + def isAbstractClass: Boolean + + /** Does this symbol represent a case class? + */ + def isCaseClass: Boolean + + /** Does this symbol represent a sealed class? + */ + def isSealed: Boolean + /** If this symbol is a class or trait, its self type, otherwise the type * of the symbol itself. */ @@ -276,6 +336,9 @@ trait Symbols extends base.Symbols { self: Universe => /** The type `C.this`, where `C` is the current class */ def thisPrefix: Type + + /** For a polymorphic class/trait, its type parameters, the empty list for all other classes/trait */ + def typeParams: List[Symbol] } /** The API of free term symbols */ diff --git a/src/reflect/scala/reflect/api/Trees.scala b/src/reflect/scala/reflect/api/Trees.scala index 28dd764c70..8165f599b2 100644 --- a/src/reflect/scala/reflect/api/Trees.scala +++ b/src/reflect/scala/reflect/api/Trees.scala @@ -640,8 +640,16 @@ trait Trees extends base.Trees { self: Universe => abstract class Transformer { val treeCopy: TreeCopier = newLazyTreeCopier protected[scala] var currentOwner: Symbol = rootMirror.RootClass - protected def currentMethod = currentOwner.enclosingMethod - protected def currentClass = currentOwner.enclosingClass + protected def currentMethod = { + def enclosingMethod(sym: Symbol): Symbol = + if (sym.isMethod || sym == NoSymbol) sym else enclosingMethod(sym.owner) + enclosingMethod(currentOwner) + } + protected def currentClass = { + def enclosingClass(sym: Symbol): Symbol = + if (sym.isClass || sym == NoSymbol) sym else enclosingClass(sym.owner) + enclosingClass(currentOwner) + } // protected def currentPackage = currentOwner.enclosingTopLevelClass.owner def transform(tree: Tree): Tree = itransform(this, tree) diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 372520e48f..304caa74d4 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -456,6 +456,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => def isAliasType = false def isAbstractType = false def isSkolem = false + def isMacro = this hasFlag MACRO /** A Type, but not a Class. */ def isNonClassType = false @@ -2487,19 +2488,9 @@ trait Symbols extends api.Symbols { self: SymbolTable => res } - override def allParams: List[List[Symbol]] = paramss + override def params: List[List[Symbol]] = paramss - override def params: List[Symbol] = { - def loop(tpe: Type): List[Symbol] = - tpe match { - case NullaryMethodType(_) => Nil - case MethodType(params, _) => params - case PolyType(_, tpe) => loop(tpe) - } - loop(info) - } - - override def resultType: Type = { + override def returnType: Type = { def loop(tpe: Type): Type = tpe match { case NullaryMethodType(ret) => loop(ret) @@ -2772,8 +2763,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => override def isJavaInterface = hasAllFlags(JAVA | TRAIT) override def isNestedClass = !owner.isPackageClass override def isNumericValueClass = definitions.isNumericValueClass(this) + override def isNumeric = isNumericValueClass override def isPackageObjectClass = isModuleClass && (name == tpnme.PACKAGE) override def isPrimitiveValueClass = definitions.isPrimitiveValueClass(this) + override def isPrimitive = isPrimitiveValueClass // The corresponding interface is the last parent by convention. private def lastParent = if (tpe.parents.isEmpty) NoSymbol else tpe.parents.last.typeSymbol diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index b11eda9b7b..64c47a5502 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -216,7 +216,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym def showTparams(tparams: List[Symbol]) = "[" + (tparams map showTparam mkString ", ") + "]" sig += showTparams(symbol.typeParams) } - if (symbol.allParams.nonEmpty) { + if (symbol.params.nonEmpty) { def showParam(param: Symbol) = s"${param.name}: ${param.typeSignature}" def showParams(params: List[Symbol]) = { val s_mods = if (params.nonEmpty && params(0).hasFlag(IMPLICIT)) "implicit " else "" @@ -224,9 +224,9 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym "(" + s_mods + s_params + ")" } def showParamss(paramss: List[List[Symbol]]) = paramss map showParams mkString "" - sig += showParamss(symbol.allParams) + sig += showParamss(symbol.params) } - sig += s": ${symbol.resultType}" + sig += s": ${symbol.returnType}" sig } diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index 525673fe6d..c65357b652 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -110,9 +110,8 @@ trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => trait SynchronizedMethodSymbol extends MethodSymbol with SynchronizedTermSymbol { override def typeAsMemberOf(pre: Type): Type = synchronized { super.typeAsMemberOf(pre) } - override def allParams: List[List[Symbol]] = synchronized { super.allParams } - override def params: List[Symbol] = synchronized { super.params } - override def resultType: Type = synchronized { super.resultType } + override def params: List[List[Symbol]] = synchronized { super.params } + override def returnType: Type = synchronized { super.returnType } } trait SynchronizedTypeSymbol extends TypeSymbol with SynchronizedSymbol { diff --git a/test/files/run/reflection-methodsymbol-allparams.check b/test/files/run/reflection-methodsymbol-allparams.check deleted file mode 100644 index 11f349d52b..0000000000 --- a/test/files/run/reflection-methodsymbol-allparams.check +++ /dev/null @@ -1,8 +0,0 @@ -List() -List(List()) -List(List(value x)) -List(List(value x), List(value y)) -List() -List(List()) -List(List(value x)) -List(List(value x), List(value y)) diff --git a/test/files/run/reflection-methodsymbol-allparams.scala b/test/files/run/reflection-methodsymbol-allparams.scala deleted file mode 100644 index d7c1c281b0..0000000000 --- a/test/files/run/reflection-methodsymbol-allparams.scala +++ /dev/null @@ -1,24 +0,0 @@ -import scala.reflect.runtime.universe._ - -class C { - def x1: Int = ??? - def x2(): Int = ??? - def x3(x: Int): Int = ??? - def x4(x: Int)(y: Int): Int = ??? - - def y1[T]: Int = ??? - def y2[T](): Int = ??? - def y3[T](x: Int): Int = ??? - def y4[T](x: Int)(y: Int): Int = ??? -} - -object Test extends App { - println(typeOf[C].member(newTermName("x1")).asMethod.allParams) - println(typeOf[C].member(newTermName("x2")).asMethod.allParams) - println(typeOf[C].member(newTermName("x3")).asMethod.allParams) - println(typeOf[C].member(newTermName("x4")).asMethod.allParams) - println(typeOf[C].member(newTermName("y1")).asMethod.allParams) - println(typeOf[C].member(newTermName("y2")).asMethod.allParams) - println(typeOf[C].member(newTermName("y3")).asMethod.allParams) - println(typeOf[C].member(newTermName("y4")).asMethod.allParams) -} \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-params.check b/test/files/run/reflection-methodsymbol-params.check index 899ae15a0c..11f349d52b 100644 --- a/test/files/run/reflection-methodsymbol-params.check +++ b/test/files/run/reflection-methodsymbol-params.check @@ -1,8 +1,8 @@ List() +List(List()) +List(List(value x)) +List(List(value x), List(value y)) List() -List(value x) -List(value x) -List() -List() -List(value x) -List(value x) +List(List()) +List(List(value x)) +List(List(value x), List(value y)) diff --git a/test/files/run/reflection-methodsymbol-resulttype.check b/test/files/run/reflection-methodsymbol-resulttype.check deleted file mode 100644 index 0f30d1beaf..0000000000 --- a/test/files/run/reflection-methodsymbol-resulttype.check +++ /dev/null @@ -1,8 +0,0 @@ -Int -Int -Int -Int -Int -Int -Int -Int diff --git a/test/files/run/reflection-methodsymbol-resulttype.scala b/test/files/run/reflection-methodsymbol-resulttype.scala deleted file mode 100644 index 0e3de26b9f..0000000000 --- a/test/files/run/reflection-methodsymbol-resulttype.scala +++ /dev/null @@ -1,24 +0,0 @@ -import scala.reflect.runtime.universe._ - -class C { - def x1: Int = ??? - def x2(): Int = ??? - def x3(x: Int): Int = ??? - def x4(x: Int)(y: Int): Int = ??? - - def y1[T]: Int = ??? - def y2[T](): Int = ??? - def y3[T](x: Int): Int = ??? - def y4[T](x: Int)(y: Int): Int = ??? -} - -object Test extends App { - println(typeOf[C].member(newTermName("x1")).asMethod.resultType) - println(typeOf[C].member(newTermName("x2")).asMethod.resultType) - println(typeOf[C].member(newTermName("x3")).asMethod.resultType) - println(typeOf[C].member(newTermName("x4")).asMethod.resultType) - println(typeOf[C].member(newTermName("y1")).asMethod.resultType) - println(typeOf[C].member(newTermName("y2")).asMethod.resultType) - println(typeOf[C].member(newTermName("y3")).asMethod.resultType) - println(typeOf[C].member(newTermName("y4")).asMethod.resultType) -} \ No newline at end of file diff --git a/test/files/run/reflection-methodsymbol-returntype.check b/test/files/run/reflection-methodsymbol-returntype.check new file mode 100644 index 0000000000..0f30d1beaf --- /dev/null +++ b/test/files/run/reflection-methodsymbol-returntype.check @@ -0,0 +1,8 @@ +Int +Int +Int +Int +Int +Int +Int +Int diff --git a/test/files/run/reflection-methodsymbol-returntype.scala b/test/files/run/reflection-methodsymbol-returntype.scala new file mode 100644 index 0000000000..392754dbe4 --- /dev/null +++ b/test/files/run/reflection-methodsymbol-returntype.scala @@ -0,0 +1,24 @@ +import scala.reflect.runtime.universe._ + +class C { + def x1: Int = ??? + def x2(): Int = ??? + def x3(x: Int): Int = ??? + def x4(x: Int)(y: Int): Int = ??? + + def y1[T]: Int = ??? + def y2[T](): Int = ??? + def y3[T](x: Int): Int = ??? + def y4[T](x: Int)(y: Int): Int = ??? +} + +object Test extends App { + println(typeOf[C].member(newTermName("x1")).asMethod.returnType) + println(typeOf[C].member(newTermName("x2")).asMethod.returnType) + println(typeOf[C].member(newTermName("x3")).asMethod.returnType) + println(typeOf[C].member(newTermName("x4")).asMethod.returnType) + println(typeOf[C].member(newTermName("y1")).asMethod.returnType) + println(typeOf[C].member(newTermName("y2")).asMethod.returnType) + println(typeOf[C].member(newTermName("y3")).asMethod.returnType) + println(typeOf[C].member(newTermName("y4")).asMethod.returnType) +} \ No newline at end of file -- cgit v1.2.3 From 5e1a0052523349775be1cc98b4094c44804f1240 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 24 Jul 2012 12:14:54 +0200 Subject: removes -Xmacro-(.*)-classpath compiler options These options were meant to be used to bootstrap macros defined in our codebase However we can bootstrap perfectly without any additional effort, because library classpath classloader can delegate to tool classpath classloader to load macro implementations from starr. Since then (for several months) this functionality hasn't proven to be useful, neither anyone on the mailing list or stackoverflow asked questions about it (even despite it was explicitly mentioned in the "cannot load macro impl" error message). Hence I suggest that it is totally unnecessary and should be removed. --- .../scala/tools/nsc/settings/ScalaSettings.scala | 2 - .../scala/tools/nsc/typechecker/Macros.scala | 74 ++++++---------------- .../scala/tools/nsc/typechecker/Namers.scala | 10 --- test/files/neg/macro-basic-mamdmi.check | 1 - 4 files changed, 19 insertions(+), 68 deletions(-) (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index aa30a7a45b..3906d7761f 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -205,8 +205,6 @@ trait ScalaSettings extends AbsScalaSettings // Feature extensions val XmacroSettings = MultiStringSetting("-Xmacro-settings", "option", "Custom settings for macros.") - val XmacroPrimaryClasspath = PathSetting("-Xmacro-primary-classpath", "Classpath to load macros implementations from, defaults to compilation classpath (aka \"library classpath\".", "") - val XmacroFallbackClasspath = PathSetting("-Xmacro-fallback-classpath", "Classpath to load macros implementations from if they cannot be loaded from library classpath.", "") /** * IDE-specific settings diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index d33857371d..71176d6247 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -591,53 +591,34 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { runtimeType } - /** Primary classloader that is used to resolve and run macro implementations. - * Loads classes from -Xmacro-primary-classpath, or from -cp if the option is not specified. + /** Macro classloader that is used to resolve and run macro implementations. + * Loads classes from from -cp (aka the library classpath). * Is also capable of detecting REPL and reusing its classloader. */ - private lazy val primaryClassloader: ClassLoader = { + private lazy val macroClassloader: ClassLoader = { if (global.forMSIL) throw new UnsupportedOperationException("Scala reflection not available on this platform") - if (settings.XmacroPrimaryClasspath.value != "") { - macroLogVerbose("primary macro classloader: initializing from -Xmacro-primary-classpath: %s".format(settings.XmacroPrimaryClasspath.value)) - val classpath = toURLs(settings.XmacroPrimaryClasspath.value) - ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader) - } else { - macroLogVerbose("primary macro classloader: initializing from -cp: %s".format(global.classPath.asURLs)) - val classpath = global.classPath.asURLs - var loader: ClassLoader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader) - - // [Eugene] a heuristic to detect the REPL - if (global.settings.exposeEmptyPackage.value) { - macroLogVerbose("primary macro classloader: initializing from a REPL classloader".format(global.classPath.asURLs)) - import scala.tools.nsc.interpreter._ - val virtualDirectory = global.settings.outputDirs.getSingleOutput.get - loader = new AbstractFileClassLoader(virtualDirectory, loader) {} - } + val classpath = global.classPath.asURLs + macroLogVerbose("macro classloader: initializing from -cp: %s".format(classpath)) + val loader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader) + // [Eugene] a heuristic to detect the REPL + if (global.settings.exposeEmptyPackage.value) { + macroLogVerbose("macro classloader: initializing from a REPL classloader".format(global.classPath.asURLs)) + import scala.tools.nsc.interpreter._ + val virtualDirectory = global.settings.outputDirs.getSingleOutput.get + new AbstractFileClassLoader(virtualDirectory, loader) {} + } else { loader } } - /** Fallback classloader that is used to resolve and run macro implementations when `primaryClassloader` fails. - * Loads classes from -Xmacro-fallback-classpath. - */ - private lazy val fallbackClassloader: ClassLoader = { - if (global.forMSIL) - throw new UnsupportedOperationException("Scala reflection not available on this platform") - - macroLogVerbose("fallback macro classloader: initializing from -Xmacro-fallback-classpath: %s".format(settings.XmacroFallbackClasspath.value)) - val classpath = toURLs(settings.XmacroFallbackClasspath.value) - ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader) - } - /** Produces a function that can be used to invoke macro implementation for a given macro definition: * 1) Looks up macro implementation symbol in this universe. - * 2) Loads its enclosing class from the primary classloader. - * 3) Loads the companion of that enclosing class from the primary classloader. + * 2) Loads its enclosing class from the macro classloader. + * 3) Loads the companion of that enclosing class from the macro classloader. * 4) Resolves macro implementation within the loaded companion. - * 5) If 2-4 fails, repeats them for the fallback classloader. * * @return Some(runtime) if macro implementation can be loaded successfully from either of the mirrors, * None otherwise. @@ -742,25 +723,10 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { } } - val primary = loadMacroImpl(primaryClassloader) - primary match { - case Some((implObj, implMeth)) => + loadMacroImpl(macroClassloader) map { + case (implObj, implMeth) => def runtime(args: List[Any]) = implMeth.invoke(implObj, (args map (_.asInstanceOf[AnyRef])): _*).asInstanceOf[Any] - Some(runtime _) - case None => - if (settings.XmacroFallbackClasspath.value != "") { - macroLogVerbose("trying to load macro implementation from the fallback mirror: %s".format(settings.XmacroFallbackClasspath.value)) - val fallback = loadMacroImpl(fallbackClassloader) - fallback match { - case Some((implObj, implMeth)) => - def runtime(args: List[Any]) = implMeth.invoke(implObj, (args map (_.asInstanceOf[AnyRef])): _*).asInstanceOf[Any] - Some(runtime _) - case None => - None - } - } else { - None - } + runtime _ } } @@ -1147,9 +1113,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { val macroDef = expandee.symbol def notFound() = { typer.context.error(expandee.pos, "macro implementation not found: " + macroDef.name + " " + - "(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)\n" + - "if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath " + - "in the second phase pointing to the output of the first phase") + "(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)") None } def fallBackToOverridden(tree: Tree): Option[Tree] = { diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 50d470ccf5..44712ba286 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -988,16 +988,6 @@ trait Namers extends MethodSynthesis { // (either "macro ???" as they used to or just "???" to maximally simplify their compilation) if (fastTrack contains ddef.symbol) ddef.symbol setFlag MACRO - // macro defs need to be typechecked in advance - // because @macroImpl annotation only gets assigned during typechecking - // otherwise we might find ourselves in the situation when we specified -Xmacro-fallback-classpath - // but macros still don't expand - // that might happen because macro def doesn't have its link a macro impl yet - if (ddef.symbol.isTermMacro) { - val pt = resultPt.substSym(tparamSyms, tparams map (_.symbol)) - typer.computeMacroDefType(ddef, pt) - } - thisMethodType({ val rt = ( if (!tpt.isEmpty) { diff --git a/test/files/neg/macro-basic-mamdmi.check b/test/files/neg/macro-basic-mamdmi.check index eef444f7b3..67b00c0ec5 100644 --- a/test/files/neg/macro-basic-mamdmi.check +++ b/test/files/neg/macro-basic-mamdmi.check @@ -1,5 +1,4 @@ Impls_Macros_Test_1.scala:36: error: macro implementation not found: foo (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) -if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath in the second phase pointing to the output of the first phase println(foo(2) + Macros.bar(2) * new Macros().quux(4)) ^ one error found -- cgit v1.2.3 From a0a63c4558018a5e75149a45f7df775f731c26f1 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 24 Jul 2012 13:24:23 +0200 Subject: evicts last traces of makro from our codebase Removes the stubs left out to appease the old starr, fixes macro tests. --- src/library/scala/reflect/makro/internal/package.scala | 11 ----------- src/reflect/scala/reflect/makro/package.scala | 5 ----- .../files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala | 2 +- test/files/neg/macro-cyclic/Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidimpl-a/Impls_1.scala | 2 +- test/files/neg/macro-invalidimpl-b/Impls_1.scala | 2 +- test/files/neg/macro-invalidimpl-c/Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidimpl-d/Impls_1.scala | 2 +- test/files/neg/macro-invalidimpl-e.check | 8 ++++---- test/files/neg/macro-invalidimpl-e/Impls_1.scala | 2 +- test/files/neg/macro-invalidimpl-f.check | 14 +++++++------- test/files/neg/macro-invalidimpl-f/Impls_1.scala | 2 +- test/files/neg/macro-invalidimpl-g.check | 4 ++-- test/files/neg/macro-invalidimpl-g/Impls_1.scala | 2 +- test/files/neg/macro-invalidimpl-h/Impls_1.scala | 2 +- test/files/neg/macro-invalidret-nontree.check | 4 ++-- test/files/neg/macro-invalidret-nontree/Impls_1.scala | 2 +- test/files/neg/macro-invalidret-nonuniversetree.check | 4 ++-- .../neg/macro-invalidret-nonuniversetree/Impls_1.scala | 2 +- test/files/neg/macro-invalidshape-a/Impls_1.scala | 2 +- test/files/neg/macro-invalidshape-b/Impls_1.scala | 2 +- test/files/neg/macro-invalidshape-c/Impls_1.scala | 2 +- test/files/neg/macro-invalidshape-d/Impls_1.scala | 2 +- .../neg/macro-invalidsig-context-bounds/Impls_1.scala | 2 +- test/files/neg/macro-invalidsig-ctx-badargc.check | 14 +++++++------- test/files/neg/macro-invalidsig-ctx-badtype.check | 4 ++-- test/files/neg/macro-invalidsig-ctx-badvarargs.check | 14 +++++++------- .../neg/macro-invalidsig-ctx-badvarargs/Impls_1.scala | 2 +- test/files/neg/macro-invalidsig-ctx-noctx.check | 14 +++++++------- test/files/neg/macro-invalidsig-ctx-noctx/Impls_1.scala | 2 +- .../macro-invalidsig-implicit-params/Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidsig-params-badargc.check | 14 +++++++------- .../macro-invalidsig-params-badargc/Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidsig-params-badtype.check | 4 ++-- .../macro-invalidsig-params-badtype/Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidsig-params-badvarargs.check | 14 +++++++------- .../Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidsig-params-namemismatch.check | 14 +++++++------- .../Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidsig-tparams-badtype.check | 4 ++-- .../neg/macro-invalidsig-tparams-badtype/Impls_1.scala | 2 +- .../neg/macro-invalidsig-tparams-bounds-a/Impls_1.scala | 2 +- .../neg/macro-invalidsig-tparams-bounds-b/Impls_1.scala | 2 +- .../neg/macro-invalidsig-tparams-notparams-a/Impls_1.scala | 2 +- .../neg/macro-invalidsig-tparams-notparams-b/Impls_1.scala | 2 +- test/files/neg/macro-invalidsig-tparams-notparams-c.check | 2 +- .../neg/macro-invalidsig-tparams-notparams-c/Impls_1.scala | 2 +- test/files/neg/macro-invalidusage-badargs/Impls_1.scala | 2 +- test/files/neg/macro-invalidusage-badbounds/Impls_1.scala | 2 +- test/files/neg/macro-invalidusage-badtargs/Impls_1.scala | 2 +- .../neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala | 2 +- test/files/neg/macro-noexpand/Impls_1.scala | 2 +- test/files/neg/macro-nontypeablebody/Impls_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../macro-override-method-overrides-macro/Impls_1.scala | 2 +- test/files/neg/macro-without-xmacros-a/Impls_1.scala | 2 +- test/files/neg/macro-without-xmacros-b/Impls_1.scala | 2 +- test/files/neg/t5689.check | 4 ++-- test/files/neg/t5689.scala | 2 +- test/files/pos/t5706.scala | 2 +- test/files/pos/t6047.scala | 2 +- test/files/run/macro-abort-fresh/Macros_1.scala | 2 +- test/files/run/macro-basic-ma-md-mi/Impls_1.scala | 2 +- test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala | 2 +- test/files/run/macro-basic-mamd-mi/Impls_1.scala | 2 +- test/files/run/macro-bodyexpandstoimpl/Impls_1.scala | 2 +- test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala | 2 +- test/files/run/macro-declared-in-annotation/Impls_1.scala | 2 +- test/files/run/macro-declared-in-anonymous/Impls_1.scala | 2 +- test/files/run/macro-declared-in-block/Impls_1.scala | 2 +- test/files/run/macro-declared-in-class-class/Impls_1.scala | 2 +- .../files/run/macro-declared-in-class-object/Impls_1.scala | 2 +- test/files/run/macro-declared-in-class/Impls_1.scala | 2 +- .../run/macro-declared-in-default-param/Impls_1.scala | 2 +- .../macro-declared-in-implicit-class/Impls_Macros_1.scala | 2 +- test/files/run/macro-declared-in-method/Impls_1.scala | 2 +- .../files/run/macro-declared-in-object-class/Impls_1.scala | 2 +- .../run/macro-declared-in-object-object/Impls_1.scala | 2 +- test/files/run/macro-declared-in-object/Impls_1.scala | 2 +- .../run/macro-declared-in-package-object/Impls_1.scala | 2 +- test/files/run/macro-declared-in-refinement/Impls_1.scala | 2 +- test/files/run/macro-declared-in-trait/Impls_1.scala | 2 +- test/files/run/macro-def-infer-return-type-a/Impls_1.scala | 2 +- .../run/macro-def-infer-return-type-b/Impls_Macros_1.scala | 2 +- test/files/run/macro-def-infer-return-type-c/Impls_1.scala | 2 +- .../run/macro-def-path-dependent-a/Impls_Macros_1.scala | 2 +- .../run/macro-def-path-dependent-b/Impls_Macros_1.scala | 2 +- .../run/macro-def-path-dependent-c/Impls_Macros_1.scala | 2 +- .../run/macro-def-path-dependent-d/Impls_Macros_1.scala | 2 +- .../macro-expand-implicit-macro-has-implicit/Impls_1.scala | 2 +- .../macro-expand-implicit-macro-is-implicit/Impls_1.scala | 2 +- .../run/macro-expand-implicit-macro-is-val/Impls_1.scala | 2 +- .../run/macro-expand-implicit-macro-is-view/Impls_1.scala | 2 +- .../files/run/macro-expand-multiple-arglists/Impls_1.scala | 2 +- test/files/run/macro-expand-nullary-generic/Impls_1.scala | 2 +- .../run/macro-expand-nullary-nongeneric/Impls_1.scala | 2 +- test/files/run/macro-expand-overload/Impls_1.scala | 2 +- test/files/run/macro-expand-override/Impls_1.scala | 2 +- test/files/run/macro-expand-recursive/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-bounds-a/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-bounds-b/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-explicit/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-implicit/Impls_1.scala | 2 +- .../run/macro-expand-tparams-only-in-impl/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-optional/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-prefix-a/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-prefix-b/Impls_1.scala | 2 +- .../files/run/macro-expand-tparams-prefix-c1/Impls_1.scala | 2 +- .../macro-expand-tparams-prefix-c2/Impls_Macros_1.scala | 2 +- .../files/run/macro-expand-tparams-prefix-d1/Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../run/macro-impl-default-params/Impls_Macros_1.scala | 2 +- .../run/macro-impl-rename-context/Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../run/macro-invalidret-nontypeable/Impls_Macros_1.scala | 2 +- .../run/macro-invalidusage-badret/Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- test/files/run/macro-openmacros/Impls_Macros_1.scala | 2 +- .../run/macro-quasiinvalidbody-c/Impls_Macros_1.scala | 2 +- test/files/run/macro-range/Common_1.scala | 2 +- test/files/run/macro-range/Expansion_Impossible_2.scala | 2 +- .../macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala | 2 +- .../run/macro-reflective-mamd-normal-mi/Impls_1.scala | 2 +- test/files/run/macro-reify-basic/Macros_1.scala | 2 +- test/files/run/macro-reify-freevars/Macros_1.scala | 2 +- test/files/run/macro-reify-nested-a/Impls_Macros_1.scala | 4 ++-- test/files/run/macro-reify-nested-b/Impls_Macros_1.scala | 4 ++-- .../files/run/macro-reify-ref-to-packageless/Impls_1.scala | 2 +- .../macro-reify-splice-outside-reify/Impls_Macros_1.scala | 2 +- test/files/run/macro-reify-splice-splice/Macros_1.scala | 2 +- test/files/run/macro-reify-staticXXX/Macros_1.scala | 2 +- test/files/run/macro-reify-tagful-a/Macros_1.scala | 2 +- test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala | 2 +- test/files/run/macro-reify-unreify/Macros_1.scala | 2 +- test/files/run/macro-repl-basic.check | 4 ++-- test/files/run/macro-repl-basic.scala | 2 +- test/files/run/macro-repl-dontexpand.check | 4 ++-- test/files/run/macro-repl-dontexpand.scala | 2 +- test/files/run/macro-settings/Impls_Macros_1.scala | 2 +- test/files/run/macro-sip19-revised/Impls_Macros_1.scala | 2 +- test/files/run/macro-sip19/Impls_Macros_1.scala | 2 +- .../macro-typecheck-implicitsdisabled/Impls_Macros_1.scala | 2 +- .../macro-typecheck-macrosdisabled/Impls_Macros_1.scala | 2 +- .../macro-typecheck-macrosdisabled2/Impls_Macros_1.scala | 2 +- .../run/macro-undetparams-consfromsls/Impls_Macros_1.scala | 2 +- .../run/macro-undetparams-macroitself/Impls_Macros_1.scala | 2 +- test/files/run/t5713/Impls_Macros_1.scala | 2 +- test/pending/run/macro-expand-default/Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../run/macro-expand-macro-has-context-bound/Impls_1.scala | 2 +- test/pending/run/macro-expand-named/Impls_1.scala | 2 +- .../run/macro-expand-tparams-prefix-e1/Impls_1.scala | 2 +- .../run/macro-expand-tparams-prefix-f1/Impls_1.scala | 2 +- test/pending/run/macro-quasiinvalidbody-a/Impls_1.scala | 2 +- .../run/macro-quasiinvalidbody-a/Macros_Test_2.scala | 2 +- test/pending/run/macro-quasiinvalidbody-b/Impls_1.scala | 2 +- .../run/macro-quasiinvalidbody-b/Macros_Test_2.scala | 2 +- test/pending/run/macro-reify-array/Macros_1.scala | 2 +- test/pending/run/macro-reify-tagful-b/Macros_1.scala | 2 +- .../pending/run/macro-reify-tagless-b/Impls_Macros_1.scala | 2 +- test/pending/run/t5692/Impls_Macros_1.scala | 4 ++-- 167 files changed, 222 insertions(+), 238 deletions(-) delete mode 100644 src/library/scala/reflect/makro/internal/package.scala delete mode 100644 src/reflect/scala/reflect/makro/package.scala (limited to 'test/files') diff --git a/src/library/scala/reflect/makro/internal/package.scala b/src/library/scala/reflect/makro/internal/package.scala deleted file mode 100644 index b8097d84e3..0000000000 --- a/src/library/scala/reflect/makro/internal/package.scala +++ /dev/null @@ -1,11 +0,0 @@ -package scala.reflect -package makro - -import scala.reflect.base.{Universe => BaseUniverse} - -package object internal { - private[scala] type macroImpl = scala.reflect.macros.internal.macroImpl - private[scala] def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = ??? // macro - private[scala] def materializeAbsTypeTag[T](u: BaseUniverse): u.AbsTypeTag[T] = ??? // macro - private[scala] def materializeTypeTag[T](u: BaseUniverse): u.TypeTag[T] = ??? // macro -} diff --git a/src/reflect/scala/reflect/makro/package.scala b/src/reflect/scala/reflect/makro/package.scala deleted file mode 100644 index f5868eab18..0000000000 --- a/src/reflect/scala/reflect/makro/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package scala.reflect - -package object makro { - type Context = scala.reflect.macros.Context -} \ No newline at end of file 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 8abde907bb..908438cf65 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 @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/neg/macro-cyclic/Impls_Macros_1.scala b/test/files/neg/macro-cyclic/Impls_Macros_1.scala index 2ecdc3416e..ac9b7938db 100644 --- a/test/files/neg/macro-cyclic/Impls_Macros_1.scala +++ b/test/files/neg/macro-cyclic/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl(c: Context) = { diff --git a/test/files/neg/macro-invalidimpl-a/Impls_1.scala b/test/files/neg/macro-invalidimpl-a/Impls_1.scala index c2f1843b8b..cfa1218038 100644 --- a/test/files/neg/macro-invalidimpl-a/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} class Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidimpl-b/Impls_1.scala b/test/files/neg/macro-invalidimpl-b/Impls_1.scala index 7b1620d117..4467021545 100644 --- a/test/files/neg/macro-invalidimpl-b/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl-b/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidimpl-c/Impls_Macros_1.scala b/test/files/neg/macro-invalidimpl-c/Impls_Macros_1.scala index 657e2d4260..67a0eb348b 100644 --- a/test/files/neg/macro-invalidimpl-c/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidimpl-c/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} class Macros { object Impls { diff --git a/test/files/neg/macro-invalidimpl-d/Impls_1.scala b/test/files/neg/macro-invalidimpl-d/Impls_1.scala index f18e699a1e..e0819c938c 100644 --- a/test/files/neg/macro-invalidimpl-d/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl-d/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} trait MacroHelpers { object Impls { diff --git a/test/files/neg/macro-invalidimpl-e.check b/test/files/neg/macro-invalidimpl-e.check index 61d1e05b87..5cfcf85625 100644 --- a/test/files/neg/macro-invalidimpl-e.check +++ b/test/files/neg/macro-invalidimpl-e.check @@ -1,12 +1,12 @@ Macros_Test_2.scala:2: error: ambiguous reference to overloaded definition, -both method foo in object Impls of type (c: scala.reflect.makro.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing -and method foo in object Impls of type (c: scala.reflect.makro.Context)(x: c.Expr[Any])Nothing +both method foo in object Impls of type (c: scala.reflect.macros.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing +and method foo in object Impls of type (c: scala.reflect.macros.Context)(x: c.Expr[Any])Nothing match expected type ? def foo(x: Any) = macro Impls.foo ^ Macros_Test_2.scala:3: error: ambiguous reference to overloaded definition, -both method foo in object Impls of type (c: scala.reflect.makro.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing -and method foo in object Impls of type (c: scala.reflect.makro.Context)(x: c.Expr[Any])Nothing +both method foo in object Impls of type (c: scala.reflect.macros.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing +and method foo in object Impls of type (c: scala.reflect.macros.Context)(x: c.Expr[Any])Nothing match expected type ? def foo(x: Any, y: Any) = macro Impls.foo ^ diff --git a/test/files/neg/macro-invalidimpl-e/Impls_1.scala b/test/files/neg/macro-invalidimpl-e/Impls_1.scala index ad3eed5cd5..fd40119c31 100644 --- a/test/files/neg/macro-invalidimpl-e/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl-e/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidimpl-f.check b/test/files/neg/macro-invalidimpl-f.check index ec82faa58c..14f1e25287 100644 --- a/test/files/neg/macro-invalidimpl-f.check +++ b/test/files/neg/macro-invalidimpl-f.check @@ -1,7 +1,7 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context)(): c.Expr[Unit] - found : (c: scala.reflect.makro.Context): c.Expr[Unit] -number of parameter sections differ - def bar1() = macro Impls.fooNullary - ^ -one error found +Macros_Test_2.scala:2: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context)(): c.Expr[Unit] + found : (c: scala.reflect.macros.Context): c.Expr[Unit] +number of parameter sections differ + def bar1() = macro Impls.fooNullary + ^ +one error found diff --git a/test/files/neg/macro-invalidimpl-f/Impls_1.scala b/test/files/neg/macro-invalidimpl-f/Impls_1.scala index 3b8f15b90c..334ee714be 100644 --- a/test/files/neg/macro-invalidimpl-f/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl-f/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def fooNullary(c: Ctx) = { diff --git a/test/files/neg/macro-invalidimpl-g.check b/test/files/neg/macro-invalidimpl-g.check index 9c01f01dc8..a886436d35 100644 --- a/test/files/neg/macro-invalidimpl-g.check +++ b/test/files/neg/macro-invalidimpl-g.check @@ -1,6 +1,6 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context): c.Expr[Unit] - found : (c: scala.reflect.makro.Context)(): c.Expr[Unit] + required: (c: scala.reflect.macros.Context): c.Expr[Unit] + found : (c: scala.reflect.macros.Context)(): c.Expr[Unit] number of parameter sections differ def foo1 = macro Impls.fooEmpty ^ diff --git a/test/files/neg/macro-invalidimpl-g/Impls_1.scala b/test/files/neg/macro-invalidimpl-g/Impls_1.scala index 3b8f15b90c..334ee714be 100644 --- a/test/files/neg/macro-invalidimpl-g/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl-g/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def fooNullary(c: Ctx) = { diff --git a/test/files/neg/macro-invalidimpl-h/Impls_1.scala b/test/files/neg/macro-invalidimpl-h/Impls_1.scala index 7db8bcd324..427fd3d5c0 100644 --- a/test/files/neg/macro-invalidimpl-h/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl-h/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U <: Int](c: Ctx) = ??? diff --git a/test/files/neg/macro-invalidret-nontree.check b/test/files/neg/macro-invalidret-nontree.check index 0b793cf421..78ab08df3e 100644 --- a/test/files/neg/macro-invalidret-nontree.check +++ b/test/files/neg/macro-invalidret-nontree.check @@ -1,6 +1,6 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context): c.Expr[Any] - found : (c: scala.reflect.makro.Context): Int + required: (c: scala.reflect.macros.Context): c.Expr[Any] + found : (c: scala.reflect.macros.Context): Int type mismatch for return type: Int does not conform to c.Expr[Any] def foo = macro Impls.foo ^ diff --git a/test/files/neg/macro-invalidret-nontree/Impls_1.scala b/test/files/neg/macro-invalidret-nontree/Impls_1.scala index efc8d4bfec..ef19b1b405 100644 --- a/test/files/neg/macro-invalidret-nontree/Impls_1.scala +++ b/test/files/neg/macro-invalidret-nontree/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = 2 diff --git a/test/files/neg/macro-invalidret-nonuniversetree.check b/test/files/neg/macro-invalidret-nonuniversetree.check index 1b9487982f..09df2c0a92 100644 --- a/test/files/neg/macro-invalidret-nonuniversetree.check +++ b/test/files/neg/macro-invalidret-nonuniversetree.check @@ -1,6 +1,6 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context): c.Expr[Any] - found : (c: scala.reflect.makro.Context): reflect.basis.Literal + required: (c: scala.reflect.macros.Context): c.Expr[Any] + found : (c: scala.reflect.macros.Context): reflect.basis.Literal type mismatch for return type: reflect.basis.Literal does not conform to c.Expr[Any] def foo = macro Impls.foo ^ diff --git a/test/files/neg/macro-invalidret-nonuniversetree/Impls_1.scala b/test/files/neg/macro-invalidret-nonuniversetree/Impls_1.scala index da0eb0ac83..8311d474c2 100644 --- a/test/files/neg/macro-invalidret-nonuniversetree/Impls_1.scala +++ b/test/files/neg/macro-invalidret-nonuniversetree/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = scala.reflect.basis.Literal(scala.reflect.basis.Constant(42)) diff --git a/test/files/neg/macro-invalidshape-a/Impls_1.scala b/test/files/neg/macro-invalidshape-a/Impls_1.scala index 7b1620d117..4467021545 100644 --- a/test/files/neg/macro-invalidshape-a/Impls_1.scala +++ b/test/files/neg/macro-invalidshape-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidshape-b/Impls_1.scala b/test/files/neg/macro-invalidshape-b/Impls_1.scala index 7b1620d117..4467021545 100644 --- a/test/files/neg/macro-invalidshape-b/Impls_1.scala +++ b/test/files/neg/macro-invalidshape-b/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidshape-c/Impls_1.scala b/test/files/neg/macro-invalidshape-c/Impls_1.scala index 7b1620d117..4467021545 100644 --- a/test/files/neg/macro-invalidshape-c/Impls_1.scala +++ b/test/files/neg/macro-invalidshape-c/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidshape-d/Impls_1.scala b/test/files/neg/macro-invalidshape-d/Impls_1.scala index 7b1620d117..4467021545 100644 --- a/test/files/neg/macro-invalidshape-d/Impls_1.scala +++ b/test/files/neg/macro-invalidshape-d/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidsig-context-bounds/Impls_1.scala b/test/files/neg/macro-invalidsig-context-bounds/Impls_1.scala index 2eef7aac8b..633981ce19 100644 --- a/test/files/neg/macro-invalidsig-context-bounds/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-context-bounds/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U: c.TypeTag: Numeric](c: Ctx) = { diff --git a/test/files/neg/macro-invalidsig-ctx-badargc.check b/test/files/neg/macro-invalidsig-ctx-badargc.check index 1e1621ab61..8a1ca6a8b1 100644 --- a/test/files/neg/macro-invalidsig-ctx-badargc.check +++ b/test/files/neg/macro-invalidsig-ctx-badargc.check @@ -1,7 +1,7 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context): c.Expr[Any] - found : : Nothing -number of parameter sections differ - def foo = macro Impls.foo - ^ -one error found +Macros_Test_2.scala:2: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context): c.Expr[Any] + found : : Nothing +number of parameter sections differ + def foo = macro Impls.foo + ^ +one error found diff --git a/test/files/neg/macro-invalidsig-ctx-badtype.check b/test/files/neg/macro-invalidsig-ctx-badtype.check index b1702bbca6..9e57ab8631 100644 --- a/test/files/neg/macro-invalidsig-ctx-badtype.check +++ b/test/files/neg/macro-invalidsig-ctx-badtype.check @@ -1,7 +1,7 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context): c.Expr[Any] + required: (c: scala.reflect.macros.Context): c.Expr[Any] found : (c: scala.reflect.api.Universe): Nothing -type mismatch for parameter c: scala.reflect.makro.Context does not conform to scala.reflect.api.Universe +type mismatch for parameter c: scala.reflect.macros.Context does not conform to scala.reflect.api.Universe def foo = macro Impls.foo ^ one error found diff --git a/test/files/neg/macro-invalidsig-ctx-badvarargs.check b/test/files/neg/macro-invalidsig-ctx-badvarargs.check index 18e3d6201f..37941a7dc9 100644 --- a/test/files/neg/macro-invalidsig-ctx-badvarargs.check +++ b/test/files/neg/macro-invalidsig-ctx-badvarargs.check @@ -1,7 +1,7 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context): c.Expr[Any] - found : (cs: scala.reflect.makro.Context*): Nothing -types incompatible for parameter cs: corresponding is not a vararg parameter - def foo = macro Impls.foo - ^ -one error found +Macros_Test_2.scala:2: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context): c.Expr[Any] + found : (cs: scala.reflect.macros.Context*): Nothing +types incompatible for parameter cs: corresponding is not a vararg parameter + def foo = macro Impls.foo + ^ +one error found diff --git a/test/files/neg/macro-invalidsig-ctx-badvarargs/Impls_1.scala b/test/files/neg/macro-invalidsig-ctx-badvarargs/Impls_1.scala index b2fb2539ec..c4ed8be91e 100644 --- a/test/files/neg/macro-invalidsig-ctx-badvarargs/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-ctx-badvarargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(cs: Ctx*) = ??? diff --git a/test/files/neg/macro-invalidsig-ctx-noctx.check b/test/files/neg/macro-invalidsig-ctx-noctx.check index 66fa7c3514..722fe9dfb6 100644 --- a/test/files/neg/macro-invalidsig-ctx-noctx.check +++ b/test/files/neg/macro-invalidsig-ctx-noctx.check @@ -1,7 +1,7 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context)(x: c.Expr[Any]): c.Expr[Any] - found : (c: scala.reflect.makro.Context): Nothing -number of parameter sections differ - def foo(x: Any) = macro Impls.foo - ^ -one error found +Macros_Test_2.scala:2: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context)(x: c.Expr[Any]): c.Expr[Any] + found : (c: scala.reflect.macros.Context): Nothing +number of parameter sections differ + def foo(x: Any) = macro Impls.foo + ^ +one error found diff --git a/test/files/neg/macro-invalidsig-ctx-noctx/Impls_1.scala b/test/files/neg/macro-invalidsig-ctx-noctx/Impls_1.scala index 1e0ed755af..6904cfb1dc 100644 --- a/test/files/neg/macro-invalidsig-ctx-noctx/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-ctx-noctx/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = ??? diff --git a/test/files/neg/macro-invalidsig-implicit-params/Impls_Macros_1.scala b/test/files/neg/macro-invalidsig-implicit-params/Impls_Macros_1.scala index 5bfe73ec59..b32a20ba06 100644 --- a/test/files/neg/macro-invalidsig-implicit-params/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidsig-implicit-params/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo_targs[T, U: c.TypeTag](c: Ctx)(implicit x: c.Expr[Int]) = { diff --git a/test/files/neg/macro-invalidsig-params-badargc.check b/test/files/neg/macro-invalidsig-params-badargc.check index 6de8c5e95a..ab4fb535c5 100644 --- a/test/files/neg/macro-invalidsig-params-badargc.check +++ b/test/files/neg/macro-invalidsig-params-badargc.check @@ -1,7 +1,7 @@ -Impls_Macros_1.scala:8: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context)(x: c.Expr[Int]): c.Expr[Any] - found : (c: scala.reflect.makro.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 Impls.foo - ^ -one error found +Impls_Macros_1.scala:8: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] + 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 Impls.foo + ^ +one error found diff --git a/test/files/neg/macro-invalidsig-params-badargc/Impls_Macros_1.scala b/test/files/neg/macro-invalidsig-params-badargc/Impls_Macros_1.scala index 4b449f35ed..ae16612b93 100644 --- a/test/files/neg/macro-invalidsig-params-badargc/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidsig-params-badargc/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int], y: c.Expr[Int]) = ??? diff --git a/test/files/neg/macro-invalidsig-params-badtype.check b/test/files/neg/macro-invalidsig-params-badtype.check index e4f67e650a..007620a366 100644 --- a/test/files/neg/macro-invalidsig-params-badtype.check +++ b/test/files/neg/macro-invalidsig-params-badtype.check @@ -1,6 +1,6 @@ Impls_Macros_1.scala:8: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context)(x: c.Expr[Int]): c.Expr[Any] - found : (c: scala.reflect.makro.Context)(x: c.universe.Tree): Nothing + required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] + found : (c: scala.reflect.macros.Context)(x: c.universe.Tree): Nothing type mismatch for parameter x: c.Expr[Int] does not conform to c.universe.Tree def foo(x: Int) = macro Impls.foo ^ diff --git a/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala b/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala index 6393e6d395..ab90b85881 100644 --- a/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.universe.Tree) = ??? diff --git a/test/files/neg/macro-invalidsig-params-badvarargs.check b/test/files/neg/macro-invalidsig-params-badvarargs.check index 0827680299..f0dcc24d03 100644 --- a/test/files/neg/macro-invalidsig-params-badvarargs.check +++ b/test/files/neg/macro-invalidsig-params-badvarargs.check @@ -1,7 +1,7 @@ -Impls_Macros_1.scala:8: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] - found : (c: scala.reflect.makro.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 Impls.foo - ^ -one error found +Impls_Macros_1.scala:8: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + 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 Impls.foo + ^ +one error found diff --git a/test/files/neg/macro-invalidsig-params-badvarargs/Impls_Macros_1.scala b/test/files/neg/macro-invalidsig-params-badvarargs/Impls_Macros_1.scala index 2ee1c2767c..b4c75ad0ba 100644 --- a/test/files/neg/macro-invalidsig-params-badvarargs/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidsig-params-badvarargs/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(xs: c.Expr[Int]*) = ??? diff --git a/test/files/neg/macro-invalidsig-params-namemismatch.check b/test/files/neg/macro-invalidsig-params-namemismatch.check index ca7270cca8..00d781a2ac 100644 --- a/test/files/neg/macro-invalidsig-params-namemismatch.check +++ b/test/files/neg/macro-invalidsig-params-namemismatch.check @@ -1,7 +1,7 @@ -Impls_Macros_1.scala:8: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] - found : (c: scala.reflect.makro.Context)(y: c.Expr[Int], x: c.Expr[Int]): Nothing -parameter names differ: x != y - def foo(x: Int, y: Int) = macro Impls.foo - ^ -one error found +Impls_Macros_1.scala:8: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + 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 Impls.foo + ^ +one error found diff --git a/test/files/neg/macro-invalidsig-params-namemismatch/Impls_Macros_1.scala b/test/files/neg/macro-invalidsig-params-namemismatch/Impls_Macros_1.scala index 89c5347647..c7cf0b06c4 100644 --- a/test/files/neg/macro-invalidsig-params-namemismatch/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidsig-params-namemismatch/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(y: c.Expr[Int], x: c.Expr[Int]) = ??? diff --git a/test/files/neg/macro-invalidsig-tparams-badtype.check b/test/files/neg/macro-invalidsig-tparams-badtype.check index 9166db3574..e5e8366ba4 100644 --- a/test/files/neg/macro-invalidsig-tparams-badtype.check +++ b/test/files/neg/macro-invalidsig-tparams-badtype.check @@ -1,6 +1,6 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context): c.Expr[Any] - found : (c: scala.reflect.makro.Context)(U: c.universe.Type): Nothing + required: (c: scala.reflect.macros.Context): c.Expr[Any] + found : (c: scala.reflect.macros.Context)(U: c.universe.Type): Nothing number of parameter sections differ def foo[U] = macro Impls.foo[U] ^ diff --git a/test/files/neg/macro-invalidsig-tparams-badtype/Impls_1.scala b/test/files/neg/macro-invalidsig-tparams-badtype/Impls_1.scala index 9886331502..dbeca178a7 100644 --- a/test/files/neg/macro-invalidsig-tparams-badtype/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-tparams-badtype/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U](c: Ctx)(U: c.universe.Type) = ??? diff --git a/test/files/neg/macro-invalidsig-tparams-bounds-a/Impls_1.scala b/test/files/neg/macro-invalidsig-tparams-bounds-a/Impls_1.scala index 88b85d48f4..89020de7dd 100644 --- a/test/files/neg/macro-invalidsig-tparams-bounds-a/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-tparams-bounds-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U <: String](c: Ctx) = ??? diff --git a/test/files/neg/macro-invalidsig-tparams-bounds-b/Impls_1.scala b/test/files/neg/macro-invalidsig-tparams-bounds-b/Impls_1.scala index 88b85d48f4..89020de7dd 100644 --- a/test/files/neg/macro-invalidsig-tparams-bounds-b/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-tparams-bounds-b/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U <: String](c: Ctx) = ??? diff --git a/test/files/neg/macro-invalidsig-tparams-notparams-a/Impls_1.scala b/test/files/neg/macro-invalidsig-tparams-notparams-a/Impls_1.scala index ea472e6f91..98a3a6db7c 100644 --- a/test/files/neg/macro-invalidsig-tparams-notparams-a/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-tparams-notparams-a/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U: c.TypeTag](c: Ctx) = ??? diff --git a/test/files/neg/macro-invalidsig-tparams-notparams-b/Impls_1.scala b/test/files/neg/macro-invalidsig-tparams-notparams-b/Impls_1.scala index c4eb3d9b4a..dbc7000485 100644 --- a/test/files/neg/macro-invalidsig-tparams-notparams-b/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-tparams-notparams-b/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T: c.TypeTag, U: c.TypeTag, V](c: Ctx)(implicit V: c.TypeTag[V]): c.Expr[Unit] = { diff --git a/test/files/neg/macro-invalidsig-tparams-notparams-c.check b/test/files/neg/macro-invalidsig-tparams-notparams-c.check index b64a469cc3..e3e17c7506 100644 --- a/test/files/neg/macro-invalidsig-tparams-notparams-c.check +++ b/test/files/neg/macro-invalidsig-tparams-notparams-c.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:3: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.makro.Context)(implicit evidence$1: c.TypeTag[T], implicit evidence$2: c.TypeTag[U], implicit V: c.TypeTag[V])c.Expr[Unit] +Macros_Test_2.scala:3: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.Context)(implicit evidence$1: c.TypeTag[T], implicit evidence$2: c.TypeTag[U], implicit V: c.TypeTag[V])c.Expr[Unit] def foo[V] = macro Impls.foo[V] ^ one error found diff --git a/test/files/neg/macro-invalidsig-tparams-notparams-c/Impls_1.scala b/test/files/neg/macro-invalidsig-tparams-notparams-c/Impls_1.scala index 41facc881e..3edadb115d 100644 --- a/test/files/neg/macro-invalidsig-tparams-notparams-c/Impls_1.scala +++ b/test/files/neg/macro-invalidsig-tparams-notparams-c/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T: c.TypeTag, U: c.TypeTag, V](c: Ctx)(implicit V: c.TypeTag[V]): c.Expr[Unit] = { diff --git a/test/files/neg/macro-invalidusage-badargs/Impls_1.scala b/test/files/neg/macro-invalidusage-badargs/Impls_1.scala index 2346a6106d..52c9f9c3e9 100644 --- a/test/files/neg/macro-invalidusage-badargs/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-badargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala b/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala index 88b85d48f4..89020de7dd 100644 --- a/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U <: String](c: Ctx) = ??? diff --git a/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala b/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala index 2346a6106d..52c9f9c3e9 100644 --- a/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala b/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala index 31e758e9a0..8d7fdf3e8a 100644 --- a/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/neg/macro-noexpand/Impls_1.scala b/test/files/neg/macro-noexpand/Impls_1.scala index 7b1620d117..4467021545 100644 --- a/test/files/neg/macro-noexpand/Impls_1.scala +++ b/test/files/neg/macro-noexpand/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-nontypeablebody/Impls_1.scala b/test/files/neg/macro-nontypeablebody/Impls_1.scala index 7b1620d117..4467021545 100644 --- a/test/files/neg/macro-nontypeablebody/Impls_1.scala +++ b/test/files/neg/macro-nontypeablebody/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala b/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala index cb0b152852..e43264f52f 100644 --- a/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala +++ b/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def impl(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala index cb0b152852..e43264f52f 100644 --- a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala +++ b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def impl(c: Ctx)(x: c.Expr[Int]) = x 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 d6493caad9..ec93dd4111 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 @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def impl(c: Ctx)(tag: String, x: c.Expr[_]) = { 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 0b6fbe240e..8976f8e28d 100644 --- a/test/files/neg/macro-without-xmacros-a/Impls_1.scala +++ b/test/files/neg/macro-without-xmacros-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { 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 0b6fbe240e..8976f8e28d 100644 --- a/test/files/neg/macro-without-xmacros-b/Impls_1.scala +++ b/test/files/neg/macro-without-xmacros-b/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/neg/t5689.check b/test/files/neg/t5689.check index 6abc4c13f6..3b25dd612e 100644 --- a/test/files/neg/t5689.check +++ b/test/files/neg/t5689.check @@ -1,6 +1,6 @@ t5689.scala:4: error: macro implementation has wrong shape: - required: (c: scala.reflect.makro.Context)(i: c.Expr[Double]): c.Expr[String] - found : (c: scala.reflect.makro.Context)(i: c.Expr[Double]): c.Expr[Int] + required: (c: scala.reflect.macros.Context)(i: c.Expr[Double]): c.Expr[String] + 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/t5689.scala b/test/files/neg/t5689.scala index ef7a45b364..3266039c35 100644 --- a/test/files/neg/t5689.scala +++ b/test/files/neg/t5689.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def returnsString(i: Double): String = macro returnsIntImpl diff --git a/test/files/pos/t5706.scala b/test/files/pos/t5706.scala index 847acb693f..20a8b255cc 100644 --- a/test/files/pos/t5706.scala +++ b/test/files/pos/t5706.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context class Logger { def error(message: String) = macro Impls.error diff --git a/test/files/pos/t6047.scala b/test/files/pos/t6047.scala index 66b52b285f..edabb95ee3 100644 --- a/test/files/pos/t6047.scala +++ b/test/files/pos/t6047.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context import java.io.InputStream object Macros { diff --git a/test/files/run/macro-abort-fresh/Macros_1.scala b/test/files/run/macro-abort-fresh/Macros_1.scala index 440d1e2915..af1e292588 100644 --- a/test/files/run/macro-abort-fresh/Macros_1.scala +++ b/test/files/run/macro-abort-fresh/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Impls { def impl(c: Context) = { diff --git a/test/files/run/macro-basic-ma-md-mi/Impls_1.scala b/test/files/run/macro-basic-ma-md-mi/Impls_1.scala index 039488ba3e..646634c972 100644 --- a/test/files/run/macro-basic-ma-md-mi/Impls_1.scala +++ b/test/files/run/macro-basic-ma-md-mi/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala b/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala index 6e1e37a485..aa1e52e4aa 100644 --- a/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala +++ b/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/run/macro-basic-mamd-mi/Impls_1.scala b/test/files/run/macro-basic-mamd-mi/Impls_1.scala index 96d26741f7..061aa2d4a3 100644 --- a/test/files/run/macro-basic-mamd-mi/Impls_1.scala +++ b/test/files/run/macro-basic-mamd-mi/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala index 7de1e59cc7..0ca0be5a48 100644 --- a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala +++ b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala b/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala index 2934201a16..b589d4be03 100644 --- a/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala +++ b/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo(x: Int) = macro Impls.refToFoo(42) diff --git a/test/files/run/macro-declared-in-annotation/Impls_1.scala b/test/files/run/macro-declared-in-annotation/Impls_1.scala index 2b309e1cc8..a11ee2907a 100644 --- a/test/files/run/macro-declared-in-annotation/Impls_1.scala +++ b/test/files/run/macro-declared-in-annotation/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-anonymous/Impls_1.scala b/test/files/run/macro-declared-in-anonymous/Impls_1.scala index d95dbd42c6..6f06f6d3f0 100644 --- a/test/files/run/macro-declared-in-anonymous/Impls_1.scala +++ b/test/files/run/macro-declared-in-anonymous/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-block/Impls_1.scala b/test/files/run/macro-declared-in-block/Impls_1.scala index d95dbd42c6..6f06f6d3f0 100644 --- a/test/files/run/macro-declared-in-block/Impls_1.scala +++ b/test/files/run/macro-declared-in-block/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-class-class/Impls_1.scala b/test/files/run/macro-declared-in-class-class/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-class-class/Impls_1.scala +++ b/test/files/run/macro-declared-in-class-class/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-class-object/Impls_1.scala b/test/files/run/macro-declared-in-class-object/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-class-object/Impls_1.scala +++ b/test/files/run/macro-declared-in-class-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-class/Impls_1.scala b/test/files/run/macro-declared-in-class/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-class/Impls_1.scala +++ b/test/files/run/macro-declared-in-class/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-default-param/Impls_1.scala b/test/files/run/macro-declared-in-default-param/Impls_1.scala index 5e7351e954..db1e5c7435 100644 --- a/test/files/run/macro-declared-in-default-param/Impls_1.scala +++ b/test/files/run/macro-declared-in-default-param/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-implicit-class/Impls_Macros_1.scala b/test/files/run/macro-declared-in-implicit-class/Impls_Macros_1.scala index e5fb4bcdf3..d506de4252 100644 --- a/test/files/run/macro-declared-in-implicit-class/Impls_Macros_1.scala +++ b/test/files/run/macro-declared-in-implicit-class/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def toOptionOfInt(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-method/Impls_1.scala b/test/files/run/macro-declared-in-method/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-method/Impls_1.scala +++ b/test/files/run/macro-declared-in-method/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-object-class/Impls_1.scala b/test/files/run/macro-declared-in-object-class/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-object-class/Impls_1.scala +++ b/test/files/run/macro-declared-in-object-class/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-object-object/Impls_1.scala b/test/files/run/macro-declared-in-object-object/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-object-object/Impls_1.scala +++ b/test/files/run/macro-declared-in-object-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-object/Impls_1.scala b/test/files/run/macro-declared-in-object/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-object/Impls_1.scala +++ b/test/files/run/macro-declared-in-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-package-object/Impls_1.scala b/test/files/run/macro-declared-in-package-object/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-package-object/Impls_1.scala +++ b/test/files/run/macro-declared-in-package-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-refinement/Impls_1.scala b/test/files/run/macro-declared-in-refinement/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-refinement/Impls_1.scala +++ b/test/files/run/macro-declared-in-refinement/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-declared-in-trait/Impls_1.scala b/test/files/run/macro-declared-in-trait/Impls_1.scala index 5c61086a40..1f8f3cbd5a 100644 --- a/test/files/run/macro-declared-in-trait/Impls_1.scala +++ b/test/files/run/macro-declared-in-trait/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-def-infer-return-type-a/Impls_1.scala b/test/files/run/macro-def-infer-return-type-a/Impls_1.scala index 2346a6106d..52c9f9c3e9 100644 --- a/test/files/run/macro-def-infer-return-type-a/Impls_1.scala +++ b/test/files/run/macro-def-infer-return-type-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/run/macro-def-infer-return-type-b/Impls_Macros_1.scala b/test/files/run/macro-def-infer-return-type-b/Impls_Macros_1.scala index 8640713846..8a0f18c01b 100644 --- a/test/files/run/macro-def-infer-return-type-b/Impls_Macros_1.scala +++ b/test/files/run/macro-def-infer-return-type-b/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T](c: Ctx)(x: c.Expr[T]) = diff --git a/test/files/run/macro-def-infer-return-type-c/Impls_1.scala b/test/files/run/macro-def-infer-return-type-c/Impls_1.scala index f3e53bbea7..78db67eebf 100644 --- a/test/files/run/macro-def-infer-return-type-c/Impls_1.scala +++ b/test/files/run/macro-def-infer-return-type-c/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T](c: Ctx)(x: c.Expr[T]): c.Expr[T] = x diff --git a/test/files/run/macro-def-path-dependent-a/Impls_Macros_1.scala b/test/files/run/macro-def-path-dependent-a/Impls_Macros_1.scala index d7167e671c..3a91e41ff9 100644 --- a/test/files/run/macro-def-path-dependent-a/Impls_Macros_1.scala +++ b/test/files/run/macro-def-path-dependent-a/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} trait Exprs { self: Universe => diff --git a/test/files/run/macro-def-path-dependent-b/Impls_Macros_1.scala b/test/files/run/macro-def-path-dependent-b/Impls_Macros_1.scala index 44af6949a7..cf9f9ebd0e 100644 --- a/test/files/run/macro-def-path-dependent-b/Impls_Macros_1.scala +++ b/test/files/run/macro-def-path-dependent-b/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} trait Exprs { self: Universe => diff --git a/test/files/run/macro-def-path-dependent-c/Impls_Macros_1.scala b/test/files/run/macro-def-path-dependent-c/Impls_Macros_1.scala index 305146c48b..6cb374d9ba 100644 --- a/test/files/run/macro-def-path-dependent-c/Impls_Macros_1.scala +++ b/test/files/run/macro-def-path-dependent-c/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} trait Exprs { self: Universe => diff --git a/test/files/run/macro-def-path-dependent-d/Impls_Macros_1.scala b/test/files/run/macro-def-path-dependent-d/Impls_Macros_1.scala index aca7f999d5..8ba687327a 100644 --- a/test/files/run/macro-def-path-dependent-d/Impls_Macros_1.scala +++ b/test/files/run/macro-def-path-dependent-d/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.Context +import scala.reflect.macros.Context import scala.reflect.api.Universe object Test { diff --git a/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala index b59555539c..082e6b2efe 100644 --- a/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala index 68ead9b9a5..cceb038f05 100644 --- a/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[String]): c.Expr[Option[Int]] = { diff --git a/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala index a1dd5aa801..fa717b2327 100644 --- a/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala index 68ead9b9a5..cceb038f05 100644 --- a/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[String]): c.Expr[Option[Int]] = { diff --git a/test/files/run/macro-expand-multiple-arglists/Impls_1.scala b/test/files/run/macro-expand-multiple-arglists/Impls_1.scala index 2c1748bc29..11e07932c3 100644 --- a/test/files/run/macro-expand-multiple-arglists/Impls_1.scala +++ b/test/files/run/macro-expand-multiple-arglists/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int])(y: c.Expr[Int]) = { diff --git a/test/files/run/macro-expand-nullary-generic/Impls_1.scala b/test/files/run/macro-expand-nullary-generic/Impls_1.scala index edbe6d504a..9a0e97c8e0 100644 --- a/test/files/run/macro-expand-nullary-generic/Impls_1.scala +++ b/test/files/run/macro-expand-nullary-generic/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def impl[T: c.TypeTag](c: Ctx) = { diff --git a/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala b/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala index 0d849a085d..c6bd1cdbf1 100644 --- a/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala +++ b/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def impl(c: Ctx) = { diff --git a/test/files/run/macro-expand-overload/Impls_1.scala b/test/files/run/macro-expand-overload/Impls_1.scala index f4646d43df..f7c240d9ca 100644 --- a/test/files/run/macro-expand-overload/Impls_1.scala +++ b/test/files/run/macro-expand-overload/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def impl(c: Ctx)(tag: String, x: c.Expr[_]) = { diff --git a/test/files/run/macro-expand-override/Impls_1.scala b/test/files/run/macro-expand-override/Impls_1.scala index d6493caad9..ec93dd4111 100644 --- a/test/files/run/macro-expand-override/Impls_1.scala +++ b/test/files/run/macro-expand-override/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def impl(c: Ctx)(tag: String, x: c.Expr[_]) = { diff --git a/test/files/run/macro-expand-recursive/Impls_1.scala b/test/files/run/macro-expand-recursive/Impls_1.scala index 26833ca0b9..61db5c4a9b 100644 --- a/test/files/run/macro-expand-recursive/Impls_1.scala +++ b/test/files/run/macro-expand-recursive/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-expand-tparams-bounds-a/Impls_1.scala b/test/files/run/macro-expand-tparams-bounds-a/Impls_1.scala index 5019d5d4a7..9b8dafaa97 100644 --- a/test/files/run/macro-expand-tparams-bounds-a/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-bounds-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U <: String](c: Ctx): c.Expr[Unit] = c.literalUnit diff --git a/test/files/run/macro-expand-tparams-bounds-b/Impls_1.scala b/test/files/run/macro-expand-tparams-bounds-b/Impls_1.scala index abd68696b6..c11c89151c 100644 --- a/test/files/run/macro-expand-tparams-bounds-b/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-bounds-b/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} class C diff --git a/test/files/run/macro-expand-tparams-explicit/Impls_1.scala b/test/files/run/macro-expand-tparams-explicit/Impls_1.scala index d1843275d0..9baea020f9 100644 --- a/test/files/run/macro-expand-tparams-explicit/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-explicit/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U: c.TypeTag](c: Ctx) = { diff --git a/test/files/run/macro-expand-tparams-implicit/Impls_1.scala b/test/files/run/macro-expand-tparams-implicit/Impls_1.scala index cbc5460720..c707e5e3c0 100644 --- a/test/files/run/macro-expand-tparams-implicit/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-implicit/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U: c.TypeTag](c: Ctx)(x: c.Expr[U]) = { diff --git a/test/files/run/macro-expand-tparams-only-in-impl/Impls_1.scala b/test/files/run/macro-expand-tparams-only-in-impl/Impls_1.scala index 5019d5d4a7..9b8dafaa97 100644 --- a/test/files/run/macro-expand-tparams-only-in-impl/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-only-in-impl/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U <: String](c: Ctx): c.Expr[Unit] = c.literalUnit diff --git a/test/files/run/macro-expand-tparams-optional/Impls_1.scala b/test/files/run/macro-expand-tparams-optional/Impls_1.scala index 97363edd9a..3b829e2e09 100644 --- a/test/files/run/macro-expand-tparams-optional/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-optional/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U](c: Ctx) = { diff --git a/test/files/run/macro-expand-tparams-prefix-a/Impls_1.scala b/test/files/run/macro-expand-tparams-prefix-a/Impls_1.scala index cbc5460720..c707e5e3c0 100644 --- a/test/files/run/macro-expand-tparams-prefix-a/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-prefix-a/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U: c.TypeTag](c: Ctx)(x: c.Expr[U]) = { diff --git a/test/files/run/macro-expand-tparams-prefix-b/Impls_1.scala b/test/files/run/macro-expand-tparams-prefix-b/Impls_1.scala index 3d29fa467d..4d58467638 100644 --- a/test/files/run/macro-expand-tparams-prefix-b/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-prefix-b/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T: c.TypeTag, U: c.TypeTag](c: Ctx)(x: c.Expr[U]) = { diff --git a/test/files/run/macro-expand-tparams-prefix-c1/Impls_1.scala b/test/files/run/macro-expand-tparams-prefix-c1/Impls_1.scala index a834d809da..961d5b658d 100644 --- a/test/files/run/macro-expand-tparams-prefix-c1/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-prefix-c1/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T, U: c.TypeTag, V](c: Ctx)(implicit T: c.TypeTag[T], V: c.TypeTag[V]): c.Expr[Unit] = { diff --git a/test/files/run/macro-expand-tparams-prefix-c2/Impls_Macros_1.scala b/test/files/run/macro-expand-tparams-prefix-c2/Impls_Macros_1.scala index e0de1f3f83..ab92c54d2c 100644 --- a/test/files/run/macro-expand-tparams-prefix-c2/Impls_Macros_1.scala +++ b/test/files/run/macro-expand-tparams-prefix-c2/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T, U: c.TypeTag, V](c: Ctx)(implicit T: c.TypeTag[T], V: c.TypeTag[V]): c.Expr[Unit] = { diff --git a/test/files/run/macro-expand-tparams-prefix-d1/Impls_1.scala b/test/files/run/macro-expand-tparams-prefix-d1/Impls_1.scala index f497e5f7a9..ca515be627 100644 --- a/test/files/run/macro-expand-tparams-prefix-d1/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-prefix-d1/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T, U: c.AbsTypeTag, V](c: Ctx)(implicit T: c.AbsTypeTag[T], V: c.AbsTypeTag[V]): c.Expr[Unit] = { diff --git a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala index b83fa046e5..2ef8f04be9 100644 --- a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(xs: c.Expr[Int]*) = { diff --git a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala index 5f550064e1..3c7f94f605 100644 --- a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(xs: c.Expr[Int]*) = { diff --git a/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala b/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala index 8c75a7e0ea..2066893bdc 100644 --- a/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def myprintln(xs: Int*) = { diff --git a/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala b/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala index b83fa046e5..2ef8f04be9 100644 --- a/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(xs: c.Expr[Int]*) = { diff --git a/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala b/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala index 8c75a7e0ea..2066893bdc 100644 --- a/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def myprintln(xs: Int*) = { 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 8154ab0341..b57af2ede4 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 @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo_targs[T, U: c.TypeTag](c: Ctx = null)(x: c.Expr[Int] = null) = { 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 367a45a2c3..537f1db8c6 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 @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(unconventionalName: Ctx)(x: unconventionalName.Expr[Int]) = { diff --git a/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala b/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala index 5a7d1a6b9a..b3babd8848 100644 --- a/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx): c.Expr[Int] = { diff --git a/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala b/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala index 04eef976c5..405ae7024f 100644 --- a/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala b/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala index c63ad01677..0d840eed3f 100644 --- a/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala b/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala index 67a19a6d62..5ce9e42b57 100644 --- a/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T: c.TypeTag](c: Ctx)(x: c.Expr[T]) = { diff --git a/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala b/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala index e5bdca008e..5866469499 100644 --- a/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int])(y: c.Expr[Int]) = { diff --git a/test/files/run/macro-openmacros/Impls_Macros_1.scala b/test/files/run/macro-openmacros/Impls_Macros_1.scala index 6b92834b81..38d46c5185 100644 --- a/test/files/run/macro-openmacros/Impls_Macros_1.scala +++ b/test/files/run/macro-openmacros/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl(c: Context): c.Expr[Unit] = { diff --git a/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala b/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala index 7cb810c86b..6c14428437 100644 --- a/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala +++ b/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { object Impls { diff --git a/test/files/run/macro-range/Common_1.scala b/test/files/run/macro-range/Common_1.scala index 650257ae16..5c4bc211fc 100644 --- a/test/files/run/macro-range/Common_1.scala +++ b/test/files/run/macro-range/Common_1.scala @@ -1,4 +1,4 @@ -import reflect.makro.Context +import reflect.macros.Context abstract class RangeDefault { val from, to: Int diff --git a/test/files/run/macro-range/Expansion_Impossible_2.scala b/test/files/run/macro-range/Expansion_Impossible_2.scala index fecce6bc48..57e0cee97f 100644 --- a/test/files/run/macro-range/Expansion_Impossible_2.scala +++ b/test/files/run/macro-range/Expansion_Impossible_2.scala @@ -1,4 +1,4 @@ -import reflect.makro.Context +import reflect.macros.Context object Impls { def foreach(c: Context)(f: c.Expr[Int => Unit]): c.Expr[Unit] = { diff --git a/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala b/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala index b10f4121a6..fa559334d4 100644 --- a/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala +++ b/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala b/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala index dd8fcd4d9e..5d7e077731 100644 --- a/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala +++ b/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-reify-basic/Macros_1.scala b/test/files/run/macro-reify-basic/Macros_1.scala index 8f8598e248..3f6720f10a 100644 --- a/test/files/run/macro-reify-basic/Macros_1.scala +++ b/test/files/run/macro-reify-basic/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo(s: String) = macro Impls.foo diff --git a/test/files/run/macro-reify-freevars/Macros_1.scala b/test/files/run/macro-reify-freevars/Macros_1.scala index df1473511d..c72a7ab54f 100644 --- a/test/files/run/macro-reify-freevars/Macros_1.scala +++ b/test/files/run/macro-reify-freevars/Macros_1.scala @@ -2,7 +2,7 @@ package scala.collection.slick object QueryableMacros{ def map[T:c.TypeTag, S:c.TypeTag] - (c: scala.reflect.makro.Context) + (c: scala.reflect.macros.Context) (projection: c.Expr[T => S]) : c.Expr[scala.collection.slick.Queryable[S]] = { import c.universe._ diff --git a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala index b52b962e31..4dda80a117 100644 --- a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala @@ -1,6 +1,6 @@ import scala.reflect.runtime.universe._ import scala.reflect.runtime.{universe => ru} -import scala.reflect.makro.Context +import scala.reflect.macros.Context case class Utils[C <: Context]( c:C ) { import c.universe._ @@ -33,7 +33,7 @@ object QueryableMacros{ c.universe.reify{ Queryable.factory[S]( foo.splice )} } def map[T:c.TypeTag, S:c.TypeTag] - (c: scala.reflect.makro.Context) + (c: scala.reflect.macros.Context) (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) } class Queryable[T]{ diff --git a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala index b52b962e31..4dda80a117 100644 --- a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala @@ -1,6 +1,6 @@ import scala.reflect.runtime.universe._ import scala.reflect.runtime.{universe => ru} -import scala.reflect.makro.Context +import scala.reflect.macros.Context case class Utils[C <: Context]( c:C ) { import c.universe._ @@ -33,7 +33,7 @@ object QueryableMacros{ c.universe.reify{ Queryable.factory[S]( foo.splice )} } def map[T:c.TypeTag, S:c.TypeTag] - (c: scala.reflect.makro.Context) + (c: scala.reflect.macros.Context) (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) } class Queryable[T]{ diff --git a/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala b/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala index 66c0ee1e9b..f19fd239f9 100644 --- a/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala +++ b/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { val `Answer to the Ultimate Question of Life, the Universe, and Everything` = 42 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 3ddfe6a737..f3e1c9ae95 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 @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-reify-splice-splice/Macros_1.scala b/test/files/run/macro-reify-splice-splice/Macros_1.scala index 0de780b5a2..efdd5dbaa2 100644 --- a/test/files/run/macro-reify-splice-splice/Macros_1.scala +++ b/test/files/run/macro-reify-splice-splice/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo = macro Impls.foo diff --git a/test/files/run/macro-reify-staticXXX/Macros_1.scala b/test/files/run/macro-reify-staticXXX/Macros_1.scala index b0ce6507f8..f12c8f7dcc 100644 --- a/test/files/run/macro-reify-staticXXX/Macros_1.scala +++ b/test/files/run/macro-reify-staticXXX/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object B { override def toString = "object" } class C { override def toString = "class" } diff --git a/test/files/run/macro-reify-tagful-a/Macros_1.scala b/test/files/run/macro-reify-tagful-a/Macros_1.scala index 32b09bdcdf..acca4921dc 100644 --- a/test/files/run/macro-reify-tagful-a/Macros_1.scala +++ b/test/files/run/macro-reify-tagful-a/Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo[T](s: T) = macro Impls.foo[T] diff --git a/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala b/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala index 77e4b729d3..96cfb75852 100644 --- a/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo[T](s: T) = macro Impls.foo[T] diff --git a/test/files/run/macro-reify-unreify/Macros_1.scala b/test/files/run/macro-reify-unreify/Macros_1.scala index 3e9033966d..620a929210 100644 --- a/test/files/run/macro-reify-unreify/Macros_1.scala +++ b/test/files/run/macro-reify-unreify/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo(s: String) = macro Impls.foo diff --git a/test/files/run/macro-repl-basic.check b/test/files/run/macro-repl-basic.check index dc65e5c55b..4a50c60469 100644 --- a/test/files/run/macro-repl-basic.check +++ b/test/files/run/macro-repl-basic.check @@ -6,8 +6,8 @@ scala> scala> import language.experimental.macros import language.experimental.macros -scala> import scala.reflect.makro.{Context => Ctx} -import scala.reflect.makro.{Context=>Ctx} +scala> import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{Context=>Ctx} scala> diff --git a/test/files/run/macro-repl-basic.scala b/test/files/run/macro-repl-basic.scala index fba0aab116..eae1febb3a 100644 --- a/test/files/run/macro-repl-basic.scala +++ b/test/files/run/macro-repl-basic.scala @@ -3,7 +3,7 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { def code = """ |import language.experimental.macros - |import scala.reflect.makro.{Context => Ctx} + |import scala.reflect.macros.{Context => Ctx} | |object Impls { | def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-repl-dontexpand.check b/test/files/run/macro-repl-dontexpand.check index 35845f0cff..3c378cdf09 100644 --- a/test/files/run/macro-repl-dontexpand.check +++ b/test/files/run/macro-repl-dontexpand.check @@ -3,8 +3,8 @@ Type :help for more information. scala> -scala> def bar(c: scala.reflect.makro.Context) = ??? -bar: (c: scala.reflect.makro.Context)Nothing +scala> def bar(c: scala.reflect.macros.Context) = ??? +bar: (c: scala.reflect.macros.Context)Nothing scala> def foo = macro bar foo: Any diff --git a/test/files/run/macro-repl-dontexpand.scala b/test/files/run/macro-repl-dontexpand.scala index cd1b2e1969..f3422d88de 100644 --- a/test/files/run/macro-repl-dontexpand.scala +++ b/test/files/run/macro-repl-dontexpand.scala @@ -3,7 +3,7 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { override def extraSettings = "-language:experimental.macros" def code = """ - |def bar(c: scala.reflect.makro.Context) = ??? + |def bar(c: scala.reflect.macros.Context) = ??? |def foo = macro bar |""".stripMargin } diff --git a/test/files/run/macro-settings/Impls_Macros_1.scala b/test/files/run/macro-settings/Impls_Macros_1.scala index 20dcdc1bd1..83d80a5bff 100644 --- a/test/files/run/macro-settings/Impls_Macros_1.scala +++ b/test/files/run/macro-settings/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Impls { def impl(c: Context) = c.universe.reify { 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 05d3e036d9..0793696fd4 100644 --- a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl(c: Context) = { diff --git a/test/files/run/macro-sip19/Impls_Macros_1.scala b/test/files/run/macro-sip19/Impls_Macros_1.scala index f6636c298c..f89e51f560 100644 --- a/test/files/run/macro-sip19/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl(c: Context) = { 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 8ed435d629..633cb930fc 100644 --- a/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl_with_implicits_enabled(c: Context) = { 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 2c9bce92a5..b2f6f7d50e 100644 --- a/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl_with_macros_enabled(c: Context) = { 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 0aca9781f4..948c047351 100644 --- a/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl_with_macros_enabled(c: Context) = { 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 7b921c0e57..3d350a50fa 100644 --- a/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala +++ b/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def cons_impl[A: c.AbsTypeTag](c: Context)(x: c.Expr[A], xs: c.Expr[List[A]]): c.Expr[List[A]] = c.universe.reify { 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 fdba40623b..4bcc610b1d 100644 --- a/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala +++ b/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Macros { def impl[T: c.TypeTag](c: Context)(foo: c.Expr[T]): c.Expr[Unit] = c.universe.reify { println(c.literal(implicitly[c.TypeTag[T]].toString).splice) } diff --git a/test/files/run/t5713/Impls_Macros_1.scala b/test/files/run/t5713/Impls_Macros_1.scala index c041d36523..12c3da2ff0 100644 --- a/test/files/run/t5713/Impls_Macros_1.scala +++ b/test/files/run/t5713/Impls_Macros_1.scala @@ -1,7 +1,7 @@ package m import language.experimental.macros -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Level extends Enumeration { val Error = Value(5) diff --git a/test/pending/run/macro-expand-default/Impls_1.scala b/test/pending/run/macro-expand-default/Impls_1.scala index a539982b45..7cf8d59c75 100644 --- a/test/pending/run/macro-expand-default/Impls_1.scala +++ b/test/pending/run/macro-expand-default/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int], y: c.Expr[Int]) = { diff --git a/test/pending/run/macro-expand-implicit-macro-defeats-type-inference/Impls_1.scala b/test/pending/run/macro-expand-implicit-macro-defeats-type-inference/Impls_1.scala index 599ddf5ed9..0dac664d38 100644 --- a/test/pending/run/macro-expand-implicit-macro-defeats-type-inference/Impls_1.scala +++ b/test/pending/run/macro-expand-implicit-macro-defeats-type-inference/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Impls { def foo[T: c.TypeTag](c: Context): c.Expr[List[T]] = c.universe.reify { diff --git a/test/pending/run/macro-expand-macro-has-context-bound/Impls_1.scala b/test/pending/run/macro-expand-macro-has-context-bound/Impls_1.scala index 3cee65ce72..be00fd0d8a 100644 --- a/test/pending/run/macro-expand-macro-has-context-bound/Impls_1.scala +++ b/test/pending/run/macro-expand-macro-has-context-bound/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[U](c: Ctx)(x: c.Expr[U])(evidence: c.Expr[Numeric[U]]) = { diff --git a/test/pending/run/macro-expand-named/Impls_1.scala b/test/pending/run/macro-expand-named/Impls_1.scala index a539982b45..7cf8d59c75 100644 --- a/test/pending/run/macro-expand-named/Impls_1.scala +++ b/test/pending/run/macro-expand-named/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int], y: c.Expr[Int]) = { diff --git a/test/pending/run/macro-expand-tparams-prefix-e1/Impls_1.scala b/test/pending/run/macro-expand-tparams-prefix-e1/Impls_1.scala index d7df919552..eff11d4a20 100644 --- a/test/pending/run/macro-expand-tparams-prefix-e1/Impls_1.scala +++ b/test/pending/run/macro-expand-tparams-prefix-e1/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T, U: c.TypeTag, V](c: Ctx)(implicit T: c.TypeTag[T], V: c.TypeTag[V]): c.Expr[Unit] = { diff --git a/test/pending/run/macro-expand-tparams-prefix-f1/Impls_1.scala b/test/pending/run/macro-expand-tparams-prefix-f1/Impls_1.scala index d7df919552..eff11d4a20 100644 --- a/test/pending/run/macro-expand-tparams-prefix-f1/Impls_1.scala +++ b/test/pending/run/macro-expand-tparams-prefix-f1/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Impls { def foo[T, U: c.TypeTag, V](c: Ctx)(implicit T: c.TypeTag[T], V: c.TypeTag[V]): c.Expr[Unit] = { diff --git a/test/pending/run/macro-quasiinvalidbody-a/Impls_1.scala b/test/pending/run/macro-quasiinvalidbody-a/Impls_1.scala index 0da37cd5c0..daedde4021 100644 --- a/test/pending/run/macro-quasiinvalidbody-a/Impls_1.scala +++ b/test/pending/run/macro-quasiinvalidbody-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} trait Impls { def impl(c: Ctx)(x: c.Expr[Any]) = x diff --git a/test/pending/run/macro-quasiinvalidbody-a/Macros_Test_2.scala b/test/pending/run/macro-quasiinvalidbody-a/Macros_Test_2.scala index 04a43080bd..27140a77ad 100644 --- a/test/pending/run/macro-quasiinvalidbody-a/Macros_Test_2.scala +++ b/test/pending/run/macro-quasiinvalidbody-a/Macros_Test_2.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros extends Impls { def foo(x: Any) = macro impl diff --git a/test/pending/run/macro-quasiinvalidbody-b/Impls_1.scala b/test/pending/run/macro-quasiinvalidbody-b/Impls_1.scala index d84d04974f..246fc9f904 100644 --- a/test/pending/run/macro-quasiinvalidbody-b/Impls_1.scala +++ b/test/pending/run/macro-quasiinvalidbody-b/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} trait ImplContainer { object Impls { diff --git a/test/pending/run/macro-quasiinvalidbody-b/Macros_Test_2.scala b/test/pending/run/macro-quasiinvalidbody-b/Macros_Test_2.scala index 82f88b62e4..da9445ac52 100644 --- a/test/pending/run/macro-quasiinvalidbody-b/Macros_Test_2.scala +++ b/test/pending/run/macro-quasiinvalidbody-b/Macros_Test_2.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros extends ImplContainer { def foo(x: Any) = macro Impls.foo diff --git a/test/pending/run/macro-reify-array/Macros_1.scala b/test/pending/run/macro-reify-array/Macros_1.scala index 4b4cb05884..8fa945b9c6 100644 --- a/test/pending/run/macro-reify-array/Macros_1.scala +++ b/test/pending/run/macro-reify-array/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo[T](s: String) = macro Impls.foo[T] diff --git a/test/pending/run/macro-reify-tagful-b/Macros_1.scala b/test/pending/run/macro-reify-tagful-b/Macros_1.scala index f730bb51f1..af078d93b4 100644 --- a/test/pending/run/macro-reify-tagful-b/Macros_1.scala +++ b/test/pending/run/macro-reify-tagful-b/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo[T](s: T) = macro Impls.foo[List[T]] diff --git a/test/pending/run/macro-reify-tagless-b/Impls_Macros_1.scala b/test/pending/run/macro-reify-tagless-b/Impls_Macros_1.scala index 2c5079ea54..a581c47026 100644 --- a/test/pending/run/macro-reify-tagless-b/Impls_Macros_1.scala +++ b/test/pending/run/macro-reify-tagless-b/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.makro.{Context => Ctx} +import scala.reflect.macros.{Context => Ctx} object Macros { def foo[T](s: T) = macro Impls.foo[List[T]] diff --git a/test/pending/run/t5692/Impls_Macros_1.scala b/test/pending/run/t5692/Impls_Macros_1.scala index 7d0e788bd6..94bcffbcaf 100644 --- a/test/pending/run/t5692/Impls_Macros_1.scala +++ b/test/pending/run/t5692/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.makro.Context +import scala.reflect.macros.Context object Impls { - def impl[A](c: reflect.makro.Context) = c.universe.reify(()) + def impl[A](c: reflect.macros.Context) = c.universe.reify(()) } object Macros { -- cgit v1.2.3 From a354ec2a77f83f57680c576758ddfa9234083b9e Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 31 Jul 2012 14:14:01 +0200 Subject: first stab at serialization of exprs and tags Instead of trying to serialize the entire universe and failing miserably (which happens now), exprs and type tags will now serialize their creators and deserialize into scala.reflect.basis. Since creators produced by reification are not serializable right now, serialization will crash. That's a small improvement over state of the art functionality-wise, but it's a step forward robustness-wise. Next step in this direction is generation of serialization code for creators. Related issues: SI-5919 and SI-5908. Also see the discussion at scala-internals http://groups.google.com/group/scala-internals/browse_thread/thread/ef63f8b5bd194c7c --- src/library/scala/reflect/base/Exprs.scala | 19 +++++++++++++ src/library/scala/reflect/base/TypeTags.scala | 32 +++++++++++++++++++--- src/reflect/scala/reflect/internal/StdNames.scala | 1 - test/files/run/abstypetags_serialize.check | 2 ++ test/files/run/abstypetags_serialize.scala | 32 ++++++++++++++++++++++ test/files/run/exprs_serialize.check | 2 ++ test/files/run/exprs_serialize.scala | 28 +++++++++++++++++++ .../files/run/macro-typecheck-macrosdisabled.check | 5 ---- .../run/macro-typecheck-macrosdisabled2.check | 5 ---- .../run/toolbox_typecheck_macrosdisabled.check | 5 ---- .../run/toolbox_typecheck_macrosdisabled2.check | 5 ---- test/files/run/typetags_serialize.check | 2 ++ test/files/run/typetags_serialize.scala | 28 +++++++++++++++++++ 13 files changed, 141 insertions(+), 25 deletions(-) create mode 100644 test/files/run/abstypetags_serialize.check create mode 100644 test/files/run/abstypetags_serialize.scala create mode 100644 test/files/run/exprs_serialize.check create mode 100644 test/files/run/exprs_serialize.scala create mode 100644 test/files/run/typetags_serialize.check create mode 100644 test/files/run/typetags_serialize.scala (limited to 'test/files') diff --git a/src/library/scala/reflect/base/Exprs.scala b/src/library/scala/reflect/base/Exprs.scala index a92860f558..8e429afb21 100644 --- a/src/library/scala/reflect/base/Exprs.scala +++ b/src/library/scala/reflect/base/Exprs.scala @@ -56,5 +56,24 @@ trait Exprs { self: Universe => |if you want to splice the underlying expression, use `.splice`. |if you want to get a value of the underlying expression, add scala-compiler.jar to the classpath, |import `scala.tools.reflect.Eval` and call `.eval` instead.""".trim.stripMargin) + + private def writeReplace(): AnyRef = new SerializedExpr(treec, implicitly[AbsTypeTag[T]].in(scala.reflect.basis.rootMirror)) + } +} + +private[scala] class SerializedExpr(var treec: TreeCreator, var tag: scala.reflect.basis.AbsTypeTag[_]) extends Serializable { + private def writeObject(out: java.io.ObjectOutputStream): Unit = { + out.writeObject(treec) + out.writeObject(tag) + } + + private def readObject(in: java.io.ObjectInputStream): Unit = { + treec = in.readObject().asInstanceOf[TreeCreator] + tag = in.readObject().asInstanceOf[scala.reflect.basis.AbsTypeTag[_]] + } + + private def readResolve(): AnyRef = { + import scala.reflect.basis._ + Expr(rootMirror, treec)(tag) } } \ No newline at end of file diff --git a/src/library/scala/reflect/base/TypeTags.scala b/src/library/scala/reflect/base/TypeTags.scala index 05b1a079d7..3f7024366e 100644 --- a/src/library/scala/reflect/base/TypeTags.scala +++ b/src/library/scala/reflect/base/TypeTags.scala @@ -169,6 +169,7 @@ trait TypeTags { self: Universe => val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] otherMirror.universe.AbsTypeTag[T](otherMirror1, tpec) } + private def writeReplace(): AnyRef = new SerializedTypeTag(tpec, concrete = false) } /** @@ -233,13 +234,18 @@ trait TypeTags { self: Universe => val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] otherMirror.universe.TypeTag[T](otherMirror1, tpec) } + private def writeReplace(): AnyRef = new SerializedTypeTag(tpec, concrete = true) } - private class PredefTypeTag[T](_tpe: Type, copyIn: Universe => Universe # TypeTag[T]) extends TypeTagImpl[T](rootMirror, null) { + private class PredefTypeCreator[T](copyIn: Universe => Universe # TypeTag[T]) extends TypeCreator { + def apply[U <: Universe with Singleton](m: MirrorOf[U]): U # Type = { + copyIn(m.universe).asInstanceOf[U # TypeTag[T]].tpe + } + } + + private class PredefTypeTag[T](_tpe: Type, copyIn: Universe => Universe # TypeTag[T]) extends TypeTagImpl[T](rootMirror, new PredefTypeCreator(copyIn)) { override lazy val tpe: Type = _tpe - override def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # TypeTag[T] = - copyIn(otherMirror.universe).asInstanceOf[U # TypeTag[T]] - private def readResolve() = copyIn(self) + private def writeReplace(): AnyRef = new SerializedTypeTag(tpec, concrete = true) } // incantations @@ -248,3 +254,21 @@ trait TypeTags { self: Universe => // big thanks to Viktor Klang for this brilliant idea! def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe } + +private[scala] class SerializedTypeTag(var tpec: TypeCreator, var concrete: Boolean) extends Serializable { + private def writeObject(out: java.io.ObjectOutputStream): Unit = { + out.writeObject(tpec) + out.writeBoolean(concrete) + } + + private def readObject(in: java.io.ObjectInputStream): Unit = { + tpec = in.readObject().asInstanceOf[TypeCreator] + concrete = in.readBoolean() + } + + private def readResolve(): AnyRef = { + import scala.reflect.basis._ + if (concrete) TypeTag(rootMirror, tpec) + else AbsTypeTag(rootMirror, tpec) + } +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 133b035228..67456cf86b 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -616,7 +616,6 @@ trait StdNames { val apply: NameType = "apply" val applyDynamic: NameType = "applyDynamic" val applyDynamicNamed: NameType = "applyDynamicNamed" - val applyImpl: NameType = "applyImpl" val applyOrElse: NameType = "applyOrElse" val args : NameType = "args" val argv : NameType = "argv" diff --git a/test/files/run/abstypetags_serialize.check b/test/files/run/abstypetags_serialize.check new file mode 100644 index 0000000000..aafb4761ad --- /dev/null +++ b/test/files/run/abstypetags_serialize.check @@ -0,0 +1,2 @@ +java.io.NotSerializableException: Test$$typecreator1$1 +java.io.NotSerializableException: Test$$typecreator2$1 diff --git a/test/files/run/abstypetags_serialize.scala b/test/files/run/abstypetags_serialize.scala new file mode 100644 index 0000000000..5b9142f6d5 --- /dev/null +++ b/test/files/run/abstypetags_serialize.scala @@ -0,0 +1,32 @@ +import java.io._ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +object Test extends App { + def test(tag: AbsTypeTag[_]) = + try { + val fout = new ByteArrayOutputStream() + val out = new ObjectOutputStream(fout) + out.writeObject(tag) + out.close() + fout.close() + + val fin = new ByteArrayInputStream(fout.toByteArray) + val in = new ObjectInputStream(fin) + val retag = in.readObject().asInstanceOf[scala.reflect.basis.AbsTypeTag[_]].in(cm) + in.close() + fin.close() + + println(retag) + } catch { + case ex: Exception => + println(ex) + } + + def qwe[T, U[_]] = { + test(implicitly[AbsTypeTag[T]]) + test(implicitly[AbsTypeTag[U[String]]]) + } + + qwe +} \ No newline at end of file diff --git a/test/files/run/exprs_serialize.check b/test/files/run/exprs_serialize.check new file mode 100644 index 0000000000..a3bf9ccdc4 --- /dev/null +++ b/test/files/run/exprs_serialize.check @@ -0,0 +1,2 @@ +java.io.NotSerializableException: Test$$treecreator1$1 +java.io.NotSerializableException: Test$$treecreator2$1 diff --git a/test/files/run/exprs_serialize.scala b/test/files/run/exprs_serialize.scala new file mode 100644 index 0000000000..075c902a34 --- /dev/null +++ b/test/files/run/exprs_serialize.scala @@ -0,0 +1,28 @@ +import java.io._ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +object Test extends App { + def test(expr: Expr[_]) = + try { + val fout = new ByteArrayOutputStream() + val out = new ObjectOutputStream(fout) + out.writeObject(expr) + out.close() + fout.close() + + val fin = new ByteArrayInputStream(fout.toByteArray) + val in = new ObjectInputStream(fin) + val reexpr = in.readObject().asInstanceOf[scala.reflect.basis.Expr[_]].in(cm) + in.close() + fin.close() + + println(reexpr) + } catch { + case ex: Exception => + println(ex) + } + + test(reify(2)) + test(reify{def foo = "hello"; foo + "world!"}) +} \ No newline at end of file diff --git a/test/files/run/macro-typecheck-macrosdisabled.check b/test/files/run/macro-typecheck-macrosdisabled.check index da1a28bc24..c560b0e4b5 100644 --- a/test/files/run/macro-typecheck-macrosdisabled.check +++ b/test/files/run/macro-typecheck-macrosdisabled.check @@ -8,11 +8,6 @@ () }; def apply[U >: Nothing <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Tree = { - val $u: scala.reflect.api.Universe = $m$untyped.universe.asInstanceOf[scala.reflect.api.Universe]; - val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - $treecreator1.this.applyImpl[$u.type]($m).asInstanceOf[U#Tree] - }; - private def applyImpl[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): scala.reflect.base.Universe#Tree = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $u.Literal.apply($u.Constant.apply(2)) diff --git a/test/files/run/macro-typecheck-macrosdisabled2.check b/test/files/run/macro-typecheck-macrosdisabled2.check index 908fb65bb3..55e7913250 100644 --- a/test/files/run/macro-typecheck-macrosdisabled2.check +++ b/test/files/run/macro-typecheck-macrosdisabled2.check @@ -8,11 +8,6 @@ () }; def apply[U >: Nothing <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Tree = { - val $u: scala.reflect.api.Universe = $m$untyped.universe.asInstanceOf[scala.reflect.api.Universe]; - val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - $treecreator1.this.applyImpl[$u.type]($m).asInstanceOf[U#Tree] - }; - private def applyImpl[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): scala.reflect.base.Universe#Tree = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $u.Apply.apply($u.Select.apply($u.Select.apply($u.build.Ident($m.staticPackage("scala")), $u.newTermName("Array")), $u.newTermName("apply")), scala.collection.immutable.List.apply[$u.Literal]($u.Literal.apply($u.Constant.apply(2)))) diff --git a/test/files/run/toolbox_typecheck_macrosdisabled.check b/test/files/run/toolbox_typecheck_macrosdisabled.check index f4a67e3054..9cf101c69d 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled.check +++ b/test/files/run/toolbox_typecheck_macrosdisabled.check @@ -8,11 +8,6 @@ () }; def apply[U <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Tree = { - val $u: scala.reflect.api.Universe = $m$untyped.universe.asInstanceOf[scala.reflect.api.Universe]; - val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - $treecreator1.this.applyImpl[$u.type]($m).asInstanceOf[U#Tree] - }; - private def applyImpl[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): scala.reflect.base.Universe#Tree = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $u.Literal.apply($u.Constant.apply(2)) diff --git a/test/files/run/toolbox_typecheck_macrosdisabled2.check b/test/files/run/toolbox_typecheck_macrosdisabled2.check index fa55a09c40..d344e33180 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled2.check +++ b/test/files/run/toolbox_typecheck_macrosdisabled2.check @@ -8,11 +8,6 @@ () }; def apply[U <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Tree = { - val $u: scala.reflect.api.Universe = $m$untyped.universe.asInstanceOf[scala.reflect.api.Universe]; - val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - $treecreator1.this.applyImpl[$u.type]($m).asInstanceOf[U#Tree] - }; - private def applyImpl[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): scala.reflect.base.Universe#Tree = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $u.Apply.apply($u.Select.apply($u.Select.apply($u.build.Ident($m.staticPackage("scala")), $u.newTermName("Array")), $u.newTermName("apply")), scala.collection.immutable.List.apply[$u.Literal]($u.Literal.apply($u.Constant.apply(2)))) diff --git a/test/files/run/typetags_serialize.check b/test/files/run/typetags_serialize.check new file mode 100644 index 0000000000..1b898250fb --- /dev/null +++ b/test/files/run/typetags_serialize.check @@ -0,0 +1,2 @@ +java.io.NotSerializableException: scala.reflect.base.TypeTags$PredefTypeCreator +java.io.NotSerializableException: Test$$typecreator1$1 diff --git a/test/files/run/typetags_serialize.scala b/test/files/run/typetags_serialize.scala new file mode 100644 index 0000000000..3917b69a93 --- /dev/null +++ b/test/files/run/typetags_serialize.scala @@ -0,0 +1,28 @@ +import java.io._ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +object Test extends App { + def test(tag: TypeTag[_]) = + try { + val fout = new ByteArrayOutputStream() + val out = new ObjectOutputStream(fout) + out.writeObject(tag) + out.close() + fout.close() + + val fin = new ByteArrayInputStream(fout.toByteArray) + val in = new ObjectInputStream(fin) + val retag = in.readObject().asInstanceOf[scala.reflect.basis.TypeTag[_]].in(cm) + in.close() + fin.close() + + println(retag) + } catch { + case ex: Exception => + println(ex) + } + + test(implicitly[TypeTag[Int]]) + test(implicitly[TypeTag[String]]) +} \ No newline at end of file -- cgit v1.2.3