Skip to content

Commit ebc3162

Browse files
committed
Fix #2064: Avoid illegal types in OrDominator
Need to skip type bounds in `underlying` chain, since TypeBounds is not a legal operand type for OrType.
1 parent 3c4d29e commit ebc3162

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
239239
case tp1: RecType =>
240240
tp1.rebind(approximateOr(tp1.parent, tp2))
241241
case tp1: TypeProxy if !isClassRef(tp1) =>
242-
orDominator(tp1.superType | tp2)
242+
orDominator(tp1.superType.bounds.hi | tp2)
243243
case _ =>
244244
tp2 match {
245245
case tp2: RecType =>

tests/pos/i2064.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object p {
2+
3+
class Foo[T] {
4+
// Crashes:
5+
def f(): Foo[T] = (if (true) this else this).bar
6+
7+
// Works:
8+
// def f(): Foo[T] = new Bar(if (true) this else this).bar
9+
}
10+
11+
implicit class Bar[A](val self: A) {
12+
def bar(): A = self
13+
}
14+
15+
}

0 commit comments

Comments
 (0)