Skip to content

Commit

Permalink
Add test for i18806
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Nov 6, 2023
1 parent f91e5d8 commit 73c4a40
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/run-macros/i18806.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi
24 changes: 24 additions & 0 deletions tests/run-macros/i18806/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import scala.annotation.{experimental, MacroAnnotation}
import scala.quoted._

@experimental
class gen extends MacroAnnotation:
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
import quotes.reflect._
tree match
case ClassDef(name, ctr, parents, self, body) =>
val cls = tree.symbol
// val meth = cls.methodMember("foo").head
// val fooTpe = cls.typeRef.memberType(meth)

val overrideTpe = MethodType(Nil)(_ => Nil, _ => defn.StringClass.typeRef)

val fooOverrideSym = Symbol.newMethod(cls, "foo", overrideTpe, Flags.Override, Symbol.noSymbol)

val fooDef = DefDef(fooOverrideSym, _ => Some(Literal(StringConstant("hi"))))

val newClassDef = ClassDef.copy(tree)(name, ctr, parents, self, fooDef :: body)
List(newClassDef)
case _ =>
report.error("Annotation only supports `class`")
List(tree)
14 changes: 14 additions & 0 deletions tests/run-macros/i18806/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.annotation.experimental

class Base:
def foo(): Object = ???

@experimental
@gen
class Sub extends Base
// > override def foo(): String = "hi"

@experimental
@main def Test(): Unit =
val sub = new Sub
println(sub.foo())
1 change: 1 addition & 0 deletions tests/run/i18806.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi

0 comments on commit 73c4a40

Please sign in to comment.