From 21425411649999b6377207c7bdcf0bb300583ff3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 8 Mar 2020 11:20:32 +0100 Subject: [PATCH] Fix #5005: Weaken assertion when trying to compute an ErasedValueType Allow for missing erased values when errors were reported previously --- compiler/src/dotty/tools/dotc/core/TypeErasure.scala | 9 +++++---- tests/neg/i5005.scala | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/neg/i5005.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index d74be5cb95c9..8499c897e304 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -550,11 +550,12 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean private def eraseDerivedValueClassRef(tref: TypeRef)(implicit ctx: Context): Type = { val cls = tref.symbol.asClass val underlying = underlyingOfValueClass(cls) - if (underlying.exists && !isCyclic(cls)) { + if underlying.exists && !isCyclic(cls) then val erasedValue = valueErasure(underlying) - assert(erasedValue.exists, i"no erasure for $underlying") - ErasedValueType(tref, erasedValue) - } + if erasedValue.exists then ErasedValueType(tref, erasedValue) + else + assert(ctx.reporter.errorsReported, i"no erasure for $underlying") + NoType else NoType } diff --git a/tests/neg/i5005.scala b/tests/neg/i5005.scala new file mode 100644 index 000000000000..5dfcfc37b1a3 --- /dev/null +++ b/tests/neg/i5005.scala @@ -0,0 +1,6 @@ + +case class i0 (i0: i1) extends AnyVal +trait i1 extends i0 // error + +trait F[x] extends AnyVal // error +case class G[x](a: F[x]) extends F[x] // error // error