Skip to content

Commit 78c58a0

Browse files
committed
Fix #10217: Avoid exponential behavior in derivesFrom
1 parent 4411811 commit 78c58a0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ object Types {
242242
// If the type is `T | Null` or `T | Nothing`, and `T` derivesFrom the class,
243243
// then the OrType derivesFrom the class. Otherwise, we need to check both sides
244244
// derivesFrom the class.
245-
if defn.isBottomType(tp.tp1) then loop(tp.tp2)
246-
else loop(tp.tp1) && (defn.isBottomType(tp.tp2) || loop(tp.tp2))
245+
loop(tp.tp1) && loop(tp.tp2)
246+
|| tp.tp1.isNullType && loop(tp.tp2)
247+
|| tp.tp2.isNullType && loop(tp.tp2)
247248
case tp: JavaArrayType =>
248249
cls == defn.ObjectClass
249250
case _ =>

tests/pos/i10217.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
trait A
2+
trait B
3+
trait C
4+
trait D
5+
trait E
6+
trait F
7+
trait G
8+
trait H
9+
trait I
10+
trait J
11+
trait K
12+
trait L
13+
trait M
14+
trait N
15+
trait O
16+
trait P
17+
trait Q
18+
trait R
19+
trait S
20+
trait T
21+
trait U
22+
trait V
23+
trait W
24+
25+
class Foo[T]
26+
27+
val f = Foo[A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U]

0 commit comments

Comments
 (0)