Skip to content

Commit 6126bf4

Browse files
committed
Give a warning when constraints are unsatisfiable
We will get some other error when checking bounds in PostTyper, unless we get a failure in Typer which might produce questionable errors. Having a warning here might be better than nothing. ```scala -- Warning: tests/neg/i4721.scala:2:39 ----------------------------------------- 2 | def main(args: Array[String]):Unit = m(1) // error | ^ | Unsatisfiable type parameter constraints in polymorphic application -- [E007] Type Mismatch Error: tests/neg/i4721.scala:2:41 ---------------------- 2 | def main(args: Array[String]):Unit = m(1) // error | ^ | found: Int(1) | required: String | one warning found one error found ```
1 parent a583a24 commit 6126bf4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,12 @@ object ProtoTypes {
480480
else tl
481481
val added = ensureFresh(tl)
482482
val tvars = if (addTypeVars) newTypeVars(added) else Nil
483-
ctx.typeComparer.addToConstraint(added, tvars.tpes.asInstanceOf[List[TypeVar]])
483+
// addToConstraint can return false if the constraints have no solution, but it seems easier to detect and report
484+
// any resulting bound violations later in PostTyper (see #4946). We still give a warning because the subsequent
485+
// errors might be misleading.
486+
if (!ctx.typeComparer.addToConstraint(added, tvars.tpes.asInstanceOf[List[TypeVar]]))
487+
ctx.warning(s"Unsatisfiable type parameter constraints in polymorphic application", owningTree.pos)
488+
484489
(added, tvars)
485490
}
486491

0 commit comments

Comments
 (0)