From e506f5c2fdca5d387b0ac560bb4235cea51cfe79 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 10 May 2021 19:19:11 +0200 Subject: [PATCH] Don't chain conversions when looking for import suggestions Fixes #12394. --- .../src/dotty/tools/dotc/typer/ImportSuggestions.scala | 7 +++++-- tests/neg/missing-implicit-3.check | 4 +--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index 7c11508ece65..8232a64fe747 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -167,12 +167,15 @@ trait ImportSuggestions: allCandidates.map(_.implicitRef.underlyingRef.symbol).toSet } + def testContext(): Context = + ctx.fresh.retractMode(Mode.ImplicitsEnabled).setExploreTyperState() + /** Test whether the head of a given instance matches the expected type `pt`, * ignoring any dependent implicit arguments. */ def shallowTest(ref: TermRef): Boolean = System.currentTimeMillis < deadLine - && inContext(ctx.fresh.setExploreTyperState()) { + && inContext(testContext()) { def test(pt: Type): Boolean = pt match case ViewProto(argType, OrType(rt1, rt2)) => // Union types do not constrain results, since comparison with a union @@ -209,7 +212,7 @@ trait ImportSuggestions: try timer.schedule(task, testOneImplicitTimeOut) typedImplicit(candidate, expectedType, argument, span)( - using ctx.fresh.setExploreTyperState()).isSuccess + using testContext()).isSuccess finally if task.cancel() then // timer task has not run yet assert(!ctx.run.isCancelled) diff --git a/tests/neg/missing-implicit-3.check b/tests/neg/missing-implicit-3.check index 206f97866186..a41f2bba8a3e 100644 --- a/tests/neg/missing-implicit-3.check +++ b/tests/neg/missing-implicit-3.check @@ -19,9 +19,7 @@ longer explanation available when compiling with `-explain` | ^^^^^^^ | value days is not a member of Int, but could be made available as an extension method. | - | One of the following imports might fix the problem: + | The following import might fix the problem: | | import concurrent.duration.DurationInt - | import concurrent.duration.DurationLong - | import concurrent.duration.DurationDouble |