Skip to content

Commit

Permalink
WIP 47 - fix scanning of Cross modules in Discover macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Sep 6, 2024
1 parent 3e7e3d3 commit f986c19
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions main/define/src/mill/define/Discover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,24 @@ object Discover {
def applyImpl[T: Type](using Quotes): Expr[Discover[T]] = {
import quotes.reflect.*
val seen = mutable.Set.empty[TypeRepr]
val crossSym = Symbol.requiredClass("mill.define.Cross")
val crossArg = crossSym.typeMembers.filter(_.isTypeParam).head
val moduleSym = Symbol.requiredClass("mill.define.Module")
val deprecatedSym = Symbol.requiredClass("scala.deprecated")
def rec(tpe: TypeRepr): Unit = {
if (seen.add(tpe)) {
val typeSym = tpe.typeSymbol
for {
// for some reason mill.define.Foreign has NoSymbol as type member.
// for some reason mill.define.Foreign has NoSymbol as field member.
m <- typeSym.fieldMembers.filterNot(_ == Symbol.noSymbol).toList.sortBy(_.name.toString)
memberTpe = {
if m == Symbol.noSymbol then
report.errorAndAbort(s"no symbol found in $typeSym typemembers ${typeSym.typeMembers}", typeSym.pos.getOrElse(Position.ofMacroExpansion))
// try tpe.memberType(m)
// catch {
// case NonFatal(err) =>
// // report.errorAndAbort(s"Error getting member type for $m in $typeSym: ${err}", m.pos.getOrElse(Position.ofMacroExpansion))
// tpe.memberType(m.typeRef.dealias.typeSymbol)
// }
m.termRef
}
memberTpe = m.termRef
if memberTpe.baseClasses.contains(moduleSym)
} rec(memberTpe)

if (tpe.baseClasses.contains(crossSym)) {
val arg = tpe.memberType(crossArg)
val argSym = arg.typeSymbol
rec(tpe.memberType(argSym))
} {
rec(memberTpe)
memberTpe.asType match {
case '[mill.define.Cross[m]] =>
rec(TypeRepr.of[m])
case _ =>
() // no cross argument to extract
}
}
}
}
Expand Down

0 comments on commit f986c19

Please sign in to comment.