Skip to content

Commit b665f45

Browse files
Only record in MatchTypeTrace if not previously attempted
`recurseWith` can be called with the same scrutinee (even if match type reduction is cached) if it is an applied match alias For example, `Tuple.Head[Tuple.Tail[T]]` will attempt to reduce `Tuple.Tail[T]` twice: - once as an argument of the match alias `Head`, and - once as a scrutinee in body of `Head` (after the substitution).
1 parent 8fb447c commit b665f45

File tree

3 files changed

+1
-43
lines changed

3 files changed

+1
-43
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object MatchTypeTrace:
7878
*/
7979
def recurseWith(scrut: Type)(op: => Type)(using Context): Type =
8080
ctx.property(MatchTrace) match
81-
case Some(trace) =>
81+
case Some(trace) if !trace.entries.contains(TryReduce(scrut)) =>
8282
val prev = trace.entries
8383
trace.entries = TryReduce(scrut) :: prev
8484
val res = op

tests/neg/i12049.check

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@
4646
|
4747
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
4848
| case EmptyTuple => EmptyTuple
49-
| trying to reduce Reverse[A *: EmptyTuple.type]
50-
| failed since selector A *: EmptyTuple.type
51-
| matches none of the cases
52-
|
53-
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
54-
| case EmptyTuple => EmptyTuple
5549
|
5650
| longer explanation available when compiling with `-explain`
5751
-- [E172] Type Error: tests/neg/i12049.scala:24:20 ---------------------------------------------------------------------
@@ -95,12 +89,6 @@
9589
|
9690
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
9791
| case EmptyTuple => EmptyTuple
98-
| trying to reduce Reverse[A *: EmptyTuple.type]
99-
| failed since selector A *: EmptyTuple.type
100-
| matches none of the cases
101-
|
102-
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
103-
| case EmptyTuple => EmptyTuple
10492
-- [E008] Not Found Error: tests/neg/i12049.scala:28:21 ----------------------------------------------------------------
10593
28 |val _ = (??? : M[B]).length // error
10694
| ^^^^^^^^^^^^^^^^^^^

tests/neg/i17944.check

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,3 @@
1414
| Therefore, reduction cannot advance to the remaining case
1515
|
1616
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
17-
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)]
18-
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
19-
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
20-
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
21-
| and cannot be shown to be disjoint from it either.
22-
| Therefore, reduction cannot advance to the remaining case
23-
|
24-
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
25-
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
26-
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
27-
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
28-
| and cannot be shown to be disjoint from it either.
29-
| Therefore, reduction cannot advance to the remaining case
30-
|
31-
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
32-
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)]
33-
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
34-
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
35-
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
36-
| and cannot be shown to be disjoint from it either.
37-
| Therefore, reduction cannot advance to the remaining case
38-
|
39-
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
40-
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
41-
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
42-
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
43-
| and cannot be shown to be disjoint from it either.
44-
| Therefore, reduction cannot advance to the remaining case
45-
|
46-
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]

0 commit comments

Comments
 (0)