Skip to content

Commit def8f7d

Browse files
oderskyolsdavis
authored andcommitted
Fix subsumes test between constraints
The test gave a false negative in the case where a parameter was instantiated to the same value in both constraints. In that case the parameter is not "contained" in either constraint, since it is already instantiated, and that caused the test to fail. Fixes scala#13541
1 parent 819a905 commit def8f7d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,10 @@ trait ConstraintHandling {
411411
// If `c2` has, compared to `pre`, instantiated a param and we iterated over params of `c2`,
412412
// we could miss that param being instantiated to an incompatible type in `c1`.
413413
pre.forallParams(p =>
414-
c1.contains(p) &&
415-
c2.upper(p).forall(c1.isLess(p, _)) &&
416-
isSubTypeWhenFrozen(c1.nonParamBounds(p), c2.nonParamBounds(p)))
414+
c1.entry(p).exists
415+
&& c2.upper(p).forall(c1.isLess(p, _))
416+
&& isSubTypeWhenFrozen(c1.nonParamBounds(p), c2.nonParamBounds(p))
417+
)
417418
finally constraint = saved
418419
}
419420

tests/pos/i13541.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait F[A]
2+
trait Z
3+
object Z:
4+
given F[Z] = ???
5+
6+
type Foo[B] = [A] =>> Bar[A, B]
7+
trait Bar[A, B]
8+
9+
given fooUnit[A: F]: Foo[Unit][A] = ???
10+
//given bar[A: F]: Bar[A, Unit] = ???
11+
12+
def f[A: F](using Foo[Unit][A]): Nothing = ???
13+
14+
def broken: Nothing = f[Z]

0 commit comments

Comments
 (0)