Skip to content

Add check for #18806 #18856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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