Skip to content

Commit

Permalink
Merge pull request #10323 from som-snytt/issue/10589-case-implicit-param
Browse files Browse the repository at this point in the history
Reification knows only first param list is case accessor
  • Loading branch information
som-snytt committed Mar 13, 2023
2 parents 122de8d + ad96fc4 commit ca4831f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/reflect/scala/reflect/internal/ReificationSupport.scala
Expand Up @@ -124,7 +124,7 @@ trait ReificationSupport { self: SymbolTable =>
def mkAnnotation(trees: List[Tree]): List[Tree] = trees.map(mkAnnotation)

def mkParam(argss: List[List[Tree]], extraFlags: FlagSet = NoFlags, excludeFlags: FlagSet = DEFERRED): List[List[ValDef]] =
argss.map { args => args.map { mkParam(_, extraFlags, excludeFlags) } }
argss.map(_.map(mkParam(_, extraFlags, excludeFlags)))

def mkParam(tree: Tree, extraFlags: FlagSet, excludeFlags: FlagSet): ValDef = tree match {
case Typed(Ident(name: TermName), tpt) =>
Expand Down Expand Up @@ -344,8 +344,12 @@ trait ReificationSupport { self: SymbolTable =>
def apply(mods: Modifiers, name: TypeName, tparams: List[Tree],
constrMods: Modifiers, vparamss: List[List[Tree]],
earlyDefs: List[Tree], parents: List[Tree], selfType: Tree, body: List[Tree]): ClassDef = {
val extraFlags = PARAMACCESSOR | (if (mods.isCase) CASEACCESSOR else 0L)
val vparamss0 = mkParam(vparamss, extraFlags, excludeFlags = DEFERRED | PARAM)
val extraCaseFlags = if (mods.isCase) CASEACCESSOR else 0L
val excludeFlags = DEFERRED | PARAM
val vparamss0 =
if (vparamss.isEmpty) vparamss.asInstanceOf[List[List[ValDef]]]
else mkParam(vparamss.head :: Nil, PARAMACCESSOR | extraCaseFlags, excludeFlags) ++
mkParam(vparamss.tail, PARAMACCESSOR, excludeFlags)
val tparams0 = mkTparams(tparams)
val parents0 = gen.mkParents(mods,
if (mods.isCase) parents.filter {
Expand Down
6 changes: 6 additions & 0 deletions test/files/pos/t10589-case-implicit-param/cc_2.scala
@@ -0,0 +1,6 @@
// scalac: -Ymacro-annotations
trait T[A]

@macid
case class CC[A: T](x: A)

19 changes: 19 additions & 0 deletions test/files/pos/t10589-case-implicit-param/macros_1.scala
@@ -0,0 +1,19 @@
// scalac: -Ymacro-annotations

import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.whitebox.Context

class macid extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro macidMacro.impl
}
object macidMacro {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
new Macros[c.type](c).macidMacroImpl(annottees.toList)
}
}
class Macros[C <: Context](val c: C) {
import c.universe._
def macidMacroImpl(annottees: List[c.Expr[Any]]): c.Expr[Any] =
annottees(0)
}

0 comments on commit ca4831f

Please sign in to comment.