File tree 2 files changed +39
-2
lines changed
compiler/src/dotty/tools/dotc/core
2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -436,8 +436,17 @@ trait ConstraintHandling {
436
436
437
437
val level1 = nestingLevel(p1)
438
438
val level2 = nestingLevel(p2)
439
- val pKept = if level1 <= level2 then p1 else p2
440
- val pRemoved = if level1 <= level2 then p2 else p1
439
+ val p1Wins = if level1 == level2 then
440
+ // If the nesting levels match, then we would prefer to unify to the outer most parameter.
441
+ // For instance in pos/i21981, while running `normalizedCompatible` against `.map2`,
442
+ // we want to unify to B over K, to allow easily removing K by just instantiating it.
443
+ def preferP1 (ctx : Context ): Boolean =
444
+ val c = ctx.typerState.constraint
445
+ ! c.contains(p2) || c.contains(p1) && preferP1(ctx.outer)
446
+ preferP1(ctx)
447
+ else level1 <= level2
448
+ val pKept = if p1Wins then p1 else p2
449
+ val pRemoved = if p1Wins then p2 else p1
441
450
442
451
val down = constraint.exclusiveLower(p2, p1)
443
452
val up = constraint.exclusiveUpper(p1, p2)
Original file line number Diff line number Diff line change
1
+ trait Ops [F [_], A ]:
2
+ def map0 [B ](f0 : A => B ): F [B ] = ???
3
+
4
+ trait Functor1 [G [_]]
5
+
6
+ trait Functor2 [H [_]]:
7
+ extension [C ](hc : H [C ])
8
+ def map2 [D ](f1 : C => D ): H [D ]
9
+
10
+ trait Ref [I [_], + E ]
11
+
12
+ final class Cov [+ F ]
13
+
14
+ class Test :
15
+ given [J [_]](using J : Functor1 [J ]): Functor2 [J ] with
16
+ extension [K ](jk : J [K ])
17
+ def map2 [L ](f2 : K => L ): J [L ] = ???
18
+
19
+ def t1 [
20
+ M [_[t]],
21
+ N [_],
22
+ ](using N : Functor1 [N ]): Unit =
23
+
24
+ val x3 : Ops [N , M [[t] =>> Ref [N , t]]] = ???
25
+
26
+ val x2 : N [(M [N ], M [[t] =>> Ref [N , t]])] = x3
27
+ .map0 { refs => (??? , refs) }
28
+ .map2 { case (not, refs) => (??? , refs) }
You can’t perform that action at this time.
0 commit comments