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

Try to fix deprecated discover warning #3711

Merged
merged 6 commits into from
Oct 10, 2024
Merged
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
11 changes: 10 additions & 1 deletion main/define/src/mill/define/Discover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,20 @@ object Discover {
}
if overridesRoutes._1.nonEmpty || overridesRoutes._2.nonEmpty || overridesRoutes._3.nonEmpty
} yield {
val lhs0 = discoveredModuleType match {
// Explicitly do not de-alias type refs, so type aliases to deprecated
// types do not result in spurious deprecation warnings appearing
case tr: TypeRef => tr
// Other types are fine
case _ => discoveredModuleType.typeSymbol.asClass.toType
}

val lhs = q"classOf[$lhs0]"

// by wrapping the `overridesRoutes` in a lambda function we kind of work around
// the problem of generating a *huge* macro method body that finally exceeds the
// JVM's maximum allowed method size
val overridesLambda = q"(() => $overridesRoutes)()"
val lhs = q"classOf[${discoveredModuleType.typeSymbol.asClass}]"
q"$lhs -> $overridesLambda"
}

Expand Down
20 changes: 10 additions & 10 deletions runner/src/mill/runner/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ object CodeGen {
newScriptCode = objectData.name.applyTo(newScriptCode, wrapperObjectName)
newScriptCode = objectData.obj.applyTo(newScriptCode, "abstract class")

val millDiscover =
if (segments.nonEmpty) ""
else
"""@_root_.scala.annotation.nowarn
| override lazy val millDiscover: _root_.mill.define.Discover = _root_.mill.define.Discover[this.type]""".stripMargin
val millDiscover = discoverSnippet(segments)

s"""$pkgLine
|$aliasImports
Expand Down Expand Up @@ -224,11 +220,7 @@ object CodeGen {
s"extends _root_.mill.main.RootModule.Subfolder "
}

val millDiscover =
if (segments.nonEmpty) ""
else
"""@_root_.scala.annotation.nowarn
| override lazy val millDiscover: _root_.mill.define.Discover = _root_.mill.define.Discover[this.type]""".stripMargin
val millDiscover = discoverSnippet(segments)

// User code needs to be put in a separate class for proper submodule
// object initialization due to https://github.com/scala/scala3/issues/21444
Expand All @@ -240,6 +232,14 @@ object CodeGen {

}

def discoverSnippet(segments: Seq[String]): String = {
if (segments.nonEmpty) ""
else
"""override lazy val millDiscover: _root_.mill.define.Discover = _root_.mill.define.Discover[this.type]
|""".stripMargin

}

private case class Snippet(var text: String = null, var start: Int = -1, var end: Int = -1) {
def applyTo(s: String, replacement: String): String =
s.patch(start, replacement.padTo(end - start, ' '), end - start)
Expand Down
Loading