diff options
Diffstat (limited to 'core')
4 files changed, 53 insertions, 9 deletions
diff --git a/core/src/main/scala/mill/discover/Discovered.scala b/core/src/main/scala/mill/discover/Discovered.scala index 9d46f196..0f3ced4e 100644 --- a/core/src/main/scala/mill/discover/Discovered.scala +++ b/core/src/main/scala/mill/discover/Discovered.scala @@ -53,10 +53,13 @@ object Discovered { !m.name.toString.contains(' ') } yield { val x = Ident(TermName(c.freshName())) - q"""mill.discover.Mirror.makeTargetPoint( + val t = q"""mill.discover.Mirror.makeTargetPoint( ${m.name.toString}, ($x: ${m.typeSignature.resultType}) => $x.${m.name.toTermName} )""" + + c.internal.setPos(t, m.pos) + t } diff --git a/core/src/main/scala/mill/discover/Router.scala b/core/src/main/scala/mill/discover/Router.scala index 90e50075..dda682b2 100644 --- a/core/src/main/scala/mill/discover/Router.scala +++ b/core/src/main/scala/mill/discover/Router.scala @@ -2,6 +2,7 @@ package mill.discover import ammonite.main.Compat import mill.define.Task +import mill.discover.Router.ArgSig import sourcecode.Compat.Context import scala.annotation.StaticAnnotation @@ -237,7 +238,18 @@ object Router{ Result.Success(rights) } } + + def makeReadCall[T: scopt.Read](dict: Map[String, String], + default: => Option[Any], + arg: ArgSig[_]) = { + read[T](dict, default, arg, implicitly[scopt.Read[T]].reads(_)) + } + def makeReadVarargsCall[T: scopt.Read](arg: ArgSig[_], + values: Seq[String]) = { + readVarargs[T](arg, values, implicitly[scopt.Read[T]].reads(_)) + } } + class Router [C <: Context](val c: C) { import c.universe._ def getValsOrMeths(curCls: Type): Iterable[MethodSymbol] = { @@ -260,6 +272,8 @@ class Router [C <: Context](val c: C) { } } + + def extractMethod(meth: MethodSymbol, curCls: c.universe.Type): c.universe.Tree = { val flattenedArgLists = meth.paramss.flatten def hasDefault(i: Int) = { @@ -334,19 +348,18 @@ class Router [C <: Context](val c: C) { val reader = if(vararg) q""" - mill.discover.Router.readVarargs[$docUnwrappedType]( + mill.discover.Router.makeReadVarargsCall[$docUnwrappedType]( $argSig, - $extrasSymbol, - implicitly[scopt.Read[$docUnwrappedType]].reads(_) + $extrasSymbol ) """ else q""" - mill.discover.Router.read[$docUnwrappedType]( + mill.discover.Router.makeReadCall[$docUnwrappedType]( $argListSymbol, $default, - $argSig, - implicitly[scopt.Read[$docUnwrappedType]].reads(_) + $argSig ) """ + c.internal.setPos(reader, meth.pos) (reader, argSig, vararg) } diff --git a/core/src/test/scala/mill/discover/DiscoveredTests.scala b/core/src/test/scala/mill/discover/DiscoveredTests.scala index dae7ff1b..843ec474 100644 --- a/core/src/test/scala/mill/discover/DiscoveredTests.scala +++ b/core/src/test/scala/mill/discover/DiscoveredTests.scala @@ -1,7 +1,9 @@ package mill.discover +import java.io.InputStreamReader + import utest._ -import mill.Module +import mill.{Module, T} import mill.util.TestUtil.test object DiscoveredTests extends TestSuite{ @@ -48,5 +50,32 @@ object DiscoveredTests extends TestSuite{ ) assert(mapped.toSet == expected.toSet) } + 'compileError - { + 'unserializableTarget - { + + object outer extends Module { + def single = mill.T{ new InputStreamReader(System.in) } + } + + val error = compileError("Discovered[outer.type]") + assert( + error.msg.contains("could not find implicit value"), + error.pos.contains("def single = mill.T{ new InputStreamReader(System.in) }") + ) + } + + 'unreadableCommand - { + object outer extends Module { + def single(in: InputStreamReader) = mill.T.command{ println(123) } + } + + val error = compileError("Discovered[outer.type]") + + assert( + error.msg.contains("could not find implicit value"), + error.pos.contains("def single(in: InputStreamReader) = mill.T.command{ println(123) }") + ) + } + } } } diff --git a/core/src/test/scala/mill/eval/EvaluationTests.scala b/core/src/test/scala/mill/eval/EvaluationTests.scala index ccb476e7..9a177b58 100644 --- a/core/src/test/scala/mill/eval/EvaluationTests.scala +++ b/core/src/test/scala/mill/eval/EvaluationTests.scala @@ -5,7 +5,6 @@ import mill.util.TestUtil.{Test, test} import mill.define.{Target, Task} import mill.{Module, T} import mill.discover.Discovered -import mill.eval.Evaluator import mill.util.{OSet, TestUtil} import utest._ import utest.framework.TestPath |