@@ -31,13 +31,14 @@ import transform.SymUtils._
3131import transform .TypeUtils ._
3232import transform .SyntheticMembers ._
3333import Hashable ._
34- import util .{Property , SourceFile , NoSource , Scheduler }
34+ import util .{Property , SourceFile , NoSource }
3535import config .Config
3636import config .Printers .{implicits , implicitsDetailed }
3737import collection .mutable
3838import reporting .trace
3939import annotation .tailrec
4040import scala .util .control .NonFatal
41+ import java .util .{Timer , TimerTask }
4142
4243import scala .annotation .internal .sharable
4344import scala .annotation .threadUnsafe
@@ -68,7 +69,10 @@ object Implicits {
6869 final val Extension = 4
6970 }
7071
71- val testOneImplicitTimeOut = 1000
72+ /** Timeout to test a single implicit value as a suggestion, in ms */
73+ val testOneImplicitTimeOut = 500
74+
75+ /** Global timeout to stop looking for further implicit suggestions, in ms */
7276 val suggestImplicitTimeOut = 10000
7377
7478 /** A common base class of contextual implicits and of-type implicits which
@@ -531,19 +535,21 @@ object Implicits {
531535 else Nil
532536
533537 def search (given ctx : Context ): List [TermRef ] =
534- val scheduler = new Scheduler ()
538+ val timer = new Timer ()
535539 val deadLine = System .currentTimeMillis() + suggestImplicitTimeOut
536540
537541 def test (ref : TermRef )(given Context ): Boolean =
538542 System .currentTimeMillis < deadLine
539543 && {
540- scheduler.scheduleAfter(testOneImplicitTimeOut) {
541- implicitsDetailed.println(i " Cancelling test of $ref when making suggestions for error in ${ctx.source}" )
542- ctx.run.isCancelled = true
544+ val task = new TimerTask {
545+ def run () =
546+ implicitsDetailed.println(i " Cancelling test of $ref when making suggestions for error in ${ctx.source}" )
547+ ctx.run.isCancelled = true
543548 }
549+ timer.schedule(task, testOneImplicitTimeOut)
544550 try qualifies(ref)
545551 finally
546- scheduler .cancel()
552+ task .cancel()
547553 ctx.run.isCancelled = false
548554 }
549555
@@ -552,7 +558,7 @@ object Implicits {
552558 .filterNot(root => defn.RootImportTypes .exists(_.symbol == root.symbol))
553559 // don't suggest things that are imported by default
554560 .flatMap(_.implicitMembers.filter(test))
555- finally scheduler.shutdown ()
561+ finally timer.cancel ()
556562 end search
557563 end suggestions
558564}
@@ -777,8 +783,9 @@ trait Implicits { self: Typer =>
777783 }
778784
779785 /** An addendum to an error message where the error might be fixed
780- * be some implicit value of type `pt` that is however not found.
781- * The addendum suggests suggests implicit imports that might fix the problem.
786+ * by some implicit value of type `pt` that is however not found.
787+ * The addendum suggests given imports that might fix the problem.
788+ * If there's nothing to suggest, an empty string is returned.
782789 */
783790 override def implicitSuggestionsFor (pt : Type )(given ctx : Context ): String =
784791 val suggestedRefs =
0 commit comments