summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
Diffstat (limited to 'test/files')
-rw-r--r--test/files/.gitignore (renamed from test/files/gitignore.SAMPLE)0
-rw-r--r--test/files/pos/t4760.scala34
-rw-r--r--test/files/pos/t7486-named.scala8
-rw-r--r--test/files/pos/t7486.scala8
-rw-r--r--test/files/pos/t7782.scala25
-rw-r--r--test/files/pos/t7782b.scala25
-rw-r--r--test/files/pos/t7818.scala10
-rw-r--r--test/files/pos/t942/Amount_1.java5
-rw-r--r--test/files/pos/t942/Test_2.scala3
-rw-r--r--test/files/run/WeakHashSetTest.scala174
-rw-r--r--test/files/run/predef-cycle.scala71
-rw-r--r--test/files/run/t7269.scala32
-rw-r--r--test/files/run/t7398.scala6
-rw-r--r--test/files/run/t7775.scala17
-rw-r--r--test/files/run/t7779.scala67
-rw-r--r--test/files/run/t7825.scala34
-rw-r--r--test/files/run/typed-annotated.check1
-rw-r--r--test/files/run/typed-annotated/Macros_1.scala17
-rw-r--r--test/files/run/typed-annotated/Test_2.scala3
19 files changed, 536 insertions, 4 deletions
diff --git a/test/files/gitignore.SAMPLE b/test/files/.gitignore
index 161be5b55f..161be5b55f 100644
--- a/test/files/gitignore.SAMPLE
+++ b/test/files/.gitignore
diff --git a/test/files/pos/t4760.scala b/test/files/pos/t4760.scala
new file mode 100644
index 0000000000..767e3847f4
--- /dev/null
+++ b/test/files/pos/t4760.scala
@@ -0,0 +1,34 @@
+
+class Test {
+ // parses
+ def f1 = {
+ import scala._;
+ }
+ // b.scala:7: error: ';' expected but '}' found.
+ // }
+ // ^
+ // one error found
+ def f2 = {
+ import scala._
+ }
+ def f2b = {
+ import scala.collection.mutable.{ Map => MMap }
+ }
+ def f(): Unit = {
+ locally {
+ import scala.util.Properties.lineSeparator
+ }
+ }
+
+ // parses
+ def f3 = {
+ import scala._
+ 5
+ }
+ locally { (x: Int) =>
+ import scala.util._
+ }
+ 1 match {
+ case 1 => import scala.concurrent._
+ }
+}
diff --git a/test/files/pos/t7486-named.scala b/test/files/pos/t7486-named.scala
new file mode 100644
index 0000000000..253293e5f1
--- /dev/null
+++ b/test/files/pos/t7486-named.scala
@@ -0,0 +1,8 @@
+
+object Test {
+ def fold(empty: Any) = ()
+ implicit val notAnnotatedImplicit = new {
+ fold(empty = 0)
+ def empty[A]: Any = ???
+ }
+}
diff --git a/test/files/pos/t7486.scala b/test/files/pos/t7486.scala
new file mode 100644
index 0000000000..6dd7f4c4ac
--- /dev/null
+++ b/test/files/pos/t7486.scala
@@ -0,0 +1,8 @@
+object Test{
+ var locker = 0
+ // remove implicit, or change to `locker = locker + 1` to make it compile.
+ implicit val davyJones0 = {
+ locker += 0
+ 0
+ }
+}
diff --git a/test/files/pos/t7782.scala b/test/files/pos/t7782.scala
new file mode 100644
index 0000000000..037bdad673
--- /dev/null
+++ b/test/files/pos/t7782.scala
@@ -0,0 +1,25 @@
+package pack
+
+object Test {
+ import O.empty
+ empty // this will trigger completion of `test`
+ // with skolemizationLevel = 1
+}
+
+object O {
+ // order matters (!!!)
+
+ // this order breaks under 2.10.x
+ def empty[E]: C[E] = ???
+ def empty(implicit a: Any): Any = ???
+}
+
+abstract class C[E] {
+ def foo[BB](f: BB)
+ def test[B](f: B): Any = foo(f)
+ // error: no type parameters for method foo: (<param> f: BB)scala.this.Unit exist so that it can be applied to arguments (B&1)
+ // --- because ---
+ // argument expression's type is not compatible with formal parameter type;
+ // found : B&1
+ // required: ?BB
+}
diff --git a/test/files/pos/t7782b.scala b/test/files/pos/t7782b.scala
new file mode 100644
index 0000000000..09da4a5c5b
--- /dev/null
+++ b/test/files/pos/t7782b.scala
@@ -0,0 +1,25 @@
+package pack
+
+object Test {
+ import O.empty
+ empty // this will trigger completion of `test`
+ // with skolemizationLevel = 1
+}
+
+object O {
+ // order matters (!!!)
+
+ // this order breaks under 2.11.x
+ def empty(implicit a: Any): Any = ???
+ def empty[E]: C[E] = ???
+}
+
+abstract class C[E] {
+ def foo[BB](f: BB)
+ def test[B](f: B): Any = foo(f)
+ // error: no type parameters for method foo: (<param> f: BB)scala.this.Unit exist so that it can be applied to arguments (B&1)
+ // --- because ---
+ // argument expression's type is not compatible with formal parameter type;
+ // found : B&1
+ // required: ?BB
+}
diff --git a/test/files/pos/t7818.scala b/test/files/pos/t7818.scala
new file mode 100644
index 0000000000..77b99e7d5d
--- /dev/null
+++ b/test/files/pos/t7818.scala
@@ -0,0 +1,10 @@
+class Observable1[+T](val asJava: JObservable[_ <: T]) extends AnyVal {
+ private def foo[X](a: JObservable[X]): JObservable[X] = ???
+ // was generating a type error as the type of the RHS included an existential
+ // skolem based on the class type parameter `T`, which did not conform
+ // to the typer parameter of the extension method into which the RHS is
+ // transplanted.
+ def synchronize: Observable1[T] = new Observable1(foo(asJava))
+}
+
+class JObservable[T]
diff --git a/test/files/pos/t942/Amount_1.java b/test/files/pos/t942/Amount_1.java
new file mode 100644
index 0000000000..d9d37d127b
--- /dev/null
+++ b/test/files/pos/t942/Amount_1.java
@@ -0,0 +1,5 @@
+import java.util.concurrent.Callable;
+
+public abstract class Amount_1<Q> extends Object
+ implements Callable<Amount_1<?>> {
+}
diff --git a/test/files/pos/t942/Test_2.scala b/test/files/pos/t942/Test_2.scala
new file mode 100644
index 0000000000..3cc84dae3c
--- /dev/null
+++ b/test/files/pos/t942/Test_2.scala
@@ -0,0 +1,3 @@
+abstract class Foo {
+ val x: Amount_1[Foo]
+}
diff --git a/test/files/run/WeakHashSetTest.scala b/test/files/run/WeakHashSetTest.scala
new file mode 100644
index 0000000000..3c8f380150
--- /dev/null
+++ b/test/files/run/WeakHashSetTest.scala
@@ -0,0 +1,174 @@
+object Test {
+ def main(args: Array[String]) {
+ val test = scala.reflect.internal.util.WeakHashSetTest
+ test.checkEmpty
+ test.checkPlusEquals
+ test.checkPlusEqualsCollisions
+ test.checkRehashing
+ test.checkRehashCollisions
+ test.checkFindOrUpdate
+ test.checkMinusEquals
+ test.checkMinusEqualsCollisions
+ test.checkClear
+ test.checkIterator
+ test.checkIteratorCollisions
+
+ // This test is commented out because it relies on gc behavior which isn't reliable enough in an automated environment
+ // test.checkRemoveUnreferencedObjects
+ }
+}
+
+// put the main test object in the same package as WeakHashSet because
+// it uses the package private "diagnostics" method
+package scala.reflect.internal.util {
+
+ object WeakHashSetTest {
+ // a class guaranteed to provide hash collisions
+ case class Collider(x : String) extends Comparable[Collider] with Serializable {
+ override def hashCode = 0
+ def compareTo(y : Collider) = this.x compareTo y.x
+ }
+
+ // basic emptiness check
+ def checkEmpty {
+ val hs = new WeakHashSet[String]()
+ assert(hs.size == 0)
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure += works
+ def checkPlusEquals {
+ val hs = new WeakHashSet[String]()
+ val elements = List("hello", "goodbye")
+ elements foreach (hs += _)
+ assert(hs.size == 2)
+ assert(hs contains "hello")
+ assert(hs contains "goodbye")
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure += works when there are collisions
+ def checkPlusEqualsCollisions {
+ val hs = new WeakHashSet[Collider]()
+ val elements = List("hello", "goodbye") map Collider
+ elements foreach (hs += _)
+ assert(hs.size == 2)
+ assert(hs contains Collider("hello"))
+ assert(hs contains Collider("goodbye"))
+ hs.diagnostics.fullyValidate
+ }
+
+ // add a large number of elements to force rehashing and then validate
+ def checkRehashing {
+ val size = 200
+ val hs = new WeakHashSet[String]()
+ val elements = (0 until size).toList map ("a" + _)
+ elements foreach (hs += _)
+ elements foreach {i => assert(hs contains i)}
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure rehashing works properly when the set is rehashed
+ def checkRehashCollisions {
+ val size = 200
+ val hs = new WeakHashSet[Collider]()
+ val elements = (0 until size).toList map {x => Collider("a" + x)}
+ elements foreach (hs += _)
+ elements foreach {i => assert(hs contains i)}
+ hs.diagnostics.fullyValidate
+ }
+
+ // test that unreferenced objects are removed
+ // not run in an automated environment because gc behavior can't be relied on
+ def checkRemoveUnreferencedObjects {
+ val size = 200
+ val hs = new WeakHashSet[Collider]()
+ val elements = (0 until size).toList map {x => Collider("a" + x)}
+ elements foreach (hs += _)
+ // don't throw the following into a retained collection so gc
+ // can remove them
+ for (i <- 0 until size) {
+ hs += Collider("b" + i)
+ }
+ System.gc()
+ Thread.sleep(1000)
+ assert(hs.size == 200)
+ elements foreach {i => assert(hs contains i)}
+ for (i <- 0 until size) {
+ assert(!(hs contains Collider("b" + i)))
+ }
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure findOrUpdate returns the originally entered element
+ def checkFindOrUpdate {
+ val size = 200
+ val hs = new WeakHashSet[Collider]()
+ val elements = (0 until size).toList map {x => Collider("a" + x)}
+ elements foreach {x => assert(hs findEntryOrUpdate x eq x)}
+ for (i <- 0 until size) {
+ // when we do a lookup the result should be the same reference we
+ // original put in
+ assert(hs findEntryOrUpdate(Collider("a" + i)) eq elements(i))
+ }
+ hs.diagnostics.fullyValidate
+ }
+
+ // check -= functionality
+ def checkMinusEquals {
+ val hs = new WeakHashSet[String]()
+ val elements = List("hello", "goodbye")
+ elements foreach (hs += _)
+ hs -= "goodbye"
+ assert(hs.size == 1)
+ assert(hs contains "hello")
+ assert(!(hs contains "goodbye"))
+ hs.diagnostics.fullyValidate
+ }
+
+ // check -= when there are collisions
+ def checkMinusEqualsCollisions {
+ val hs = new WeakHashSet[Collider]
+ val elements = List(Collider("hello"), Collider("goodbye"))
+ elements foreach (hs += _)
+ hs -= Collider("goodbye")
+ assert(hs.size == 1)
+ assert(hs contains Collider("hello"))
+ assert(!(hs contains Collider("goodbye")))
+ hs -= Collider("hello")
+ assert(hs.size == 0)
+ assert(!(hs contains Collider("hello")))
+ hs.diagnostics.fullyValidate
+ }
+
+ // check that the clear method actually cleans everything
+ def checkClear {
+ val size = 200
+ val hs = new WeakHashSet[String]()
+ val elements = (0 until size).toList map ("a" + _)
+ elements foreach (hs += _)
+ hs.clear()
+ assert(hs.size == 0)
+ elements foreach {i => assert(!(hs contains i))}
+ hs.diagnostics.fullyValidate
+ }
+
+ // check that the iterator covers all the contents
+ def checkIterator {
+ val hs = new WeakHashSet[String]()
+ val elements = (0 until 20).toList map ("a" + _)
+ elements foreach (hs += _)
+ assert(elements.iterator.toList.sorted == elements.sorted)
+ hs.diagnostics.fullyValidate
+ }
+
+ // check that the iterator covers all the contents even when there is a collision
+ def checkIteratorCollisions {
+ val hs = new WeakHashSet[Collider]
+ val elements = (0 until 20).toList map {x => Collider("a" + x)}
+ elements foreach (hs += _)
+ assert(elements.iterator.toList.sorted == elements.sorted)
+ hs.diagnostics.fullyValidate
+ }
+ }
+}
diff --git a/test/files/run/predef-cycle.scala b/test/files/run/predef-cycle.scala
new file mode 100644
index 0000000000..ab147688bc
--- /dev/null
+++ b/test/files/run/predef-cycle.scala
@@ -0,0 +1,71 @@
+class Force {
+ val t1 = new Thread {
+ override def run() {
+ scala.`package`
+ }
+ }
+ val t2 = new Thread {
+ override def run() {
+ scala.Predef
+ }
+ }
+ t1.start()
+ t2.start()
+ t1.join()
+ t2.join()
+}
+
+object Test {
+ def main(args: Array[String]) {
+ new Force()
+ }
+}
+
+/* Was deadlocking:
+"Thread-2" prio=5 tid=7f9637268000 nid=0x119601000 in Object.wait() [119600000]
+ java.lang.Thread.State: RUNNABLE
+ at scala.Predef$.<init>(Predef.scala:90)
+ at scala.Predef$.<clinit>(Predef.scala)
+ at Force$$anon$2.run(predef-cycle.scala:10)
+
+"Thread-1" prio=5 tid=7f9637267800 nid=0x1194fe000 in Object.wait() [1194fb000]
+ java.lang.Thread.State: RUNNABLE
+ at scala.collection.immutable.Set$Set4.$plus(Set.scala:127)
+ at scala.collection.immutable.Set$Set4.$plus(Set.scala:121)
+ at scala.collection.mutable.SetBuilder.$plus$eq(SetBuilder.scala:24)
+ at scala.collection.mutable.SetBuilder.$plus$eq(SetBuilder.scala:22)
+ at scala.collection.generic.Growable$$anonfun$$plus$plus$eq$1.apply(Growable.scala:48)
+ at scala.collection.generic.Growable$$anonfun$$plus$plus$eq$1.apply(Growable.scala:48)
+ at scala.collection.immutable.List.foreach(List.scala:318)
+ at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
+ at scala.collection.mutable.SetBuilder.$plus$plus$eq(SetBuilder.scala:22)
+ at scala.collection.TraversableLike$class.to(TraversableLike.scala:629)
+ at scala.collection.AbstractTraversable.to(Traversable.scala:105)
+ at scala.collection.TraversableOnce$class.toSet(TraversableOnce.scala:267)
+ at scala.collection.AbstractTraversable.toSet(Traversable.scala:105)
+ at scala.runtime.ScalaRunTime$.<init>(ScalaRunTime.scala:50)
+ at scala.runtime.ScalaRunTime$.<clinit>(ScalaRunTime.scala)
+ at scala.collection.mutable.HashTable$HashUtils$class.elemHashCode(HashTable.scala)
+ at scala.collection.mutable.HashMap.elemHashCode(HashMap.scala:39)
+ at scala.collection.mutable.HashTable$class.findOrAddEntry(HashTable.scala:161)
+ at scala.collection.mutable.HashMap.findOrAddEntry(HashMap.scala:39)
+ at scala.collection.mutable.HashMap.put(HashMap.scala:75)
+ at scala.collection.mutable.HashMap.update(HashMap.scala:80)
+ at scala.sys.SystemProperties$.addHelp(SystemProperties.scala:64)
+ at scala.sys.SystemProperties$.bool(SystemProperties.scala:68)
+ at scala.sys.SystemProperties$.noTraceSupression$lzycompute(SystemProperties.scala:80)
+ - locked <7b8b0e228> (a scala.sys.SystemProperties$)
+ at scala.sys.SystemProperties$.noTraceSupression(SystemProperties.scala:80)
+ at scala.util.control.NoStackTrace$.<init>(NoStackTrace.scala:31)
+ at scala.util.control.NoStackTrace$.<clinit>(NoStackTrace.scala)
+ at scala.util.control.NoStackTrace$class.fillInStackTrace(NoStackTrace.scala:22)
+ at scala.util.control.BreakControl.fillInStackTrace(Breaks.scala:93)
+ at java.lang.Throwable.<init>(Throwable.java:181)
+ at scala.util.control.BreakControl.<init>(Breaks.scala:93)
+ at scala.util.control.Breaks.<init>(Breaks.scala:28)
+ at scala.collection.Traversable$.<init>(Traversable.scala:96)
+ at scala.collection.Traversable$.<clinit>(Traversable.scala)
+ at scala.package$.<init>(package.scala:46)
+ at scala.package$.<clinit>(package.scala)
+ at Force$$anon$1.run(predef-cycle.scala:4)
+ */ \ No newline at end of file
diff --git a/test/files/run/t7269.scala b/test/files/run/t7269.scala
new file mode 100644
index 0000000000..d22e57dfee
--- /dev/null
+++ b/test/files/run/t7269.scala
@@ -0,0 +1,32 @@
+import scala.collection.JavaConversions._
+import scala.collection.mutable
+
+object Test extends App {
+
+ def testMap(): Unit = {
+ val mapJ = new java.util.HashMap[Int, String]
+ val mapS: mutable.Map[Int, String] = mapJ
+
+ (10 to 20).foreach(i => mapS += ((i, i.toString)))
+ assert(11 == mapS.size)
+
+ // ConcurrentModificationException thrown in the following line
+ mapS.retain((i, str) => i % 2 == 0)
+ assert(6 == mapS.size)
+ }
+
+ def testSet(): Unit = {
+ val mapJ = new java.util.HashSet[Int]
+ val mapS: mutable.Set[Int] = mapJ
+
+ (10 to 20).foreach(i => mapS += i)
+ assert(11 == mapS.size)
+
+ // ConcurrentModificationException thrown in the following line
+ mapS.retain((i) => i % 2 == 0)
+ assert(6 == mapS.size)
+ }
+
+ testSet()
+ testMap()
+}
diff --git a/test/files/run/t7398.scala b/test/files/run/t7398.scala
index dd59697b71..493c4dcf40 100644
--- a/test/files/run/t7398.scala
+++ b/test/files/run/t7398.scala
@@ -3,11 +3,9 @@ import scala.tools.partest._
object Test extends CompilerTest {
import global._
- // This way we auto-pass on non-java8 since there's nothing to check
- override lazy val units: List[CompilationUnit] = testUnderJavaAtLeast("1.8") {
+ override lazy val units: List[CompilationUnit] = {
+ // This test itself does not depend on JDK8.
javaCompilationUnits(global)(defaultMethodSource)
- } otherwise {
- Nil
}
private def defaultMethodSource = """
diff --git a/test/files/run/t7775.scala b/test/files/run/t7775.scala
new file mode 100644
index 0000000000..5fb0327611
--- /dev/null
+++ b/test/files/run/t7775.scala
@@ -0,0 +1,17 @@
+import scala.concurrent.{duration, future, Await, ExecutionContext}
+import scala.tools.nsc.Settings
+import ExecutionContext.Implicits.global
+
+// Was failing pretty regularly with a ConcurrentModificationException as
+// WrappedProperties#systemProperties iterated directly over the mutable
+// global system properties map.
+object Test {
+ def main(args: Array[String]) {
+ val tries = 1000 // YMMV
+ val compiler = future {
+ for(_ <- 1 to tries) new Settings(_ => {})
+ }
+ for(i <- 1 to tries * 10) System.setProperty(s"foo$i", i.toString)
+ Await.result(compiler, duration.Duration.Inf)
+ }
+}
diff --git a/test/files/run/t7779.scala b/test/files/run/t7779.scala
new file mode 100644
index 0000000000..db32cb751f
--- /dev/null
+++ b/test/files/run/t7779.scala
@@ -0,0 +1,67 @@
+// -Xmax-classfile-length doesn't compress top-level classes.
+// class :::::::::::::::::::::::::::::::::::::::::::::::::
+
+trait Marker
+
+class Short extends Marker
+
+// We just test with member classes
+object O {
+ object ::::::::::::::::::::::::::::::::::::::::::::::::: extends Marker
+}
+class C {
+ class D {
+ class ::::::::::::::::::::::::::::::::::::::::::::::::: extends Marker
+ }
+}
+
+package pack {
+ // abbreviates to: $colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon to $read$$iw$$iw$$colon$colon$colon$colon$colon$colon$colon$colon$$$$c39b3f245029fbed9732fc888d44231b$$$$on$colon$colon$colon$colon$colon$colon$colon$colon$colon$colon
+ // class :::::::::::::::::::::::::::::::::::::::::::::::::
+
+ class Short extends Marker
+
+ // We just test with member classes
+ object O {
+ object ::::::::::::::::::::::::::::::::::::::::::::::::: extends Marker
+ }
+ class C {
+ class D {
+ class ::::::::::::::::::::::::::::::::::::::::::::::::: extends Marker
+ }
+ }
+ package p2 {
+ class Short extends Marker
+
+ object O {
+ object ::::::::::::::::::::::::::::::::::::::::::::::::: extends Marker
+ }
+ class C {
+ class D {
+ class ::::::::::::::::::::::::::::::::::::::::::::::::: extends Marker
+ }
+ }
+ }
+}
+
+
+object Test extends App {
+ import reflect.runtime.universe._
+ def test[T: TypeTag] = {
+ val tt = typeTag[T]
+ val clz = tt.mirror.runtimeClass(tt.tpe)
+ assert(classOf[Marker].isAssignableFrom(clz), clz.toString)
+ }
+
+ test[Short]
+ test[O.:::::::::::::::::::::::::::::::::::::::::::::::::.type]
+ test[C#D#`:::::::::::::::::::::::::::::::::::::::::::::::::`]
+
+ test[pack.Short]
+ test[pack.O.:::::::::::::::::::::::::::::::::::::::::::::::::.type]
+ test[pack.C#D#`:::::::::::::::::::::::::::::::::::::::::::::::::`]
+
+ test[pack.p2.Short]
+ test[pack.p2.O.:::::::::::::::::::::::::::::::::::::::::::::::::.type]
+ test[pack.p2.C#D#`:::::::::::::::::::::::::::::::::::::::::::::::::`]
+}
diff --git a/test/files/run/t7825.scala b/test/files/run/t7825.scala
new file mode 100644
index 0000000000..65ca06fdfc
--- /dev/null
+++ b/test/files/run/t7825.scala
@@ -0,0 +1,34 @@
+import scala.tools.partest._
+
+object Test extends CompilerTest {
+ import global._
+
+ override lazy val units: List[CompilationUnit] = {
+ // We can test this on JDK6.
+ javaCompilationUnits(global)(defaultMethodSource) ++ compilationUnits(global)(scalaExtendsDefault)
+ }
+
+ private def defaultMethodSource = """
+public interface Iterator<E> {
+ boolean hasNext();
+ E next();
+ default void remove() {
+ throw new UnsupportedOperationException("remove");
+ }
+}
+ """
+
+ private def scalaExtendsDefault = """
+object Test {
+ object X extends Iterator[String] {
+ def hasNext = true
+ def next = "!"
+ }
+}
+ """
+
+ // We're only checking we that the Scala compilation unit passes refchecks
+ // No further checks are needed here.
+ def check(source: String, unit: global.CompilationUnit): Unit = {
+ }
+}
diff --git a/test/files/run/typed-annotated.check b/test/files/run/typed-annotated.check
new file mode 100644
index 0000000000..d81cc0710e
--- /dev/null
+++ b/test/files/run/typed-annotated.check
@@ -0,0 +1 @@
+42
diff --git a/test/files/run/typed-annotated/Macros_1.scala b/test/files/run/typed-annotated/Macros_1.scala
new file mode 100644
index 0000000000..dd18c63d90
--- /dev/null
+++ b/test/files/run/typed-annotated/Macros_1.scala
@@ -0,0 +1,17 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+class ann extends scala.annotation.StaticAnnotation
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ // val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), Ident(newTypeName("Int")))
+ val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), TypeTree(weakTypeOf[Int]))
+ c.Expr[Unit](Block(
+ List(ValDef(Modifiers(), newTermName("x"), tpt, Literal(Constant(42)))),
+ Apply(Ident(newTermName("println")), List(Ident(newTermName("x"))))))
+ }
+
+ def foo = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/typed-annotated/Test_2.scala b/test/files/run/typed-annotated/Test_2.scala
new file mode 100644
index 0000000000..acfddae942
--- /dev/null
+++ b/test/files/run/typed-annotated/Test_2.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ Macros.foo
+} \ No newline at end of file