Skip to content
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

Fix sneaky binary incompatibility in Discover.scala #2752

Merged
merged 11 commits into from
Sep 18, 2023
17 changes: 13 additions & 4 deletions main/define/src/mill/define/Discover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ import scala.reflect.macros.blackbox
* the `T.command` methods we find. This mapping from `Class[_]` to `MainData`
* can then be used later to look up the `MainData` for any module.
*/
case class Discover[T] private (val value: Map[
Class[_],
(Seq[String], Seq[mainargs.MainData[_, _]])
])
case class Discover[T] private (
val value: Map[
Class[_],
(Seq[String], Seq[mainargs.MainData[_, _]])
],
dummy: Int = 0 /* avoid conflict with Discover.apply(value: Map) below*/
) {
def this(value: Map[Class[_], Seq[mainargs.MainData[_, _]]]) =
this(value.mapValues((Nil, _)).toMap)
lihaoyi marked this conversation as resolved.
Show resolved Hide resolved
}

object Discover {
def apply2[T](value: Map[Class[_], (Seq[String], Seq[mainargs.MainData[_, _]])]): Discover[T] =
new Discover[T](value)

def apply[T](value: Map[Class[_], Seq[mainargs.MainData[_, _]]]): Discover[T] =
new Discover[T](value.mapValues((Nil, _)).toMap)
lihaoyi marked this conversation as resolved.
Show resolved Hide resolved

def apply[T]: Discover[T] = macro Router.applyImpl[T]

private class Router(val ctx: blackbox.Context) extends mainargs.Macros(ctx) {
Expand Down
2 changes: 1 addition & 1 deletion main/resolve/src/mill/resolve/Resolve.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ trait Resolve[T] {
nullCommandDefaults: Boolean
): Either[String, Seq[T]] = {
val rootResolved = ResolveCore.Resolved.Module(Segments(), rootModule.getClass)
val allPossibleNames = rootModule.millDiscover.value.values.flatMap(_._1).toSet
val resolved =
ResolveCore.resolve(rootModule, sel.value.toList, rootResolved, Segments()) match {
case ResolveCore.Success(value) => Right(value)
case ResolveCore.NotFound(segments, found, next, possibleNexts) =>
val allPossibleNames = rootModule.millDiscover.value.values.flatMap(_._1).toSet
Left(ResolveNotFoundHandler(sel, segments, found, next, possibleNexts, allPossibleNames))
case ResolveCore.Error(value) => Left(value)
}
Expand Down