From 1cd30d2491a9e68a8f200362e6e5d1539d067be1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 22 Jan 2020 22:32:03 +0100 Subject: [PATCH] Fix #8072: Synchronize cancelling timer task properly Concurrent programming is hard ... I tested that it works now by setting the timeout from 500 to 1. I gots lots of cancellations but no discrepancies in the error counts. --- .../src/dotty/tools/dotc/typer/ImportSuggestions.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index a9c11c0314b0..0843adb925f1 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -186,8 +186,11 @@ trait ImportSuggestions with typedImplicit(candidate, expectedType, argument, span)( given ctx.fresh.setExploreTyperState()).isSuccess finally - task.cancel() - ctx.run.isCancelled = false + if task.cancel() then // timer task has not run yet + assert(!ctx.run.isCancelled) + else + while !ctx.run.isCancelled do () // wait until timer task has run to completion + ctx.run.isCancelled = false } end deepTest