Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10299 from scalacenter/tasty/upgrade-3.2.2-extras
Tasty Reader: test APPLYsigpoly, fail in forced annotations
- Loading branch information
Showing
8 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TestApplySigPoly_fail.scala:6: error: Unsupported Scala 3 signature polymorphic application in an annotation of method annotatedMethod; note that complex trees are not yet supported for Annotations; found in method annotatedMethod in object tastytest.ApplySigPoly. | ||
def test = TestApplySigPolyPre.forceAnnots[ApplySigPoly.type, ApplySigPoly.boxAnnot] | ||
^ | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package tastytest | ||
|
||
object TestApplySigPoly { | ||
|
||
// force an annotation tree with an APPLYsigpoly node | ||
def test = TestApplySigPolyPre.forceAnnots[ApplySigPoly.type, ApplySigPoly.boxAnnot] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tastytest | ||
|
||
import scala.language.experimental.macros | ||
|
||
import scala.reflect.macros.blackbox.Context | ||
|
||
object TestApplySigPolyPre { | ||
|
||
/** forces annotations of type `A` on methods from class `T` */ | ||
def forceAnnots[T, A]: Unit = macro Macros.forceAnnotsImpl[T, A] | ||
|
||
object Macros { | ||
def forceAnnotsImpl[T, A](c: Context)(implicit T: c.WeakTypeTag[T], A: c.WeakTypeTag[A]): c.Expr[Unit] = { | ||
import c.universe._ | ||
for { | ||
method <- weakTypeOf[T].members.filter(_.isMethod) | ||
annot <- method.annotations.find(_.tree.tpe =:= weakTypeOf[A]) | ||
} { | ||
annot.tree | ||
} | ||
c.Expr[Unit](q"()") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package tastytest | ||
|
||
object ApplySigPoly { | ||
|
||
class Foo { | ||
def foo(x: Int): Int = x | ||
} | ||
|
||
private val lookup = java.lang.invoke.MethodHandles.lookup() | ||
private val mt = java.lang.invoke.MethodType.methodType(classOf[Int], classOf[Int]); | ||
|
||
val mh = lookup.findVirtual(classOf[Foo], "foo", mt) | ||
|
||
val self = new Foo() | ||
|
||
class boxAnnot(val value: Int) extends scala.annotation.Annotation | ||
|
||
@boxAnnot(mh.invokeExact(self, 23): Int) | ||
def annotatedMethod: Int = 23 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tastytest | ||
|
||
object TestApplySigPoly extends Suite("TestApplySigPoly") { | ||
|
||
test("construct class with APPLYsigpoly in parent") { | ||
val subbox = new ApplySigPoly.SubBox() | ||
assert(subbox.value == 23) | ||
} | ||
|
||
test("call method with APPLYsigpoly in annotation") { | ||
assert(ApplySigPoly.annotatedMethod == 23) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tastytest | ||
|
||
object ApplySigPoly { | ||
|
||
class Foo { | ||
def foo(x: Int): Int = x | ||
} | ||
|
||
private val lookup = java.lang.invoke.MethodHandles.lookup() | ||
private val mt = java.lang.invoke.MethodType.methodType(classOf[Int], classOf[Int]); | ||
|
||
val mh = lookup.findVirtual(classOf[Foo], "foo", mt) | ||
|
||
class IntBox(val value: Int) | ||
|
||
val self = new Foo() | ||
|
||
// There should appear a APPLYsigpoly node in the parent of SubBox | ||
class SubBox extends IntBox(mh.invokeExact(self, 23): Int) | ||
|
||
class boxAnnot(val value: Int) extends scala.annotation.Annotation | ||
|
||
@boxAnnot(mh.invokeExact(self, 23): Int) | ||
def annotatedMethod: Int = 23 | ||
} |