Skip to content

Commit 7f6e01d

Browse files
authored
Merge pull request #2068 from dotty-staging/fix-#2064
Fix #2064: Avoid illegal types in OrDominator
2 parents 8e5c9c4 + 57e449e commit 7f6e01d

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,10 +1274,14 @@ object Types {
12741274
def underlying(implicit ctx: Context): Type
12751275

12761276
/** The closest supertype of this type. This is the same as `underlying`,
1277-
* except for TypeRefs where the upper bound is returned, and HKApplys,
1278-
* where the upper bound of the constructor is re-applied to the arguments.
1277+
* except that
1278+
* - instead of a TyperBounds type it returns its upper bound, and
1279+
* - for HKApplys it returns the upper bound of the constructor re-applied to the arguments.
12791280
*/
1280-
def superType(implicit ctx: Context): Type = underlying
1281+
def superType(implicit ctx: Context): Type = underlying match {
1282+
case TypeBounds(_, hi) => hi
1283+
case st => st
1284+
}
12811285
}
12821286

12831287
// Every type has to inherit one of the following four abstract type classes.,
@@ -1766,11 +1770,6 @@ object Types {
17661770
type ThisType = TypeRef
17671771

17681772
override def underlying(implicit ctx: Context): Type = info
1769-
1770-
override def superType(implicit ctx: Context): Type = info match {
1771-
case TypeBounds(_, hi) => hi
1772-
case _ => info
1773-
}
17741773
}
17751774

17761775
final class TermRefWithSignature(prefix: Type, name: TermName, override val sig: Signature) extends TermRef(prefix, name) {

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)