Skip to content

Commit 5c9c31c

Browse files
committed
Prioritise tree type over proto type when typing Binds
1 parent 5c51b7b commit 5c9c31c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28752875
// leave the original tuple type; don't mix with & TupleXXL which would only obscure things
28762876
pt
28772877
case _ =>
2878-
pt & body1.tpe
2878+
body1.tpe & pt
28792879
val sym = newPatternBoundSymbol(name, symTp, tree.span)
28802880
if (pt == defn.ImplicitScrutineeTypeRef || tree.mods.is(Given)) sym.setFlag(Given)
28812881
if (ctx.mode.is(Mode.InPatternAlternative))

tests/pos/i24038a.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
final class MBufferLong:
2+
final def +=(elem: Long): this.type = ???
3+
4+
type M[Tup <: Tuple] <: Tuple = Tup match
5+
case EmptyTuple => EmptyTuple
6+
case h *: t => BufferOf[h] *: M[t]
7+
8+
type M2[T <: Tuple] <: Tuple = (T, M[T]) match
9+
case (h *: t, a *: b) => BufferOf[h] *: M2[t]
10+
case (EmptyTuple, EmptyTuple) => EmptyTuple
11+
case (_, EmptyTuple) => EmptyTuple
12+
case (EmptyTuple, _) => EmptyTuple
13+
14+
type BufferOf[T] = T match
15+
case Long => MBufferLong
16+
17+
inline def append[T](t: T, buffer: BufferOf[T]): BufferOf[T] =
18+
inline (t, buffer) match
19+
case (x: Long, y: BufferOf[Long]) => y.+=(x)
20+
buffer
21+
22+
transparent inline def appendBuffers[T <: Tuple](t: T, buffers: M[T]): M2[T] = {
23+
inline (t, buffers) match
24+
case abcd: ((h *: t), bh *: bt) =>
25+
val (hh *: tt, bh *: bt) = abcd
26+
val x: BufferOf[h] = append[h](hh, bh.asInstanceOf[BufferOf[h]])
27+
x *: appendBuffers[t](tt, bt.asInstanceOf[M[t]])
28+
case _: (EmptyTuple, EmptyTuple) => EmptyTuple
29+
case _: (_, EmptyTuple) => EmptyTuple
30+
case _: (EmptyTuple, _) => EmptyTuple
31+
}

tests/pos/i24038b.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
final class MBufferLong
2+
3+
type M[Tup <: Tuple] <: Tuple = Tup match
4+
case EmptyTuple => EmptyTuple
5+
case h *: t => MBufferLong *: M[t]
6+
7+
def appendBuffers[T <: Tuple](t: T, buffers: M[T]): Unit = {
8+
(t, buffers) match
9+
case abcd: (h *: t, bh *: bt) =>
10+
val (hh *: tt, bh *: bt) = abcd
11+
summon[hh.type <:< h]
12+
}

0 commit comments

Comments
 (0)