From b3ac78fca13634aab203ae727f91b4a759f936b3 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 9 Jun 2021 20:01:00 +0200 Subject: [PATCH] TyperState#commit: Flush reporter before committing Flushing the reporter can force messages (apparently because of `HideNonSensicalMessages#isHidden`) which can affect the TyperState we're in the process of committing, so make sure that flushing happens before committing to not trigger any assertion. Fixes #12736 --- compiler/src/dotty/tools/dotc/core/TyperState.scala | 2 +- tests/neg/i12736b.scala | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i12736b.scala diff --git a/compiler/src/dotty/tools/dotc/core/TyperState.scala b/compiler/src/dotty/tools/dotc/core/TyperState.scala index 0f5ea0ac431d..2c41fc8f0231 100644 --- a/compiler/src/dotty/tools/dotc/core/TyperState.scala +++ b/compiler/src/dotty/tools/dotc/core/TyperState.scala @@ -140,6 +140,7 @@ class TyperState() { Stats.record("typerState.commit") assert(isCommittable, s"$this is not committable") assert(!isCommitted, s"$this is already committed") + reporter.flush() setCommittable(false) val targetState = ctx.typerState assert(!targetState.isCommitted, s"Attempt to commit $this into already committed $targetState") @@ -152,7 +153,6 @@ class TyperState() { else targetState.mergeConstraintWith(this) targetState.gc() - reporter.flush() isCommitted = true } diff --git a/tests/neg/i12736b.scala b/tests/neg/i12736b.scala new file mode 100644 index 000000000000..c7db2f7a92ea --- /dev/null +++ b/tests/neg/i12736b.scala @@ -0,0 +1,6 @@ +object Test { + def apply[S](r: Any)(using DoesntExist): Any = r // error + + def test(o: Option[Any]) = + o.map(x => Test(doesntExist, x)) // error +}