Skip to content

Commit c13f027

Browse files
committed
Don't make AndTypes Singletons
1 parent db24013 commit c13f027

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ object Types {
248248
case _ => NoType
249249
}
250250

251-
/** Is this type a (possibly aliased or intersected) singleton type? */
251+
/** Is this type a (possibly aliased) singleton type? */
252252
def isSingleton(implicit ctx: Context) = SingletonType.unapply(this).isDefined
253253

254254
/** Is this type guaranteed not to have `null` as a value? */
@@ -1501,11 +1501,10 @@ object Types {
15011501
}
15021502

15031503
/** An extractor that returns the underlying singleton type of a
1504-
* (possibly annotated, aliased, or intersected) type
1504+
* (possibly annotated or aliased) type
15051505
*/
15061506
object SingletonType {
15071507
def unapply(tp: Type)(implicit ctx: Context): Option[SingletonType] = tp.dealias match {
1508-
case AndType(tp1, tp2) => unapply(tp1).orElse(unapply(tp2))
15091508
case tp: SingletonType => Some(tp)
15101509
case _ => None
15111510
}

tests/neg/i830.scala renamed to tests/pos/i830.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ object C {
22
trait X[T]
33
implicit def u[A, B]: X[A | B] = new X[A | B] {}
44
def y[T](implicit x: X[T]): T = ???
5-
val x: 1 & 2 | 2 & 3 = y // error: singleton is not allowed in a union type
5+
val x: 1 & 2 | 2 & 3 = y
66
}

tests/pos/i864.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ object C {
66
trait X[T]
77
implicit def u[A, B]: X[A | B] = new X[A | B] {}
88
def y[T](implicit x: X[T]): T = ???
9-
// val x: a.type & b.type | b.type & c.type = y // no longer allowed, singletons cannot be in union types
9+
val x: a.type & b.type | b.type & c.type = y // no longer allowed, singletons cannot be in union types
1010
}

0 commit comments

Comments
 (0)