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 7cd28ef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/run/i18806.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi
24 changes: 24 additions & 0 deletions tests/run/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)
10 changes: 10 additions & 0 deletions tests/run/i18806/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Base:
def foo(): Object = ???

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

@main def Test(): Unit =
val sub = new Sub
println(sub.foo())

0 comments on commit 7cd28ef

Please sign in to comment.