From da044bafd7f909088aab1e8e48035fe5b5baba70 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 21 Aug 2020 18:44:24 +0200 Subject: [PATCH 1/2] I observed a crash in replace when hacking ElimOpaque the compiler. It came down to the problem that a TermRef with a context function as underlying type was added to the context as lower bound after some errors were already reported. I could not track down the exact chain of effects. But anyway it's better to be defensive and not let junk enter the context. --- compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 27949f3fb899..48cddb32a7dd 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -484,6 +484,9 @@ trait ConstraintHandling { * way isSubType is organized. */ protected def addConstraint(param: TypeParamRef, bound: Type, fromBelow: Boolean)(using Context): Boolean = + if !bound.isValueTypeOrLambda then + assert(ctx.reporter.errorsReported) + return false /** When comparing lambdas we might get constraints such as * `A <: X0` or `A = List[X0]` where `A` is a constrained parameter From d26f1f4c57aa508ce6c55553730cc1f35720626e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 21 Aug 2020 22:11:35 +0200 Subject: [PATCH 2/2] Weaken assertion Turns out there are more situations where we can get junk in constraints, and in at least one of them (i7969.scala) this happens before errors are reported. So, it's better to just reject junk types and return false in addConstraint. --- compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 48cddb32a7dd..91d6b2c7fbf2 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -484,9 +484,7 @@ trait ConstraintHandling { * way isSubType is organized. */ protected def addConstraint(param: TypeParamRef, bound: Type, fromBelow: Boolean)(using Context): Boolean = - if !bound.isValueTypeOrLambda then - assert(ctx.reporter.errorsReported) - return false + if !bound.isValueTypeOrLambda then return false /** When comparing lambdas we might get constraints such as * `A <: X0` or `A = List[X0]` where `A` is a constrained parameter