Skip to content

Commit 995cfc1

Browse files
committed
Add check for #18806
1 parent 27dbeb3 commit 995cfc1

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

tests/run-macros/i18806.check

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hi

tests/run-macros/i18806/Macro_1.scala

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import scala.annotation.{experimental, MacroAnnotation}
2+
import scala.quoted._
3+
4+
@experimental
5+
class gen extends MacroAnnotation:
6+
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
7+
import quotes.reflect._
8+
tree match
9+
case ClassDef(name, ctr, parents, self, body) =>
10+
val cls = tree.symbol
11+
// val meth = cls.methodMember("foo").head
12+
// val fooTpe = cls.typeRef.memberType(meth)
13+
14+
val overrideTpe = MethodType(Nil)(_ => Nil, _ => defn.StringClass.typeRef)
15+
16+
val fooOverrideSym = Symbol.newMethod(cls, "foo", overrideTpe, Flags.Override, Symbol.noSymbol)
17+
18+
val fooDef = DefDef(fooOverrideSym, _ => Some(Literal(StringConstant("hi"))))
19+
20+
val newClassDef = ClassDef.copy(tree)(name, ctr, parents, self, fooDef :: body)
21+
List(newClassDef)
22+
case _ =>
23+
report.error("Annotation only supports `class`")
24+
List(tree)

tests/run-macros/i18806/Test_2.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.annotation.experimental
2+
3+
class Base:
4+
def foo(): Object = ???
5+
6+
@experimental
7+
@gen
8+
class Sub extends Base
9+
// > override def foo(): String = "hi"
10+
11+
@experimental
12+
@main def Test(): Unit =
13+
val sub = new Sub
14+
println(sub.foo())

0 commit comments

Comments
 (0)